org.eclipse.jdt.core.dom.InstanceofExpression Java Examples
The following examples show how to use
org.eclipse.jdt.core.dom.InstanceofExpression.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ASTNodeMatcher.java From JDeodorant with MIT License | 6 votes |
protected boolean isTypeHolder(Object o) { if(o.getClass().equals(MethodInvocation.class) || o.getClass().equals(SuperMethodInvocation.class) || o.getClass().equals(NumberLiteral.class) || o.getClass().equals(StringLiteral.class) || o.getClass().equals(CharacterLiteral.class) || o.getClass().equals(BooleanLiteral.class) || o.getClass().equals(TypeLiteral.class) || o.getClass().equals(NullLiteral.class) || o.getClass().equals(ArrayCreation.class) || o.getClass().equals(ClassInstanceCreation.class) || o.getClass().equals(ArrayAccess.class) || o.getClass().equals(FieldAccess.class) || o.getClass().equals(SuperFieldAccess.class) || o.getClass().equals(ParenthesizedExpression.class) || o.getClass().equals(SimpleName.class) || o.getClass().equals(QualifiedName.class) || o.getClass().equals(CastExpression.class) || o.getClass().equals(InfixExpression.class) || o.getClass().equals(PrefixExpression.class) || o.getClass().equals(InstanceofExpression.class) || o.getClass().equals(ThisExpression.class) || o.getClass().equals(ConditionalExpression.class)) return true; return false; }
Example #2
Source File: CodeBlock.java From SimFix with GNU General Public License v2.0 | 6 votes |
private InstanceofExpr visit(InstanceofExpression node) { int startLine = _cunit.getLineNumber(node.getStartPosition()); int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength()); InstanceofExpr instanceofExpr = new InstanceofExpr(startLine, endLine, node); Expr expression = (Expr) process(node.getLeftOperand()); expression.setParent(instanceofExpr); instanceofExpr.setExpression(expression); instanceofExpr.setInstanceType(node.getRightOperand()); AST ast = AST.newAST(AST.JLS8); Type exprType = ast.newPrimitiveType(PrimitiveType.BOOLEAN); instanceofExpr.setType(exprType); return instanceofExpr; }
Example #3
Source File: ExpressionsFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean needsParentesis(ASTNode node) { if (!(node.getParent() instanceof InfixExpression)) return false; if (node instanceof InstanceofExpression) return true; if (node instanceof InfixExpression) { InfixExpression expression = (InfixExpression) node; InfixExpression.Operator operator = expression.getOperator(); InfixExpression parentExpression = (InfixExpression) node.getParent(); InfixExpression.Operator parentOperator = parentExpression.getOperator(); if (parentOperator == operator) return false; return true; } return false; }
Example #4
Source File: ReferenceResolvingVisitor.java From windup with Eclipse Public License 1.0 | 5 votes |
@Override public boolean visit(InstanceofExpression node) { Type type = node.getRightOperand(); processType(type, TypeReferenceLocation.INSTANCE_OF, compilationUnit.getLineNumber(node.getStartPosition()), compilationUnit.getColumnNumber(type.getStartPosition()), type.getLength(), node.toString()); return super.visit(node); }
Example #5
Source File: FlowAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void endVisit(InstanceofExpression node) { if (skipNode(node)) { return; } processSequential(node, node.getLeftOperand(), node.getRightOperand()); }
Example #6
Source File: JavaASTFlattener.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override public boolean visit(final InstanceofExpression node) { node.getLeftOperand().accept(this); this.appendToBuffer(" instanceof "); node.getRightOperand().accept(this); return false; }
Example #7
Source File: StyledStringVisitor.java From JDeodorant with MIT License | 5 votes |
public boolean visit(InstanceofExpression expr) { /* * InstanceofExpression: Expression instanceof Type */ activateDiffStyle(expr); handleExpression((Expression) expr.getLeftOperand()); appendSpace(); styledString.append("instanceof", determineDiffStyle(expr, new StyledStringStyler(keywordStyle))); appendSpace(); handleType((Type) expr.getRightOperand()); deactivateDiffStyle(expr); return false; }
Example #8
Source File: OperatorPrecedence.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Returns the precedence of the expression. Expression * with higher precedence are executed before expressions * with lower precedence. * i.e. in: * <br><code> int a= ++3--;</code></br> * * the precedence order is * <ul> * <li>3</li> * <li>++</li> * <li>--</li> * <li>=</li> * </ul> * 1. 3 -(++)-> 4<br> * 2. 4 -(--)-> 3<br> * 3. 3 -(=)-> a<br> * * @param expression the expression to determine the precedence for * @return the precedence the higher to stronger the binding to its operand(s) */ public static int getExpressionPrecedence(Expression expression) { if (expression instanceof InfixExpression) { return getOperatorPrecedence(((InfixExpression)expression).getOperator()); } else if (expression instanceof Assignment) { return ASSIGNMENT; } else if (expression instanceof ConditionalExpression) { return CONDITIONAL; } else if (expression instanceof InstanceofExpression) { return RELATIONAL; } else if (expression instanceof CastExpression) { return TYPEGENERATION; } else if (expression instanceof ClassInstanceCreation) { return POSTFIX; } else if (expression instanceof PrefixExpression) { return PREFIX; } else if (expression instanceof FieldAccess) { return POSTFIX; } else if (expression instanceof MethodInvocation) { return POSTFIX; } else if (expression instanceof ArrayAccess) { return POSTFIX; } else if (expression instanceof PostfixExpression) { return POSTFIX; } return Integer.MAX_VALUE; }
Example #9
Source File: FullConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public ITypeConstraint[] create(InstanceofExpression instanceofExpression){ Expression expression= instanceofExpression.getLeftOperand(); Type type= instanceofExpression.getRightOperand(); if (isClassBinding(expression.resolveTypeBinding()) && isClassBinding(type.resolveBinding())) { ConstraintVariable expressionVar= fConstraintVariableFactory.makeExpressionOrTypeVariable(expression, getContext()); ConstraintVariable typeVariable= fConstraintVariableFactory.makeTypeVariable(type); return createOrOrSubtypeConstraint(expressionVar, typeVariable); } else return new ITypeConstraint[0]; }
Example #10
Source File: IfStatementExpressionAnalyzer.java From JDeodorant with MIT License | 5 votes |
public List<InstanceofExpression> getInstanceofExpressions() { List<InstanceofExpression> expressionList = new ArrayList<InstanceofExpression>(); DefaultMutableTreeNode leaf = root.getFirstLeaf(); while(leaf != null) { Expression expression = (Expression)leaf.getUserObject(); if(expression instanceof InstanceofExpression) { InstanceofExpression instanceofExpression = (InstanceofExpression)expression; expressionList.add(instanceofExpression); } leaf = leaf.getNextLeaf(); } return expressionList; }
Example #11
Source File: LocalCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void addUnnecessaryInstanceofProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot()); ASTNode curr= selectedNode; while (curr instanceof ParenthesizedExpression) { curr= ((ParenthesizedExpression) curr).getExpression(); } if (curr instanceof InstanceofExpression) { AST ast= curr.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); InstanceofExpression inst= (InstanceofExpression) curr; InfixExpression expression= ast.newInfixExpression(); expression.setLeftOperand((Expression) rewrite.createCopyTarget(inst.getLeftOperand())); expression.setOperator(InfixExpression.Operator.NOT_EQUALS); expression.setRightOperand(ast.newNullLiteral()); rewrite.replace(inst, expression, null); String label= CorrectionMessages.LocalCorrectionsSubProcessor_unnecessaryinstanceof_description; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.UNNECESSARY_INSTANCEOF, image); proposals.add(proposal); } }
Example #12
Source File: GenericVisitor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public void endVisit(InstanceofExpression node) { endVisitNode(node); }
Example #13
Source File: StyledStringVisitor.java From JDeodorant with MIT License | 4 votes |
private void handleExpression(Expression expression) { if (expression instanceof ArrayAccess) { visit((ArrayAccess) expression); } else if (expression instanceof ArrayCreation) { visit((ArrayCreation) expression); } else if (expression instanceof ArrayInitializer) { visit((ArrayInitializer) expression); } else if (expression instanceof Assignment) { visit((Assignment) expression); } else if (expression instanceof BooleanLiteral) { visit((BooleanLiteral) expression); } else if (expression instanceof CastExpression) { visit((CastExpression) expression); } else if (expression instanceof CharacterLiteral) { visit((CharacterLiteral) expression); } else if (expression instanceof ClassInstanceCreation) { visit((ClassInstanceCreation) expression); } else if (expression instanceof ConditionalExpression) { visit((ConditionalExpression) expression); } else if (expression instanceof FieldAccess) { visit((FieldAccess) expression); } else if (expression instanceof InfixExpression) { visit((InfixExpression) expression); } else if (expression instanceof InstanceofExpression) { visit((InstanceofExpression) expression); } else if (expression instanceof MethodInvocation) { visit((MethodInvocation) expression); } else if (expression instanceof NullLiteral) { visit((NullLiteral) expression); } else if (expression instanceof NumberLiteral) { visit((NumberLiteral) expression); } else if (expression instanceof ParenthesizedExpression) { visit((ParenthesizedExpression) expression); } else if (expression instanceof PostfixExpression) { visit((PostfixExpression) expression); } else if (expression instanceof PrefixExpression) { visit((PrefixExpression) expression); } else if ((expression instanceof QualifiedName)) { visit((QualifiedName) expression); } else if (expression instanceof SimpleName) { visit((SimpleName) expression); } else if (expression instanceof StringLiteral) { visit((StringLiteral) expression); } else if (expression instanceof SuperFieldAccess) { visit((SuperFieldAccess) expression); } else if (expression instanceof SuperMethodInvocation) { visit((SuperMethodInvocation) expression); } else if (expression instanceof ThisExpression) { visit((ThisExpression) expression); } else if (expression instanceof TypeLiteral) { visit((TypeLiteral) expression); } else if (expression instanceof VariableDeclarationExpression) { visit((VariableDeclarationExpression) expression); } }
Example #14
Source File: BindingSignatureVisitor.java From JDeodorant with MIT License | 4 votes |
private void handleExpression(Expression expression) { if (expression instanceof ArrayAccess) { visit((ArrayAccess) expression); } else if (expression instanceof ArrayCreation) { visit((ArrayCreation) expression); } else if (expression instanceof ArrayInitializer) { visit((ArrayInitializer) expression); } else if (expression instanceof Assignment) { visit((Assignment) expression); } else if (expression instanceof BooleanLiteral) { visit((BooleanLiteral) expression); } else if (expression instanceof CastExpression) { visit((CastExpression) expression); } else if (expression instanceof CharacterLiteral) { visit((CharacterLiteral) expression); } else if (expression instanceof ClassInstanceCreation) { visit((ClassInstanceCreation) expression); } else if (expression instanceof ConditionalExpression) { visit((ConditionalExpression) expression); } else if (expression instanceof FieldAccess) { visit((FieldAccess) expression); } else if (expression instanceof InfixExpression) { visit((InfixExpression) expression); } else if (expression instanceof InstanceofExpression) { visit((InstanceofExpression) expression); } else if (expression instanceof MethodInvocation) { visit((MethodInvocation) expression); } else if (expression instanceof NullLiteral) { visit((NullLiteral) expression); } else if (expression instanceof NumberLiteral) { visit((NumberLiteral) expression); } else if (expression instanceof ParenthesizedExpression) { visit((ParenthesizedExpression) expression); } else if (expression instanceof PostfixExpression) { visit((PostfixExpression) expression); } else if (expression instanceof PrefixExpression) { visit((PrefixExpression) expression); } else if ((expression instanceof QualifiedName)) { visit((QualifiedName) expression); } else if (expression instanceof SimpleName) { visit((SimpleName) expression); } else if (expression instanceof StringLiteral) { visit((StringLiteral) expression); } else if (expression instanceof SuperFieldAccess) { visit((SuperFieldAccess) expression); } else if (expression instanceof SuperMethodInvocation) { visit((SuperMethodInvocation) expression); } else if (expression instanceof ThisExpression) { visit((ThisExpression) expression); } else if (expression instanceof TypeLiteral) { visit((TypeLiteral) expression); } else if (expression instanceof VariableDeclarationExpression) { visit((VariableDeclarationExpression) expression); } }
Example #15
Source File: BindingSignatureVisitor.java From JDeodorant with MIT License | 4 votes |
public boolean visit(InstanceofExpression expr) { handleExpression(expr.getLeftOperand()); handleType(expr.getRightOperand()); return false; }
Example #16
Source File: InstanceOfInstanceofExpression.java From JDeodorant with MIT License | 4 votes |
public boolean instanceOf(Expression expression) { if(expression instanceof InstanceofExpression) return true; else return false; }
Example #17
Source File: AdvancedQuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean getAddParenthesesForExpressionProposals(IInvocationContext context, ASTNode coveringNode, Collection<ICommandAccess> resultingCollections) { ASTNode node; if (context.getSelectionLength() == 0) { node= coveringNode; while (node != null && !(node instanceof CastExpression) && !(node instanceof InfixExpression) && !(node instanceof InstanceofExpression) && !(node instanceof ConditionalExpression)) { node= node.getParent(); } } else { node= context.getCoveredNode(); } String label= null; if (node instanceof CastExpression) { label= CorrectionMessages.UnresolvedElementsSubProcessor_missingcastbrackets_description; } else if (node instanceof InstanceofExpression) { label= CorrectionMessages.LocalCorrectionsSubProcessor_setparenteses_instanceof_description; } else if (node instanceof InfixExpression) { InfixExpression infixExpression= (InfixExpression)node; label= Messages.format(CorrectionMessages.LocalCorrectionsSubProcessor_setparenteses_description, infixExpression.getOperator().toString()); } else if (node instanceof ConditionalExpression) { label= CorrectionMessages.AdvancedQuickAssistProcessor_putConditionalExpressionInParentheses; } else { return false; } if (node.getParent() instanceof ParenthesizedExpression) return false; if (resultingCollections == null) return true; AST ast= node.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression(); parenthesizedExpression.setExpression((Expression)rewrite.createCopyTarget(node)); rewrite.replace(node, parenthesizedExpression, null); Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CAST); ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.ADD_PARENTHESES_FOR_EXPRESSION, image); resultingCollections.add(proposal); return true; }
Example #18
Source File: GenericVisitor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public boolean visit(InstanceofExpression node) { return visitNode(node); }
Example #19
Source File: ConstraintCollector.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public boolean visit(InstanceofExpression node) { add(fCreator.create(node)); return true; }
Example #20
Source File: AstMatchingNodeFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public boolean visit(InstanceofExpression node) { if (node.subtreeMatch(fMatcher, fNodeToMatch)) return matches(node); return super.visit(node); }
Example #21
Source File: FlowAnalyzer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public void endVisit(InstanceofExpression node) { if (skipNode(node)) return; processSequential(node, node.getLeftOperand(), node.getRightOperand()); }
Example #22
Source File: SuperTypeConstraintsCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public final void endVisit(final Type node) { final ASTNode parent= node.getParent(); if (!(parent instanceof AbstractTypeDeclaration) && !(parent instanceof ClassInstanceCreation) && !(parent instanceof TypeLiteral) && (!(parent instanceof InstanceofExpression) || fInstanceOf)) node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, fModel.createTypeVariable(node)); }
Example #23
Source File: JavaASTVisitor.java From SnowGraph with Apache License 2.0 | 4 votes |
private void parseExpression(MethodInfo methodInfo, Expression expression) { if (expression == null) { return; }//System.out.println(expression.toString()+" "+Annotation.nodeClassForType(expression.getNodeType())); if (expression.getNodeType() == ASTNode.ARRAY_INITIALIZER) { List<Expression> expressions = ((ArrayInitializer) expression).expressions(); for (Expression expression2 : expressions) { parseExpression(methodInfo, expression2); } } if (expression.getNodeType() == ASTNode.CAST_EXPRESSION) { parseExpression(methodInfo, ((CastExpression) expression).getExpression()); } if (expression.getNodeType() == ASTNode.CONDITIONAL_EXPRESSION) { parseExpression(methodInfo, ((ConditionalExpression) expression).getExpression()); parseExpression(methodInfo, ((ConditionalExpression) expression).getElseExpression()); parseExpression(methodInfo, ((ConditionalExpression) expression).getThenExpression()); } if (expression.getNodeType() == ASTNode.INFIX_EXPRESSION) { parseExpression(methodInfo, ((InfixExpression) expression).getLeftOperand()); parseExpression(methodInfo, ((InfixExpression) expression).getRightOperand()); } if (expression.getNodeType() == ASTNode.INSTANCEOF_EXPRESSION) { parseExpression(methodInfo, ((InstanceofExpression) expression).getLeftOperand()); } if (expression.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION) { parseExpression(methodInfo, ((ParenthesizedExpression) expression).getExpression()); } if (expression.getNodeType() == ASTNode.POSTFIX_EXPRESSION) { parseExpression(methodInfo, ((PostfixExpression) expression).getOperand()); } if (expression.getNodeType() == ASTNode.PREFIX_EXPRESSION) { parseExpression(methodInfo, ((PrefixExpression) expression).getOperand()); } if (expression.getNodeType() == ASTNode.THIS_EXPRESSION) { parseExpression(methodInfo, ((ThisExpression) expression).getQualifier()); } if (expression.getNodeType() == ASTNode.METHOD_INVOCATION) { List<Expression> arguments = ((MethodInvocation) expression).arguments(); IMethodBinding methodBinding = ((MethodInvocation) expression).resolveMethodBinding(); if (methodBinding != null) methodInfo.methodCalls.add(methodBinding); for (Expression exp : arguments) parseExpression(methodInfo, exp); parseExpression(methodInfo, ((MethodInvocation) expression).getExpression()); } if (expression.getNodeType() == ASTNode.ASSIGNMENT) { parseExpression(methodInfo, ((Assignment) expression).getLeftHandSide()); parseExpression(methodInfo, ((Assignment) expression).getRightHandSide()); } if (expression.getNodeType() == ASTNode.QUALIFIED_NAME) { if (((QualifiedName) expression).getQualifier().resolveTypeBinding() != null) { String name = ((QualifiedName) expression).getQualifier().resolveTypeBinding().getQualifiedName() + "." + ((QualifiedName) expression).getName().getIdentifier(); methodInfo.fieldUsesSet.add(name); } parseExpression(methodInfo, ((QualifiedName) expression).getQualifier()); } }
Example #24
Source File: InstanceOfVisitor.java From DesigniteJava with Apache License 2.0 | 4 votes |
public boolean visit(InstanceofExpression node) { typesInInstanceOf.add(node.getRightOperand()); return true; }
Example #25
Source File: ConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 2 votes |
/** * @param node the AST node * @return array of type constraints, may be empty * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.InstanceofExpression) */ public ITypeConstraint[] create(InstanceofExpression node) { return EMPTY_ARRAY; }