List of usage examples for org.eclipse.jdt.core.dom ClassInstanceCreation ARGUMENTS_PROPERTY
ChildListPropertyDescriptor ARGUMENTS_PROPERTY
To view the source code for org.eclipse.jdt.core.dom ClassInstanceCreation ARGUMENTS_PROPERTY.
Click Source Link
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 + "]"; }/* w w w . j a v a2 s .co 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:nz.ac.massey.cs.care.refactoring.executers.IntroduceFactoryRefactoring.java
License:Open Source License
/** * Updates the constructor call.//from ww w . j a v a 2s . c om * * @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}. *//*www . j av a 2s .com*/ 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.rcp.model.jface.viewers.TableViewerColumnInfo.java
License:Open Source License
private JavaProperty createSorterProperty() { return new JavaProperty(this, "sorter", TableViewerColumnSorterPropertyEditor.INSTANCE) { @Override/*from w w w .j ava 2 s . com*/ public boolean isModified() throws Exception { return getValue() != null; } @Override public Object getValue() throws Exception { for (ASTNode node : getRelatedNodes()) { if (node.getLocationInParent() == ClassInstanceCreation.ARGUMENTS_PROPERTY) { ClassInstanceCreation creation = (ClassInstanceCreation) node.getParent(); if (AstNodeUtils.isSuccessorOf(creation, "org.eclipse.wb.swt.TableViewerColumnSorter")) { return creation; } } } return null; } @Override public void setValue(Object value) throws Exception { final ASTNode node = (ASTNode) getValue(); if (node != null) { ExecutionUtils.run(m_this, new RunnableEx() { public void run() throws Exception { m_this.getEditor().removeEnclosingStatement(node); } }); } } }; }