List of usage examples for org.eclipse.jdt.core.dom MethodInvocation getExpression
public Expression getExpression()
null
if there is none. From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(MethodInvocation node) { if (node.getExpression() != null) { node.getExpression().accept(this); this.fBuffer.append(".");//$NON-NLS-1$ }/*from w ww. j av a 2s.c om*/ if (node.getAST().apiLevel() >= JLS3) { if (!node.typeArguments().isEmpty()) { this.fBuffer.append("<");//$NON-NLS-1$ for (Iterator<Type> it = node.typeArguments().iterator(); it.hasNext();) { Type t = it.next(); t.accept(this); if (it.hasNext()) { this.fBuffer.append(",");//$NON-NLS-1$ } } this.fBuffer.append(">");//$NON-NLS-1$ } } node.getName().accept(this); this.fBuffer.append("(");//$NON-NLS-1$ for (Iterator<Expression> it = node.arguments().iterator(); it.hasNext();) { Expression e = it.next(); e.accept(this); if (it.hasNext()) { this.fBuffer.append(",");//$NON-NLS-1$ } } this.fBuffer.append(")");//$NON-NLS-1$ return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(MethodInvocation node) { boa.types.Ast.Expression.Builder b = boa.types.Ast.Expression.newBuilder(); // b.setPosition(pos.build()); b.setKind(boa.types.Ast.Expression.ExpressionKind.METHODCALL); b.setMethod(node.getName().getFullyQualifiedName()); if (node.getExpression() != null) { node.getExpression().accept(this); b.addExpressions(expressions.pop()); }/* w w w . j a v a 2 s. c om*/ for (Object a : node.arguments()) { ((org.eclipse.jdt.core.dom.Expression) a).accept(this); b.addMethodArgs(expressions.pop()); } for (Object t : node.typeArguments()) { boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); tb.setName(getIndex(typeName((org.eclipse.jdt.core.dom.Type) t))); tb.setKind(boa.types.Ast.TypeKind.GENERIC); b.addGenericParameters(tb.build()); } expressions.push(b.build()); return false; }
From source file:ca.mcgill.cs.swevo.ppa.PPAASTUtil.java
License:Open Source License
/** * XXX When changing getContainer, getMethodContainer, and * isMethodContainer, do not forget to change getTypeBinding * // ww w . j a va 2 s. c o m * @param mi * @return */ public static ASTNode getContainer(MethodInvocation mi) { ASTNode container = mi.getExpression(); if (container == null) { container = PPAASTUtil.getMethodContainer(mi); } return container; }
From source file:ch.acanda.eclipse.pmd.java.resolution.design.EqualsNullQuickFix.java
License:Open Source License
/** * Replaces {@code x.equals(null)} with {@code x == null}. *//*from w w w .j a va2s . co m*/ @Override protected boolean apply(final MethodInvocation node) { final AST ast = node.getAST(); final InfixExpression infix = (InfixExpression) ast.createInstance(InfixExpression.class); infix.setOperator(Operator.EQUALS); infix.setLeftOperand(ASTUtil.copy(node.getExpression())); infix.setRightOperand((NullLiteral) ast.createInstance(NullLiteral.class)); ASTUtil.replace(node, infix); return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.design.UseCollectionIsEmptyQuickFix.java
License:Open Source License
/** * Replaces {@code x.size() == 0} or {@code 0 == x.size()} with {@code x.isEmpty()}. Replaces {@code x.size() != 0} * or {@code 0 != x.size()} with {@code !x.isEmpty()}. *//*from w w w.j a v a 2 s . c o m*/ @Override protected boolean apply(final InfixExpression node) { final MethodInvocation size; if (node.getLeftOperand() instanceof MethodInvocation) { size = (MethodInvocation) node.getLeftOperand(); } else if (node.getRightOperand() instanceof MethodInvocation) { size = (MethodInvocation) node.getRightOperand(); } else { return false; } final AST ast = node.getAST(); final MethodInvocation invocation = (MethodInvocation) ast.createInstance(MethodInvocation.class); invocation.setExpression(ASTUtil.copy(size.getExpression())); final SimpleName isEmpty = (SimpleName) ast.createInstance(SimpleName.class); isEmpty.setIdentifier("isEmpty"); invocation.setName(isEmpty); final Expression replacement; if (isNotEmpty(node)) { final PrefixExpression not = (PrefixExpression) ast.createInstance(PrefixExpression.class); not.setOperator(org.eclipse.jdt.core.dom.PrefixExpression.Operator.NOT); not.setOperand(invocation); replacement = not; } else { replacement = invocation; } ASTUtil.replace(node, replacement); return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.optimization.SimplifyStartsWithQuickFix.java
License:Open Source License
/** * Rewrites <code>s.startsWith("a")</code> as <code>s.charAt(0) == 'a'</code>. *//*from ww w.j a v a 2s . c om*/ @Override @SuppressWarnings("unchecked") protected boolean apply(final MethodInvocation node) { final AST ast = node.getAST(); final MethodInvocation charAt = ast.newMethodInvocation(); charAt.setExpression(copy(node.getExpression())); charAt.setName(ast.newSimpleName("charAt")); charAt.arguments().add(ast.newNumberLiteral("0")); final CharacterLiteral character = ast.newCharacterLiteral(); final StringLiteral s = (StringLiteral) node.arguments().get(0); character.setEscapedValue(s.getEscapedValue().replace('"', '\'')); final InfixExpression eq = ast.newInfixExpression(); eq.setOperator(Operator.EQUALS); eq.setLeftOperand(charAt); eq.setRightOperand(character); replace(node, eq); return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.stringandstringbuffer.StringToStringQuickFix.java
License:Open Source License
/** * Removes the <code>.toString()</code> from <code>"foo".toString()</code> if the expression is only a part of an * statement. Removes the expression completely if it is the whole statement. *///from ww w . j a v a 2 s .c om @Override protected boolean apply(final MethodInvocation node) { if (node.getParent() instanceof ExpressionStatement) { // remove "foo".toString() completely if it is a statement as "foo" alone is not a valid statement node.getParent().delete(); } else { // remove .toString() if "foo".toString() is only part of a statement // e.g. return "foo".toString(); -> return "foo"; replace(node, copy(node.getExpression())); } return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.stringandstringbuffer.UnnecessaryCaseChangeQuickFix.java
License:Open Source License
/** * Removes the <code>.toString()</code> from <code>"foo".toString()</code> if the expression is only a part of an * statement. Removes the expression completely if it is the whole statement. *//*ww w .j a v a 2 s .com*/ @Override @SuppressWarnings("unchecked") protected boolean apply(final MethodInvocation node) { final AST ast = node.getAST(); final MethodInvocation invocation = ast.newMethodInvocation(); if (node.getExpression().getNodeType() == ASTNode.METHOD_INVOCATION) { invocation.setExpression(removeCaseChange((MethodInvocation) node.getExpression())); invocation.setName(ast.newSimpleName("equalsIgnoreCase")); invocation.arguments().add(copy((Expression) node.arguments().get(0))); return replace(node, invocation); } return false; }
From source file:ch.acanda.eclipse.pmd.java.resolution.stringandstringbuffer.UnnecessaryCaseChangeQuickFix.java
License:Open Source License
private Expression removeCaseChange(final MethodInvocation withCaseChange) { final String identifier = withCaseChange.getName().getIdentifier(); if ("toUpperCase".equals(identifier) || "toLowerCase".equals(identifier)) { return copy(withCaseChange.getExpression()); }//w w w.j a va 2s . c o m return copy(withCaseChange); }
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(MethodInvocation node) { IMethodBinding mmtb = node.resolveMethodBinding(); if (this.mtbStack.isEmpty()) { return true; }/* w w w .j a v a2s. co m*/ try { if (node.getExpression() != null) { if (mmtb.getDeclaringClass().getQualifiedName().startsWith("java.awt.geom.Path2D")) { Expression e = node.getExpression(); ITypeBinding itb = e.resolveTypeBinding(); this.facts.add(Fact.makeCallsFact(getQualifiedName((IMethodBinding) this.mtbStack.peek()), getQualifiedName(itb) + "#" + getSimpleName(mmtb))); break label179; } } this.facts.add(Fact.makeCallsFact(getQualifiedName((IMethodBinding) this.mtbStack.peek()), getQualifiedName(mmtb))); } catch (Exception localException) { System.err.println("Cannot resolve method invocation \"" + node.getName().toString() + "\""); } label179: return true; }