List of usage examples for org.eclipse.jdt.core.dom MethodInvocation getLocationInParent
public final StructuralPropertyDescriptor getLocationInParent()
null
if this is a root node. From source file:com.bsiag.eclipse.jdt.java.formatter.linewrap.WrapPreparator.java
License:Open Source License
@Override public boolean visit(MethodInvocation node) { handleArguments(node.arguments(), this.options.alignment_for_arguments_in_method_invocation); boolean isInvocationChainRoot = !(node.getParent() instanceof MethodInvocation) || node.getLocationInParent() != MethodInvocation.EXPRESSION_PROPERTY; if (isInvocationChainRoot) { Expression expression = node; MethodInvocation invocation = node; while (expression instanceof MethodInvocation) { invocation = (MethodInvocation) expression; expression = invocation.getExpression(); if (expression != null) this.wrapIndexes.add(this.tm.firstIndexBefore(invocation.getName(), TokenNameDOT)); }/*from w w w . j a va 2 s.c o m*/ Collections.reverse(this.wrapIndexes); this.wrapParentIndex = (expression != null) ? this.tm.lastIndexIn(expression, -1) : this.tm.lastIndexIn(invocation, -1); this.wrapGroupEnd = this.tm.firstIndexIn(node.getName(), -1); handleWrap(this.options.alignment_for_selector_in_method_invocation); } return true; }
From source file:de.ovgu.cide.export.physical.ahead.MethodObjectHelper.java
License:Open Source License
/** * replaces all implicit access to "this" with explicit access (i.e. writes * a this. before every method invocation or field access where possible) * /*w w w . ja v a 2 s . com*/ * * @param targetMethod * @param colorManager */ public static void makeThisAccessExplicit(final MethodDeclaration targetMethod) { final AST ast = targetMethod.getAST(); final TypeDeclaration thisClass = RefactoringUtils.getContainingType(targetMethod); targetMethod.accept(new ASTVisitor() { @Override public boolean visit(MethodInvocation node) { if (node.getExpression() == null) node.setExpression(ast.newThisExpression()); return super.visit(node); } @Override public boolean visit(FieldAccess node) { if (node.getExpression() == null) node.setExpression(ast.newThisExpression()); return super.visit(node); } @Override public void endVisit(SimpleName node) { if (node.getLocationInParent() == FieldAccess.NAME_PROPERTY) return; if (node.getLocationInParent() == QualifiedName.NAME_PROPERTY) return; IBinding binding = ((Name) node).resolveBinding(); if (binding instanceof IVariableBinding) { IVariableBinding vBinding = (IVariableBinding) binding; if (vBinding.isField()) { ITypeBinding bc = vBinding.getDeclaringClass(); if (thisClass.resolveBinding() == bc) { /* * workaround if a field access is represented by a * qualified name (this qualified name must be first * replaced by a field access */ if (node.getLocationInParent() == QualifiedName.QUALIFIER_PROPERTY) { QualifiedName parent = (QualifiedName) node.getParent(); parent.setQualifier(ast.newSimpleName("notUsed")); FieldAccess fieldAccess = ast.newFieldAccess(); RefactoringUtils.replaceASTNode(parent, fieldAccess); fieldAccess.setExpression(node); fieldAccess.setName(ast.newSimpleName(parent.getName().getIdentifier())); } FieldAccess fieldAccess = ast.newFieldAccess(); RefactoringUtils.replaceASTNode(node, fieldAccess); fieldAccess.setExpression(ast.newThisExpression()); fieldAccess.setName(node); } } } } }); }
From source file:org.eclipse.wb.internal.core.model.variable.FieldInitializerVariableSupport.java
License:Open Source License
/** * @return the related {@link Statement}'s, that should be moved with component. */// www.ja v a2 s.c om private List<Statement> getRelatedStatements() { List<Statement> statements = Lists.newArrayList(); // add association statement (when we move component, association may not exist) if (m_javaInfo.getAssociation() != null) { Statement associationStatement = m_javaInfo.getAssociation().getStatement(); if (associationStatement != null) { statements.add(associationStatement); } } // add related statements for (ASTNode relatedNode : m_javaInfo.getRelatedNodes()) { // add Statement with MethodInvocation { MethodInvocation invocation = m_javaInfo.getMethodInvocation(relatedNode); if (invocation != null && invocation.getLocationInParent() == ExpressionStatement.EXPRESSION_PROPERTY) { statements.add((Statement) invocation.getParent()); continue; } } // add Statement with Assignment { ASTNode fieldAccess = AstNodeUtils.getFieldAssignment(relatedNode); if (fieldAccess != null) { Assignment fieldAssignment = (Assignment) fieldAccess.getParent(); if (fieldAssignment.getLocationInParent() == ExpressionStatement.EXPRESSION_PROPERTY) { statements.add((Statement) fieldAssignment.getParent()); continue; } } } } return statements; }
From source file:org.eclipse.wb.internal.rcp.parser.ParseFactory.java
License:Open Source License
@Override public JavaInfo create(AstEditor editor, MethodInvocation invocation, IMethodBinding methodBinding, Expression[] arguments, JavaInfo expressionInfo, JavaInfo[] argumentInfos, IJavaInfoParseResolver javaInfoResolver) throws Exception { if (!hasRCP(editor)) { return null; }//from ww w .java 2s . com // check "super" { JavaInfo javaInfo = super.create(editor, invocation, methodBinding, arguments, expressionInfo, argumentInfos, javaInfoResolver); if (javaInfo != null) { return javaInfo; } } // support for org.eclipse.ui.IPerspectiveFactory if (expressionInfo instanceof PageLayoutInfo) { PageLayoutInfo pageLayout = (PageLayoutInfo) expressionInfo; String signature = AstNodeUtils.getMethodSignature(methodBinding); if (signature.equals("addView(java.lang.String,int,float,java.lang.String)") || signature.equals("addPlaceholder(java.lang.String,int,float,java.lang.String)") || signature.equals("addStandaloneView(java.lang.String,boolean,int,float,java.lang.String)") || signature.equals( "addStandaloneViewPlaceholder(java.lang.String,int,float,java.lang.String,boolean)")) { return new PageLayoutAddViewInfo(pageLayout, invocation); } if (signature.equals("createFolder(java.lang.String,int,float,java.lang.String)") || signature.equals("createPlaceholderFolder(java.lang.String,int,float,java.lang.String)")) { return new PageLayoutCreateFolderInfo(pageLayout, invocation); } if (signature.equals("addFastView(java.lang.String)") || signature.equals("addFastView(java.lang.String,float)")) { return new FastViewInfo(pageLayout, pageLayout.getFastViewContainer(), invocation); } if (signature.equals("addShowViewShortcut(java.lang.String)")) { return new ViewShortcutInfo(pageLayout, pageLayout.getViewShortcutContainer(), invocation); } if (signature.equals("addPerspectiveShortcut(java.lang.String)")) { return new PerspectiveShortcutInfo(pageLayout, pageLayout.getPerspectiveShortcutContainer(), invocation); } return null; } else if (expressionInfo instanceof PageLayoutCreateFolderInfo) { PageLayoutCreateFolderInfo folder = (PageLayoutCreateFolderInfo) expressionInfo; String signature = AstNodeUtils.getMethodSignature(methodBinding); if (signature.equals("addView(java.lang.String)") || signature.equals("addPlaceholder(java.lang.String)")) { return new FolderViewInfo(folder, invocation); } } // Action from org.eclipse.ui.actions.ActionFactory if (invocation.getExpression() instanceof QualifiedName) { QualifiedName qualifiedName = (QualifiedName) invocation.getExpression(); if (AstNodeUtils.getFullyQualifiedName(qualifiedName.getQualifier(), false) .equals("org.eclipse.ui.actions.ActionFactory")) { CreationSupport creationSupport = new ActionFactoryCreationSupport(invocation, qualifiedName.getName().getIdentifier()); JavaInfo component = JavaInfoUtils.createJavaInfo(editor, getClass(editor, methodBinding.getReturnType()), creationSupport); return component; } } // special support for IManagedForm.getToolkit() if (invocation.getLocationInParent() == ConstructorInvocation.ARGUMENTS_PROPERTY && AstNodeUtils .isMethodInvocation(invocation, "org.eclipse.ui.forms.IManagedForm", "getToolkit()")) { CreationSupport creationSupport = new OpaqueCreationSupport(invocation); InstanceFactoryInfo toolkit = InstanceFactoryInfo.createFactory(editor, getClass(editor, methodBinding.getReturnType()), creationSupport); EditorState.get(editor).getTmp_Components().add(toolkit); return toolkit; } // no JavaInfo for MethodInvocation return null; }