List of usage examples for org.eclipse.jdt.core.dom MethodInvocation arguments
ASTNode.NodeList arguments
To view the source code for org.eclipse.jdt.core.dom MethodInvocation arguments.
Click Source Link
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 www . ja v a 2s . c o m*/ 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()); }/*from w w w . j a v a2s . c o m*/ 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
public static boolean isIndicationOfField(Name node) { boolean isField = false; ASTNode parent = node.getParent();//from ww w.ja v a2 s . co m // The thing here is that if the parent is a qualified name, go one // level up. // If the parent is still a qualified name, then, it means we were in // the middle, so this is // not necessarily a field. if (parent instanceof QualifiedName) { QualifiedName qName = (QualifiedName) parent; if (qName.getName().equals(node)) { node = (Name) parent; parent = parent.getParent(); } } if (parent instanceof ArrayAccess) { isField = true; // } else if (parent instanceof ArrayCreation) { // isField = true; } else if (parent instanceof ArrayInitializer) { isField = true; } else if (parent instanceof Assignment) { isField = true; } else if (parent instanceof CastExpression) { CastExpression cExpression = (CastExpression) parent; isField = cExpression.getExpression().equals(node); } else if (parent instanceof ConditionalExpression) { isField = true; } else if (parent instanceof InfixExpression) { isField = true; } else if (parent instanceof WhileStatement) { isField = true; } else if (parent instanceof DoStatement) { isField = true; } else if (parent instanceof ForStatement) { ForStatement forStatement = (ForStatement) parent; isField = forStatement.getExpression().equals(node); } else if (parent instanceof PrefixExpression) { isField = true; } else if (parent instanceof PostfixExpression) { isField = true; } else if (parent instanceof ReturnStatement) { isField = true; } else if (parent instanceof InstanceofExpression) { InstanceofExpression ioe = (InstanceofExpression) parent; isField = ioe.getLeftOperand().equals(node); } else if (parent instanceof FieldAccess) { isField = true; } else if (parent instanceof SuperFieldAccess) { isField = true; } else if (parent instanceof MethodInvocation) { MethodInvocation mi = (MethodInvocation) parent; for (Object object : mi.arguments()) { if (node == object) { isField = true; break; } } } else if (parent instanceof ClassInstanceCreation) { ClassInstanceCreation cic = (ClassInstanceCreation) parent; for (Object object : cic.arguments()) { if (node == object) { isField = true; break; } } } else if (parent instanceof VariableDeclarationFragment) { isField = true; } return isField; }
From source file:ca.mcgill.cs.swevo.ppa.PPAASTUtil.java
License:Open Source License
/** * Return true if 1) this is a method invocation and 2) one of the parameter * is not full./*from w w w . ja v a 2s . co m*/ * * Always return false if this is a method invocation from Object and that * is final. * * @param node * @return */ public static boolean isUnsafeMethod(SimpleName node) { boolean isUnsafe = false; ASTNode parent = node.getParent(); if (parent instanceof MethodInvocation) { MethodInvocation mi = (MethodInvocation) parent; if (mi.getName() == node) { if (!checkObjectFinalMethod(mi)) { for (Object arg : mi.arguments()) { Expression exp = (Expression) arg; if (PPABindingsUtil .getSafetyValue(PPABindingsUtil.getTypeBinding(exp)) < PPABindingsUtil.FULL_TYPE) { isUnsafe = true; break; } } if (!isUnsafe) { ITypeBinding containerType = PPABindingsUtil.getTypeBinding(getContainer(mi)); isUnsafe = PPABindingsUtil.getSafetyValue(containerType) < PPABindingsUtil.FULL_TYPE; } } } } return isUnsafe; }
From source file:ch.acanda.eclipse.pmd.java.resolution.migration.ByteInstantiationValueOfQuickFix.java
License:Open Source License
/** * Replaces the Byte instantiation with its argument, e.g. {@code new Byte(123 + x)} with * {@code Byte.valueOf(123 + x)}./*from ww w . jav a 2s . c o m*/ */ @Override @SuppressWarnings("unchecked") protected boolean apply(final ClassInstanceCreation node) { final AST ast = node.getAST(); final MethodInvocation invocation = ast.newMethodInvocation(); invocation.setExpression(ast.newSimpleName("Byte")); invocation.setName(ast.newSimpleName("valueOf")); invocation.arguments().add(copy((Expression) node.arguments().get(0))); replace(node, invocation); return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.migration.IntegerInstantiationValueOfQuickFix.java
License:Open Source License
/** * Replaces the Integer instantiation with its argument, e.g. {@code new Integer(123 + x)} with * {@code Integer.valueOf(123 + x)}./* w ww. j a va2 s . c om*/ */ @Override @SuppressWarnings("unchecked") protected boolean apply(final ClassInstanceCreation node) { final AST ast = node.getAST(); final MethodInvocation invocation = ast.newMethodInvocation(); invocation.setExpression(ast.newSimpleName("Integer")); invocation.setName(ast.newSimpleName("valueOf")); invocation.arguments().add(copy((Expression) node.arguments().get(0))); replace(node, invocation); return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.migration.LongInstantiationValueOfQuickFix.java
License:Open Source License
/** * Replaces the Long instantiation with its argument, e.g. {@code new Long(123 + x)} with * {@code Long.valueOf(123 + x)}./* ww w.j a va 2 s. c om*/ */ @Override @SuppressWarnings("unchecked") protected boolean apply(final ClassInstanceCreation node) { final AST ast = node.getAST(); final MethodInvocation invocation = ast.newMethodInvocation(); invocation.setExpression(ast.newSimpleName("Long")); invocation.setName(ast.newSimpleName("valueOf")); invocation.arguments().add(copy((Expression) node.arguments().get(0))); replace(node, invocation); return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.migration.ShortInstantiationValueOfQuickFix.java
License:Open Source License
/** * Replaces the Short instantiation with its argument, e.g. {@code new Short(123 + x)} with * {@code Short.valueOf(123 + x)}.//from w ww .j a v a 2 s. c o m */ @Override @SuppressWarnings("unchecked") protected boolean apply(final ClassInstanceCreation node) { final AST ast = node.getAST(); final MethodInvocation invocation = ast.newMethodInvocation(); invocation.setExpression(ast.newSimpleName("Short")); invocation.setName(ast.newSimpleName("valueOf")); invocation.arguments().add(copy((Expression) node.arguments().get(0))); replace(node, invocation); return true; }
From source file:ch.acanda.eclipse.pmd.java.resolution.optimization.AddEmptyStringQuickFix.java
License:Open Source License
@Override @SuppressWarnings("unchecked") protected boolean apply(final InfixExpression node) { final Expression rightOperand = node.getRightOperand(); // "" + "abc" -> "abc" // "" + x.toString() -> x.toString() if (isString(rightOperand)) { return replace(node, copy(rightOperand)); }/*from w w w . j a va 2s.c o m*/ // "" + 'a' -> "a" if (isCharacterLiteral(rightOperand)) { final AST ast = node.getAST(); final StringLiteral stringLiteral = ast.newStringLiteral(); final String escapedCharacter = ((CharacterLiteral) rightOperand).getEscapedValue(); stringLiteral.setEscapedValue(convertToEscapedString(escapedCharacter)); return replace(node, stringLiteral); } // "" + x -> String.valueOf(x) final AST ast = node.getAST(); final MethodInvocation toString = ast.newMethodInvocation(); toString.setExpression(ast.newSimpleName("String")); toString.setName(ast.newSimpleName("valueOf")); toString.arguments().add(copy(rightOperand)); return replace(node, toString); }
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 w w w. j ava2s .c o m*/ @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; }