当前位置: 首页>>代码示例>>Java>>正文


Java JSExpression类代码示例

本文整理汇总了Java中com.intellij.lang.javascript.psi.JSExpression的典型用法代码示例。如果您正苦于以下问题:Java JSExpression类的具体用法?Java JSExpression怎么用?Java JSExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JSExpression类属于com.intellij.lang.javascript.psi包,在下文中一共展示了JSExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getElementByReference

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Nullable
@Override
public PsiElement getElementByReference(@NotNull PsiReference ref, int flags) {
    if (ref instanceof JSTextReference) {
        final PsiElement element = ref.getElement();
        final JSCallExpression call = PsiTreeUtil.getParentOfType(element, JSCallExpression.class);
        final JSExpression expression = call != null ? call.getMethodExpression() : null;
        if (expression instanceof JSReferenceExpression) {
            JSReferenceExpression callee = (JSReferenceExpression)expression;
            JSExpression qualifier = callee.getQualifier();

            if (qualifier != null && "component".equals(callee.getReferencedName()) &&
                    EmberIndexUtil.hasEmberJS(element.getProject())) {
                return element;
            }
        }
    }
    return null;
}
 
开发者ID:kristianmandrup,项目名称:emberjs-plugin,代码行数:20,代码来源:EmberJSTargetElementEvaluator.java

示例2: visitJSCallExpression

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override public void visitJSCallExpression(JSCallExpression jsCallExpression) {
    super.visitJSCallExpression(jsCallExpression);
    final JSExpression methodExpression;
    try {
        methodExpression = jsCallExpression.getMethodExpression();
    } catch (Exception e) {
        return; //catching an intelliJ CCE
    }
    if (!(methodExpression instanceof JSReferenceExpression)) {
        return;
    }
    final JSReferenceExpression referenceExpression = (JSReferenceExpression) methodExpression;
    final JSExpression qualifier = referenceExpression.getQualifier();

    @NonNls final String methodName = referenceExpression.getReferencedName();
    if (!"eval".equals(methodName) && !"setTimeout".equals(methodName) && !"setInterval".equals(methodName)) {
        return;
    }
    registerError(methodExpression);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:21,代码来源:DynamicallyGeneratedCodeJSInspection.java

示例3: processIntention

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override
public void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
       final JSIfStatement exp             = (JSIfStatement) element;
       final JSExpression  condition       = exp.getCondition();
       final JSStatement   thenBranch      = exp.getThen();
       final JSStatement   elseBranch      = exp.getElse();
       final String        negatedText     = BoolUtils.getNegatedExpressionText(condition);
       final boolean       emptyThenBranch = (thenBranch == null  ||
                                              (thenBranch instanceof JSBlockStatement &&
                                               ((JSBlockStatement) thenBranch).getStatements().length == 0));
       final String        thenText        = (emptyThenBranch      ? ""   : ELSE_KEYWORD + thenBranch.getText());
       final String        elseText        = ((elseBranch == null) ? "{}" : elseBranch.getText());

       final String newStatement = IF_PREFIX + negatedText + ')' + elseText + thenText;

       JSElementFactory.replaceStatement(exp, newStatement);
   }
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:18,代码来源:JSFlipIfIntention.java

示例4: processIntention

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override
public void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
       assert (element.getParent() != null);
       assert (element.getParent() instanceof JSIfStatement || element instanceof JSIfStatement);

       final JSIfStatement parentStatement     = (JSIfStatement) (element.getParent() instanceof JSIfStatement ? element.getParent() : element);
       final JSIfStatement childStatement      = (JSIfStatement) ConditionalUtils.stripBraces(parentStatement.getThen());
       final JSExpression  childCondition      = childStatement.getCondition();
       final JSExpression  parentCondition     = parentStatement.getCondition();
       final String        childConditionText  = ParenthesesUtils.getParenthesized(childCondition,  ParenthesesUtils.AND_PRECENDENCE);
       final String        parentConditionText = ParenthesesUtils.getParenthesized(parentCondition, ParenthesesUtils.AND_PRECENDENCE);
       final JSStatement   childThenBranch     = childStatement.getThen();
       final String        statement           = IF_STATEMENT_PREFIX + parentConditionText + " && " + childConditionText + ')' +
                                                 childThenBranch.getText();

       JSElementFactory.replaceStatement(parentStatement, statement);
   }
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:18,代码来源:JSMergeIfAndIntention.java

