List of usage examples for org.eclipse.jdt.core.dom MethodInvocation ARGUMENTS_PROPERTY
ChildListPropertyDescriptor ARGUMENTS_PROPERTY
To view the source code for org.eclipse.jdt.core.dom MethodInvocation ARGUMENTS_PROPERTY.
Click Source Link
From source file:com.google.gdt.eclipse.designer.gxt.model.widgets.GridInfo.java
License:Open Source License
/** * @return {@link MethodInvocation} used for associating given "column" with {@link List} of model * columns.// www. jav a2 s. com */ private MethodInvocation getInvocationOfAssociationWithThisGrid(SimpleName columnsList, ColumnConfigInfo column) { for (ASTNode node : column.getRelatedNodes()) { if (node.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) { MethodInvocation invocation = (MethodInvocation) node.getParent(); if (invocation.getName().getIdentifier().equals("add") && isSameColumnsList(columnsList, invocation.getExpression())) { return invocation; } } } return null; }
From source file:com.google.gdt.eclipse.designer.model.widgets.panels.grid.FlexTableInfo.java
License:Open Source License
/** * @return <code>true</code> if this {@link FlexTableInfo} already "fixed". *///from www . j a v a2s . c o m private boolean hasInvocation_fixRowSpan() { for (ASTNode relatedNode : getRelatedNodes()) { if (relatedNode.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) { MethodInvocation invocation = (MethodInvocation) relatedNode.getParent(); if (invocation.toString().contains("FlexTableHelper.fixRowSpan(")) { return true; } } } return false; }
From source file:de.ovgu.cide.language.jdt.ASTID.java
License:Open Source License
public static String calculateId(ASTNode node) { if (node == null) return "/"; String id = calculateId(node.getParent()); if (node.getParent() instanceof Block) { Block block = (Block) node.getParent(); int idx = block.statements().indexOf(node); id += "[" + idx + "]"; }/*from w w w.j av a2s. c o m*/ if (node.getParent() instanceof ArrayInitializer) { ArrayInitializer block = (ArrayInitializer) node.getParent(); int idx = block.expressions().indexOf(node); id += "[" + idx + "]"; } if (node.getLocationInParent() != null && node.getParent() != null) { id += ":" + node.getLocationInParent().getId(); } if (node.getParent() instanceof TryStatement) { TryStatement trystmt = (TryStatement) node.getParent(); if (trystmt.getBody() == node) id += "[body]"; } // if (node.getLocationInParent() instanceof // ChildListPropertyDescriptor) { // List children = (List) node.getParent().getStructuralProperty( // node.getLocationInParent()); // id += "[" + children.indexOf(node) + "]"; // } id += "/" + clean(node.getClass().getSimpleName()); if (node instanceof TypeDeclaration) { id += ":" + clean(((TypeDeclaration) node).getName().toString()); } if (node instanceof FieldDeclaration) { for (Object fragment : ((FieldDeclaration) node).fragments()) { id += ":" + clean(((VariableDeclarationFragment) fragment).getName().toString()); } } if (node instanceof Type) { ITypeBinding b = ((Type) node).resolveBinding(); id += "::" + (b == null ? "null" : b.getQualifiedName()); } if (node instanceof VariableDeclaration) id += ":" + clean(((VariableDeclaration) node).getName().toString()); if (node instanceof Name) id += ":" + clean(((Name) node).getFullyQualifiedName()); if (node instanceof ImportDeclaration) id += ":" + clean(((ImportDeclaration) node).getName().toString()); if (node instanceof MethodDeclaration) { Type rt = ((MethodDeclaration) node).getReturnType2(); id += ":" + clean(rt == null ? "void" : rt.toString()); id += ":" + clean(((MethodDeclaration) node).getName().toString()); id += ":" + clean(getParameterTypes(((MethodDeclaration) node).parameters())); } ChildListPropertyDescriptor[] enumLists = new ChildListPropertyDescriptor[] { SwitchStatement.STATEMENTS_PROPERTY, InfixExpression.EXTENDED_OPERANDS_PROPERTY, TryStatement.CATCH_CLAUSES_PROPERTY, MethodInvocation.ARGUMENTS_PROPERTY, ConstructorInvocation.ARGUMENTS_PROPERTY, ClassInstanceCreation.ARGUMENTS_PROPERTY, SuperConstructorInvocation.ARGUMENTS_PROPERTY, SuperMethodInvocation.ARGUMENTS_PROPERTY }; for (ChildListPropertyDescriptor prop : enumLists) { if (node.getLocationInParent() == prop) { List<?> childList = (List<?>) node.getParent().getStructuralProperty(prop); int idx = childList.indexOf(node); id += "[" + idx + "]"; } } if (node instanceof CompilationUnit) { // IJavaElement je = ((CompilationUnit) node).getJavaElement(); CompilationUnit cu = ((CompilationUnit) node); id += "["; if (cu.getPackage() != null && cu.getPackage().getName() != null) id += clean(cu.getPackage().getName().getFullyQualifiedName() + "."); if (cu.types() != null && cu.types().size() >= 1 && ((AbstractTypeDeclaration) cu.types().get(0)).getName() != null) id += ((AbstractTypeDeclaration) cu.types().get(0)).getName().getFullyQualifiedName(); id += "]"; // id += "[" + clean(je.getPath().toPortableString()) + "]"; } return id; }
From source file:edu.umd.cs.findbugs.plugin.eclipse.quickfix.UseEqualsResolution.java
License:Open Source License
protected Expression createEqualsExpression(ASTRewrite rewrite, InfixExpression stringEqualityCheck) { Assert.isNotNull(rewrite);//w w w .ja v a 2 s. c o m Assert.isNotNull(stringEqualityCheck); final AST ast = rewrite.getAST(); MethodInvocation equalsInvocation = ast.newMethodInvocation(); Expression leftOperand = createLeftOperand(rewrite, stringEqualityCheck.getLeftOperand()); Expression rightOperand = createRightOperand(rewrite, stringEqualityCheck.getRightOperand()); equalsInvocation.setName(ast.newSimpleName(EQUALS_METHOD_NAME)); equalsInvocation.setExpression(leftOperand); ListRewrite argumentsRewrite = rewrite.getListRewrite(equalsInvocation, MethodInvocation.ARGUMENTS_PROPERTY); argumentsRewrite.insertLast(rightOperand, null); return equalsInvocation; }
From source file:nz.ac.massey.cs.care.refactoring.executers.IntroduceFactoryRefactoring.java
License:Open Source License
/** * Updates the constructor call./*w w w .j a va 2 s . c o m*/ * * @param ctorCall the ClassInstanceCreation to be marked as replaced * @param unitRewriter the AST rewriter * @param gd the edit group to use */ private void rewriteFactoryMethodCall(ClassInstanceCreation ctorCall, ASTRewrite unitRewriter, TextEditGroup gd) { AST ast = unitRewriter.getAST(); MethodInvocation factoryMethodCall = ast.newMethodInvocation(); ASTNode ctorCallParent = ctorCall.getParent(); StructuralPropertyDescriptor ctorCallLocation = ctorCall.getLocationInParent(); if (ctorCallLocation instanceof ChildListPropertyDescriptor) { ListRewrite ctorCallParentListRewrite = unitRewriter.getListRewrite(ctorCallParent, (ChildListPropertyDescriptor) ctorCallLocation); int index = ctorCallParentListRewrite.getOriginalList().indexOf(ctorCall); ctorCall = (ClassInstanceCreation) ctorCallParentListRewrite.getRewrittenList().get(index); } else { ctorCall = (ClassInstanceCreation) unitRewriter.get(ctorCallParent, ctorCallLocation); } ListRewrite actualFactoryArgs = unitRewriter.getListRewrite(factoryMethodCall, MethodInvocation.ARGUMENTS_PROPERTY); ListRewrite actualCtorArgs = unitRewriter.getListRewrite(ctorCall, ClassInstanceCreation.ARGUMENTS_PROPERTY); // Need to use a qualified name for the factory method if we're not // in the context of the class holding the factory. AbstractTypeDeclaration callOwner = (AbstractTypeDeclaration) ASTNodes.getParent(ctorCall, AbstractTypeDeclaration.class); ITypeBinding callOwnerBinding = callOwner.resolveBinding(); if (callOwnerBinding == null || !Bindings.equals(callOwner.resolveBinding(), fFactoryOwningClass.resolveBinding())) { String qualifier = fImportRewriter.addImport(fFactoryOwningClass.resolveBinding()); factoryMethodCall.setExpression(ASTNodeFactory.newName(ast, qualifier)); } factoryMethodCall.setName(ast.newSimpleName(fNewMethodName)); List<Expression> actualCtorArgsList = actualCtorArgs.getRewrittenList(); for (int i = 0; i < actualCtorArgsList.size(); i++) { Expression actualCtorArg = actualCtorArgsList.get(i); ASTNode movedArg; if (ASTNodes.isExistingNode(actualCtorArg)) { movedArg = unitRewriter.createMoveTarget(actualCtorArg); } else { unitRewriter.remove(actualCtorArg, null); movedArg = actualCtorArg; } actualFactoryArgs.insertLast(movedArg, gd); } unitRewriter.replace(ctorCall, factoryMethodCall, gd); }
From source file:org.eclipse.wb.core.model.JavaInfo.java
License:Open Source License
/** * @return the {@link ASTNode} that should be used to display given related {@link ASTNode}. *//*from w ww .j a va 2 s . c om*/ public static ASTNode getRelatedNodeForSource(ASTNode node) { ASTNode sourceNode = node; // part of invocation if (node.getLocationInParent() == MethodInvocation.EXPRESSION_PROPERTY) { sourceNode = node.getParent(); } if (node.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) { sourceNode = node.getParent(); } if (node.getLocationInParent() == SuperConstructorInvocation.ARGUMENTS_PROPERTY) { sourceNode = node.getParent(); } if (node.getLocationInParent() == SuperMethodInvocation.ARGUMENTS_PROPERTY) { sourceNode = node.getParent(); } if (node.getLocationInParent() == ClassInstanceCreation.ARGUMENTS_PROPERTY) { sourceNode = node.getParent(); } // javaInfo.foo = something if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) { QualifiedName qualifiedName = (QualifiedName) node.getParent(); sourceNode = qualifiedName; if (qualifiedName.getLocationInParent() == Assignment.LEFT_HAND_SIDE_PROPERTY) { sourceNode = qualifiedName.getParent(); } } // done return sourceNode; }
From source file:org.eclipse.wb.internal.core.model.util.factory.FactoryApplyAction.java
License:Open Source License
/** * @param oldArguments/*w ww . j av a 2 s . c o m*/ * the arguments of old {@link ClassInstanceCreation} or {@link MethodInvocation} that * was used to create component. * * @return the arguments for factory method invocation. */ private List<String> getFactoryArguments(List<Expression> oldArguments) throws Exception { List<String> arguments = Lists.newArrayList(); for (ParameterDescription parameter : m_description.getParameters()) { // check for "parent" if (parameter.isParent()) { m_hasParentArgument = true; arguments.add(TemplateUtils.getExpression(m_component.getParentJava())); continue; } // try to use source from bound property { GenericPropertyImpl property = getGenericProperty(parameter.getProperty()); if (property != null) { Expression expression = ((GenericProperty) property).getExpression(); // argument of creation if (oldArguments.contains(expression)) { arguments.add(m_editor.getSource(expression)); continue; } // argument of separate method (only literal) if (expression.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY && (expression instanceof NullLiteral || expression instanceof BooleanLiteral || expression instanceof NumberLiteral || expression instanceof StringLiteral)) { arguments.add(m_editor.getSource(expression)); m_editor.removeEnclosingStatement(expression); continue; } } } // default source arguments.add(parameter.getDefaultSource()); } return arguments; }
From source file:org.eclipse.wb.internal.rcp.parser.RcpExecutionFlowProvider.java
License:Open Source License
@Override public boolean shouldVisit(AnonymousClassDeclaration anonymous) throws Exception { // Realm.runWithDefault() if (AstNodeUtils.isSuccessorOf(anonymous, "java.lang.Runnable")) { ClassInstanceCreation creation = (ClassInstanceCreation) anonymous.getParent(); if (creation.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) { MethodInvocation invocation = (MethodInvocation) creation.getParent(); return AstNodeUtils.isMethodInvocation(invocation, "org.eclipse.core.databinding.observable.Realm", "runWithDefault(org.eclipse.core.databinding.observable.Realm,java.lang.Runnable)"); }//www . j a va2 s. com } // unknown pattern return false; }
From source file:org.eclipse.wb.internal.swing.model.bean.ActionExpressionAccessor.java
License:Open Source License
@Override public boolean setExpression(final JavaInfo javaInfo, final String source) throws Exception { final Expression expression = getExpression(javaInfo); if (expression != null) { final AstEditor editor = javaInfo.getEditor(); if (source == null) { if (expression.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) { ExecutionUtils.run(javaInfo, new RunnableEx() { public void run() throws Exception { editor.removeEnclosingStatement(expression); }//www.j av a 2 s.c o m }); } } else if (!editor.getSource(expression).equals(source)) { ExecutionUtils.run(javaInfo, new RunnableEx() { public void run() throws Exception { editor.replaceExpression(expression, source); } }); } } else if (source != null) { ExecutionUtils.run(javaInfo, new RunnableEx() { public void run() throws Exception { String statementSource = "putValue(" + m_keyName + ", " + source + ");"; javaInfo.getEditor().addStatement(statementSource, getTarget()); } private StatementTarget getTarget() throws Exception { // if first statement in constructor is "super", add after it Block block = m_actionInfo.getInitializationBlocks().get(0); List<Statement> statements = DomGenerics.statements(block); if (!statements.isEmpty()) { Statement statement = statements.get(0); if (statement instanceof SuperConstructorInvocation) { return new StatementTarget(statement, false); } } // in other case add as first statement in constructor return new StatementTarget(block, true); } }); } // success return true; }
From source file:org.eclipse.wb.internal.swing.model.bean.ButtonGroupInfo.java
License:Open Source License
/** * Removes given {@link AbstractButton} from any {@link ButtonGroupInfo}. *///from w ww .j a v a 2s. co m public static void clearButton(ComponentInfo button) throws Exception { assertIsButton(button); for (ASTNode relatedNode : button.getRelatedNodes()) { if (relatedNode.getLocationInParent() == MethodInvocation.ARGUMENTS_PROPERTY) { MethodInvocation invocation = (MethodInvocation) relatedNode.getParent(); if (AstNodeUtils.getMethodSignature(invocation).equals("add(javax.swing.AbstractButton)")) { button.getEditor().removeEnclosingStatement(invocation); } } } }