List of usage examples for org.eclipse.jdt.core.dom ThisExpression setQualifier
public void setQualifier(Name name)
From source file:java5totext.input.JDTVisitor.java
License:Open Source License
@Override public void endVisit(org.eclipse.jdt.core.dom.ThisExpression node) { ThisExpression element = (ThisExpression) this.binding.get(node); this.initializeNode(element, node); if (this.binding.get(node.getQualifier()) != null) element.setQualifier((NamedElementRef) this.binding.get(node.getQualifier())); }
From source file:net.sf.eclipsecs.ui.quickfixes.coding.RequireThisQuickfix.java
License:Open Source License
/** * {@inheritDoc}/*from w w w . ja v a 2 s. c om*/ */ protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) { return new ASTVisitor() { @Override public boolean visit(final SimpleName node) { if (containsPosition(node, markerStartOffset)) { replace(node, findFieldReplacement(node, node, 0)); } return false; } @Override public boolean visit(final MethodInvocation node) { if (containsPosition(node, markerStartOffset)) { replace(node, findMethodReplacement(node.getName(), node, node, 0)); } return false; } private Expression findFieldReplacement(final SimpleName name, final ASTNode node, int typeLevel) { int level = typeLevel; final ASTNode parent = node.getParent(); if (parent instanceof TypeDeclaration) { level++; final TypeDeclaration type = (TypeDeclaration) parent; for (final FieldDeclaration fieldDeclaration : type.getFields()) { @SuppressWarnings("unchecked") final List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments(); for (final VariableDeclarationFragment fragment : fragments) { if (name.getFullyQualifiedName().equals(fragment.getName().getFullyQualifiedName())) { return createFieldAccessReplacement(level == 1 ? null : type, name); } } } } return findFieldReplacement(name, parent, level); } private FieldAccess createFieldAccessReplacement(final TypeDeclaration type, final SimpleName name) { final AST ast = name.getAST(); final FieldAccess fieldAccess = ast.newFieldAccess(); final ThisExpression thisExpr = ast.newThisExpression(); if (type != null) { thisExpr.setQualifier(copy(type.getName())); } fieldAccess.setExpression(thisExpr); fieldAccess.setName(copy(name)); return fieldAccess; } private Expression findMethodReplacement(final SimpleName name, ASTNode contextNode, final MethodInvocation node, int typeLevel) { int level = typeLevel; final ASTNode parent = contextNode.getParent(); if (parent instanceof TypeDeclaration) { level++; final TypeDeclaration type = (TypeDeclaration) parent; for (final MethodDeclaration methodDeclaration : type.getMethods()) { if (name.getFullyQualifiedName() .equals(methodDeclaration.getName().getFullyQualifiedName())) { return createMethodInvocationReplacement(level == 1 ? null : type, node); } } } return findMethodReplacement(name, parent, node, level); } private Expression createMethodInvocationReplacement(final TypeDeclaration type, MethodInvocation origMethodInvocation) { final AST ast = origMethodInvocation.getAST(); final MethodInvocation methodInvocation = copy(origMethodInvocation); final ThisExpression thisExpr = ast.newThisExpression(); if (type != null) { thisExpr.setQualifier(copy(type.getName())); } methodInvocation.setExpression(thisExpr); return methodInvocation; } }; }
From source file:org.eclipse.ajdt.internal.ui.editor.quickfix.UnresolvedElementsSubProcessor.java
License:Open Source License
private static void addQualifierToOuterProposal(IInvocationContext context, MethodInvocation invocationNode, IMethodBinding binding, Collection proposals) throws CoreException { ITypeBinding declaringType = binding.getDeclaringClass(); ITypeBinding parentType = Bindings.getBindingOfParentType(invocationNode); ITypeBinding currType = parentType;/*from ww w . j a v a 2 s. c om*/ boolean isInstanceMethod = !Modifier.isStatic(binding.getModifiers()); while (currType != null && !Bindings.isSuperType(declaringType, currType)) { if (isInstanceMethod && Modifier.isStatic(currType.getModifiers())) { return; } currType = currType.getDeclaringClass(); } if (currType == null || currType == parentType) { return; } ASTRewrite rewrite = ASTRewrite.create(invocationNode.getAST()); String label = Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_changetoouter_description, ASTResolving.getTypeSignature(currType)); Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); ASTRewriteCorrectionProposal proposal = new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 8, image); ImportRewrite imports = proposal.createImportRewrite(context.getASTRoot()); AST ast = invocationNode.getAST(); String qualifier = imports.addImport(currType); Name name = ASTNodeFactory.newName(ast, qualifier); Expression newExpression; if (isInstanceMethod) { ThisExpression expr = ast.newThisExpression(); expr.setQualifier(name); newExpression = expr; } else { newExpression = name; } rewrite.set(invocationNode, MethodInvocation.EXPRESSION_PROPERTY, newExpression, null); proposals.add(proposal); }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
public ThisExpression convert(org.eclipse.jdt.internal.compiler.ast.QualifiedThisReference reference) { final ThisExpression thisExpression = new ThisExpression(this.ast); thisExpression.setSourceRange(reference.sourceStart, reference.sourceEnd - reference.sourceStart + 1); thisExpression.setQualifier(convert(reference.qualification)); if (this.resolveBindings) { recordNodes(thisExpression, reference); recordPendingThisExpressionScopeResolution(thisExpression); }/*from w w w.j a v a2s . c om*/ return thisExpression; }
From source file:org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.java
License:Open Source License
@Override public void endVisit(final org.eclipse.jdt.core.dom.ThisExpression node) { ThisExpression element = (ThisExpression) this.binding.get(node); initializeNode(element, node);// ww w . j av a 2 s . co m if (this.binding.get(node.getQualifier()) != null) { element.setQualifier(JDTVisitorUtils.completeTypeAccess(this.binding.get(node.getQualifier()), this)); } }
From source file:org.whole.lang.visitors.JavaJavaModelGeneratorVisitor.java
License:Open Source License
public void visit(ThisExpression entity) { org.eclipse.jdt.core.dom.ThisExpression exp = builder().ast.newThisExpression(); if (!EntityUtils.isResolver(entity.getQualifier())) exp.setQualifier(astOf(entity.getQualifier())); setExpression(exp);/*from w w w . ja va 2s. c o m*/ }