示例5: isConstantMask

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
private static boolean isConstantMask(JSExpression expression) {
    if (expression == null) {
        return false;
    }
    if (!(expression instanceof JSBinaryExpression)) {
        return false;
    }
    final JSBinaryExpression binaryExpression =
            (JSBinaryExpression) expression;
    final IElementType tokenType = binaryExpression.getOperationSign();
    if (!JSTokenTypes.OR.equals(tokenType) &&
            !JSTokenTypes.AND.equals(tokenType)) {
        return false;
    }
    final JSExpression rhs = binaryExpression.getROperand();
    if (ExpressionUtil.isConstantExpression(rhs)) {
        return true;
    }
    final JSExpression lhs = binaryExpression.getLOperand();
    return ExpressionUtil.isConstantExpression(lhs);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:22,代码来源:IncompatibleMaskJSInspection.java

示例6: satisfiedBy

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override
public boolean satisfiedBy(@NotNull PsiElement element) {
          if (!(element instanceof JSBinaryExpression)) {
              return false;
          }

          final JSBinaryExpression expression = (JSBinaryExpression) element;
          final IElementType       sign       = expression.getOperationSign();

          if (!sign.equals(JSTokenTypes.PLUS)) {
              return false;
          }
          final JSExpression lhs = expression.getLOperand();
          final JSExpression rhs = expression.getROperand();

          if (!isApplicableLiteral(lhs)) {
              return false;
          }
          if (!isApplicableLiteral(rhs)) {
              return false;
          }

          return true;
      }
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:25,代码来源:JSJoinConcatenatedStringLiteralsIntention.java

示例7: satisfiedBy

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override
public boolean satisfiedBy(@NotNull PsiElement element) {
          if (!(element instanceof JSConditionalExpression)) {
              return false;
          }
          if (ErrorUtil.containsError(element)) {
              return false;
          }

          final JSConditionalExpression condition      = (JSConditionalExpression) element;
          final JSExpression            thenExpression = ParenthesesUtils.stripParentheses(condition.getThen());
          final JSExpression            elseExpression = ParenthesesUtils.stripParentheses(condition.getElse());

          if (condition.getCondition() == null ||
              thenExpression           == null ||
              elseExpression           == null) {
              return false;
          }

          final String thenText = thenExpression.getText();
          final String elseText = elseExpression.getText();

          return  ((BoolUtils.TRUE.equals(elseText) && BoolUtils.FALSE.equals(thenText)) ||
                   (BoolUtils.TRUE.equals(thenText) && BoolUtils.FALSE.equals(elseText)));
      }
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:26,代码来源:JSRemoveConditionalIntention.java

示例8: getIndexExpression

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override
public JSExpression getIndexExpression()
{
	ASTNode child = getNode().getFirstChildNode();
	boolean bracketPassed = false;
	while(child != null)
	{
		final IElementType type = child.getElementType();
		if(type == JSTokenTypes.LBRACKET)
		{
			bracketPassed = true;
		}
		if(bracketPassed && JSElementTypes.EXPRESSIONS.contains(type))
		{
			return (JSExpression) child.getPsi();
		}
		child = child.getTreeNext();
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:21,代码来源:JSIndexedPropertyAccessExpressionImpl.java

示例9: binaryExpressionDefinitelyRecurses

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
private static boolean binaryExpressionDefinitelyRecurses(
        JSBinaryExpression expression, JSFunction method) {
    final JSExpression lhs = expression.getLOperand();

    if (RecursionUtil.expressionDefinitelyRecurses(lhs, method)) {
        return true;
    }

    final IElementType tokenType = expression.getOperationSign();

    if (tokenType.equals(JSTokenTypes.ANDAND) ||
        tokenType.equals(JSTokenTypes.OROR)) {
        return false;
    }

    return RecursionUtil.expressionDefinitelyRecurses(expression.getROperand(), method);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:18,代码来源:RecursionUtil.java

示例10: visitJSBinaryExpression

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override public void visitJSBinaryExpression(@NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    if (!(expression.getROperand() != null)) {
        return;
    }
    if (!ComparisonUtils.isComparison(expression)) {
        return;
    }
    final JSExpression lhs = expression.getLOperand();
    final JSExpression rhs = expression.getROperand();
    if (lhs instanceof JSLiteralExpression ||
            !(rhs instanceof JSLiteralExpression)) {
        return;
    }
    registerError(expression);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:17,代码来源:ConstantOnRHSOfComparisonJSInspection.java

示例11: visitJSBinaryExpression

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override public void visitJSBinaryExpression(
        @NotNull JSBinaryExpression expression) {
    super.visitJSBinaryExpression(expression);
    final JSExpression rhs = expression.getROperand();
    if (rhs == null) {
        return;
    }
    final IElementType tokenType = expression.getOperationSign();
    if (!JSTokenTypes.DIV.equals(tokenType) &&
            !JSTokenTypes.PERC.equals(tokenType)) {
        return;
    }
    if(!isZero(rhs))
    {
        return;
    }
    registerError(expression);
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:19,代码来源:DivideByZeroJSInspection.java

示例12: visitJSConditionalExpression

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override public void visitJSConditionalExpression(JSConditionalExpression exp) {
    super.visitJSConditionalExpression(exp);
    final JSExpression thenExpression = exp.getThen();
    if (thenExpression == null) {
        return;
    }
    final JSExpression elseExpression = exp.getElse();
    if (elseExpression == null) {
        return;
    }
    if (((isFalse(thenExpression) && isTrue(elseExpression))
            || (isTrue(thenExpression) && isFalse(elseExpression))) &&
        "Boolean".equals(JSResolveUtil.getExpressionType(exp.getCondition(), exp.getContainingFile())) 
       ) {
        registerError(exp);
    }
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:18,代码来源:TrivialConditionalJSInspection.java

示例13: getCollectionExpression

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override
public JSExpression getCollectionExpression()
{
	ASTNode child = getNode().getFirstChildNode();
	boolean inPassed = false;
	while(child != null)
	{
		if(child.getElementType() == JSTokenTypes.IN_KEYWORD)
		{
			inPassed = true;
		}
		if(inPassed && JSElementTypes.EXPRESSIONS.contains(child.getElementType()))
		{
			return (JSExpression) child.getPsi();
		}
		child = child.getTreeNext();
	}

	return null;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:21,代码来源:JSForInStatementImpl.java

示例14: processDeclarations

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor, @NotNull ResolveState state, PsiElement lastParent,
		@NotNull PsiElement place)
{
	if(lastParent != null)
	{
		final JSVarStatement statement = getDeclarationStatement();
		if(statement != null)
		{
			return statement.processDeclarations(processor, state, lastParent, place);
		}
		else
		{
			final JSExpression expression = getVariableExpression();
			if(expression != null && !processor.execute(expression, null))
			{
				return false;
			}
		}
	}
	return true;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:23,代码来源:JSForInStatementImpl.java

示例15: getType

import com.intellij.lang.javascript.psi.JSExpression; //导入依赖的package包/类
@NotNull
@Override
public JavaScriptType getType()
{
	final JSExpression initializer = getInitializer();
	if(initializer != null)
	{
		JavaScriptType javaScriptType = RecursionManager.doPreventingRecursion(this, false, new Computable<JavaScriptType>()
		{
			@Override
			@RequiredReadAction
			public JavaScriptType compute()
			{
				return initializer.getType();
			}
		});
		return javaScriptType == null ? JavaScriptType.UNKNOWN : javaScriptType;
	}
	return JavaScriptType.UNKNOWN;
}
 
开发者ID:consulo,项目名称:consulo-javascript,代码行数:21,代码来源:JSVariableBaseImpl.java


注:本文中的com.intellij.lang.javascript.psi.JSExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。