List of usage examples for org.eclipse.jdt.core.dom QualifiedName NAME_PROPERTY
ChildPropertyDescriptor NAME_PROPERTY
To view the source code for org.eclipse.jdt.core.dom QualifiedName NAME_PROPERTY.
Click Source Link
From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java
License:Open Source License
public static void getTypeProposals(IInvocationContext context, IProblemLocation problem, Map<String, LinkedCorrectionProposal> proposals) throws CoreException { ICompilationUnit cu = context.getCompilationUnit(); ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot()); if (selectedNode == null) { return;/*from w w w .jav a2s . c o m*/ } int kind = evauateTypeKind(selectedNode, cu.getJavaProject()); while (selectedNode.getLocationInParent() == QualifiedName.NAME_PROPERTY) { selectedNode = selectedNode.getParent(); } Name node = null; if (selectedNode instanceof SimpleType) { node = ((SimpleType) selectedNode).getName(); } else if (selectedNode instanceof ArrayType) { Type elementType = ((ArrayType) selectedNode).getElementType(); if (elementType.isSimpleType()) { node = ((SimpleType) elementType).getName(); } else { return; } } else if (selectedNode instanceof Name) { node = (Name) selectedNode; } else { return; } while (node.getParent() instanceof QualifiedName) { node = (Name) node.getParent(); } if (selectedNode != node) { kind = evauateTypeKind(node, cu.getJavaProject()); } if ((kind & (SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES)) != 0) { kind &= ~SimilarElementsRequestor.ANNOTATIONS; // only propose annotations when there are no other suggestions } addNewTypeProposals(cu, node, kind, IProposalRelevance.NEW_TYPE, proposals); }
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) * // ww w .ja v a 2 s .c o m * * @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:edu.illinois.jflow.core.transformations.code.ExtractClosureAnalyzer.java
License:Open Source License
@Override public void endVisit(CompilationUnit node) { RefactoringStatus status = getStatus(); superCall: {/* ww w . j a v a2s. c om*/ if (status.hasFatalError()) break superCall; if (!hasSelectedNodes()) { ASTNode coveringNode = getLastCoveringNode(); if (coveringNode instanceof Block && coveringNode.getParent() instanceof MethodDeclaration) { MethodDeclaration methodDecl = (MethodDeclaration) coveringNode.getParent(); Message[] messages = ASTNodes.getMessages(methodDecl, ASTNodes.NODE_ONLY); if (messages.length > 0) { status.addFatalError( Messages.format(JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_compile_errors, BasicElementLabels .getJavaElementName(methodDecl.getName().getIdentifier())), JavaStatusContext.create(fCUnit, methodDecl)); break superCall; } } status.addFatalError(JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_only_method_body); break superCall; } fEnclosingBodyDeclaration = (BodyDeclaration) ASTNodes.getParent(getFirstSelectedNode(), BodyDeclaration.class); if (fEnclosingBodyDeclaration == null || (fEnclosingBodyDeclaration.getNodeType() != ASTNode.METHOD_DECLARATION && fEnclosingBodyDeclaration.getNodeType() != ASTNode.FIELD_DECLARATION && fEnclosingBodyDeclaration.getNodeType() != ASTNode.INITIALIZER)) { status.addFatalError(JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_only_method_body); break superCall; } else if (ASTNodes.getEnclosingType(fEnclosingBodyDeclaration) == null) { status.addFatalError( JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_compile_errors_no_parent_binding); break superCall; } else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) { fEnclosingMethodBinding = ((MethodDeclaration) fEnclosingBodyDeclaration).resolveBinding(); } if (!isSingleExpressionOrStatementSet()) { status.addFatalError(JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_single_expression_or_set); break superCall; } if (isExpressionSelected()) { ASTNode expression = getFirstSelectedNode(); if (expression instanceof Name) { Name name = (Name) expression; if (name.resolveBinding() instanceof ITypeBinding) { status.addFatalError( JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_type_reference); break superCall; } if (name.resolveBinding() instanceof IMethodBinding) { status.addFatalError( JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_method_name_reference); break superCall; } if (name.resolveBinding() instanceof IVariableBinding) { StructuralPropertyDescriptor locationInParent = name.getLocationInParent(); if (locationInParent == QualifiedName.NAME_PROPERTY || (locationInParent == FieldAccess.NAME_PROPERTY && !(((FieldAccess) name.getParent()) .getExpression() instanceof ThisExpression))) { status.addFatalError( JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_part_of_qualified_name); break superCall; } } if (name.isSimpleName() && ((SimpleName) name).isDeclaration()) { status.addFatalError( JFlowRefactoringCoreMessages.ExtractClosureAnalyzer_cannot_extract_name_in_declaration); break superCall; } } fForceStatic = ASTNodes.getParent(expression, ASTNode.SUPER_CONSTRUCTOR_INVOCATION) != null || ASTNodes.getParent(expression, ASTNode.CONSTRUCTOR_INVOCATION) != null; } status.merge(LocalTypeAnalyzer.perform(fEnclosingBodyDeclaration, getSelection())); computeLastStatementSelected(); } super.endVisit(node); }
From source file:org.apache.felix.sigil.eclipse.ui.internal.quickfix.ImportQuickFixProcessor.java
License:Apache License
private Name findNode(IInvocationContext context, IProblemLocation problem) { ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot()); if (selectedNode == null) { return null; }/*from w w w .j ava 2s.co m*/ while (selectedNode.getLocationInParent() == QualifiedName.NAME_PROPERTY) { selectedNode = selectedNode.getParent(); } Name node = null; if (selectedNode instanceof Type) { node = findName((Type) selectedNode); } else if (selectedNode instanceof Name) { node = (Name) selectedNode; } return node; }
From source file:org.eclipse.ajdt.internal.ui.editor.quickfix.UnresolvedElementsSubProcessor.java
License:Open Source License
public static void getTypeProposals(IInvocationContext context, IProblemLocation problem, Collection proposals) throws CoreException { ICompilationUnit cu = context.getCompilationUnit(); ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot()); if (selectedNode == null) { return;// w w w . j av a2 s. com } // AspectJ Change Begin // need to add non-null checks for quick fix inside aspects // ensures Aspects in java files fail gracefully if (selectedNode.getParent() == null) { return; } int kind = evauateTypeKind(selectedNode, cu.getJavaProject()); while ((selectedNode != null) && (selectedNode.getLocationInParent() == QualifiedName.NAME_PROPERTY)) { selectedNode = selectedNode.getParent(); } if (selectedNode == null) { return; } // AspectJ Change End Name node = null; if (selectedNode instanceof SimpleType) { node = ((SimpleType) selectedNode).getName(); } else if (selectedNode instanceof ArrayType) { Type elementType = ((ArrayType) selectedNode).getElementType(); if (elementType.isSimpleType()) { node = ((SimpleType) elementType).getName(); } else { return; } } else if (selectedNode instanceof Name) { node = (Name) selectedNode; } else { return; } // change to similar type proposals addSimilarTypeProposals(kind, cu, node, 3, proposals); // add type while (node.getParent() instanceof QualifiedName) { node = (Name) node.getParent(); } addNewTypeProposals(cu, node, kind, 0, proposals); }
From source file:org.eclipse.che.jdt.dom.ASTNodes.java
License:Open Source License
/** * For {@link Name} or {@link org.eclipse.jdt.core.dom.Type} nodes, returns the topmost {@link org.eclipse.jdt.core.dom.Type} node * that shares the same type binding as the given node. * * @param node/*ww w . j a va 2 s . c om*/ * an ASTNode * @return the normalized {@link org.eclipse.jdt.core.dom.Type} node or the original node */ public static ASTNode getNormalizedNode(ASTNode node) { ASTNode current = node; // normalize name if (QualifiedName.NAME_PROPERTY.equals(current.getLocationInParent())) { current = current.getParent(); } // normalize type if (QualifiedType.NAME_PROPERTY.equals(current.getLocationInParent()) || SimpleType.NAME_PROPERTY.equals(current.getLocationInParent()) || NameQualifiedType.NAME_PROPERTY.equals(current.getLocationInParent())) { current = current.getParent(); } // normalize parameterized types if (ParameterizedType.TYPE_PROPERTY.equals(current.getLocationInParent())) { current = current.getParent(); } return current; }
From source file:org.eclipse.recommenders.jdt.templates.SnippetCodeBuilder.java
License:Open Source License
private boolean isUnqualified(SimpleName name) { return !QualifiedName.NAME_PROPERTY.equals(name.getLocationInParent()); }
From source file:org.eclipse.scout.sdk.saml.importer.internal.jdt.imports.OrganizeImportsHelper.java
License:Open Source License
public static ASTNode getNormalizedNode(ASTNode node) { ASTNode current = node;//from w w w. java2 s. c o m // normalize name if (QualifiedName.NAME_PROPERTY.equals(current.getLocationInParent())) { current = current.getParent(); } // normalize type if (QualifiedType.NAME_PROPERTY.equals(current.getLocationInParent()) || SimpleType.NAME_PROPERTY.equals(current.getLocationInParent())) { current = current.getParent(); } // normalize parameterized types if (ParameterizedType.TYPE_PROPERTY.equals(current.getLocationInParent())) { current = current.getParent(); } return current; }
From source file:org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.java
License:Open Source License
/** * @return <code>true</code> if given {@link ASTNode} is single variable {@link SimpleName} or * {@link FieldAccess} like "this.fieldName". *//*from w w w. jav a 2 s . c o m*/ public static boolean isVariable(ASTNode variable) { // FieldAccess if (variable instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess) variable; return fieldAccess.getExpression() instanceof ThisExpression; } // SimpleName if (variable instanceof SimpleName) { StructuralPropertyDescriptor locationInParent = variable.getLocationInParent(); if (locationInParent == MethodInvocation.NAME_PROPERTY || locationInParent == SimpleType.NAME_PROPERTY || locationInParent == FieldAccess.NAME_PROPERTY || locationInParent == QualifiedName.NAME_PROPERTY || locationInParent == MethodDeclaration.NAME_PROPERTY || locationInParent == TypeDeclaration.NAME_PROPERTY) { return false; } // variable has binding return getVariableBinding(variable) != null; } // unknown ASTNode return false; }