本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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)));
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}