1 /* 2 * Copyright 2000-2005 JetBrains s.r.o. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.intellij.lang.javascript.psi.util; 17 18 import com.intellij.lang.javascript.psi.*; 19 import com.intellij.psi.PsiElement; 20 21 /** 22 * @author max 23 */ 24 public class JSUtils { 25 public static boolean isLHSExpression(JSExpression expr) { 26 if (expr instanceof JSReferenceExpression) { 27 final PsiElement resolved = ((JSReferenceExpression)expr).resolve(); 28 // funcid = null sometimes used for gc-ing purposes? 29 return resolved == null || resolved instanceof JSVariable || resolved instanceof JSFunction; 30 } 31 32 if (expr instanceof JSParenthesizedExpression) { 33 return isLHSExpression(((JSParenthesizedExpression)expr).getInnerExpression()); 34 } 35 36 if (expr instanceof JSIndexedPropertyAccessExpression) { 37 return true; 38 } 39 40 if (expr instanceof JSCallExpression) { 41 return true; 42 } 43 44 if (expr instanceof JSNewExpression) { 45 return true; 46 } 47 48 return false; 49 } 50 } 51