org.eclipse.jdt.core.dom.MemberRef Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.MemberRef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MovedMemberAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean visit(MemberRef node) {
	IBinding binding= node.resolveBinding();
	if (isSourceAccess(binding)) {
		if (isMovedMember(binding)) {
			if (node.getQualifier() != null)
				rewrite(node, fTarget);
		} else
			rewrite(node, fSource);

	} else if (isTargetAccess(binding)) {
		// remove qualifier:
		SimpleName replace= (SimpleName)fCuRewrite.getASTRewrite().createCopyTarget(node.getName());
		fCuRewrite.getASTRewrite().replace(node, replace, null);
		fCuRewrite.getImportRemover().registerRemovedNode(node);
	}
	return super.visit(node);
}
 
Example #2
Source File: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private OccurrenceUpdate<? extends ASTNode> createOccurrenceUpdate(ASTNode node, CompilationUnitRewrite cuRewrite, RefactoringStatus result) {
	if (BUG_89686 && node instanceof SimpleName && node.getParent() instanceof EnumConstantDeclaration)
		node= node.getParent();

	if (Invocations.isInvocationWithArguments(node))
		return new ReferenceUpdate(node, cuRewrite, result);

	else if (node instanceof SimpleName && node.getParent() instanceof MethodDeclaration)
		return new DeclarationUpdate((MethodDeclaration) node.getParent(), cuRewrite, result);

	else if (node instanceof MemberRef || node instanceof MethodRef)
		return new DocReferenceUpdate(node, cuRewrite, result);

	else if (ASTNodes.getParent(node, ImportDeclaration.class) != null)
		return new StaticImportUpdate((ImportDeclaration) ASTNodes.getParent(node, ImportDeclaration.class), cuRewrite, result);

	else if (node instanceof LambdaExpression)
		return new LambdaExpressionUpdate((LambdaExpression) node, cuRewrite, result);

	else if (node.getLocationInParent() == ExpressionMethodReference.NAME_PROPERTY)
		return new ExpressionMethodRefUpdate((ExpressionMethodReference) node.getParent(), cuRewrite, result);

	else
		return new NullOccurrenceUpdate(node, cuRewrite, result);
}
 
Example #3
Source File: DelegateFieldCreator.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected ASTNode createDocReference(BodyDeclaration declaration) {
	MemberRef ref= getAst().newMemberRef();
	ref.setName(getAst().newSimpleName(getNewElementName()));

	if (isMoveToAnotherFile()) {
		ref.setQualifier(createDestinationTypeName());
	}
	return ref;
}
 
Example #4
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final MemberRef node) {
  Name _qualifier = node.getQualifier();
  boolean _tripleNotEquals = (_qualifier != null);
  if (_tripleNotEquals) {
    node.getQualifier().accept(this);
  }
  this.appendToBuffer("#");
  node.getName().accept(this);
  return false;
}
 
Example #5
Source File: MoveStaticMemberAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void rewrite(MemberRef node, ITypeBinding type) {
	Name qualifier= node.getQualifier();
	if (qualifier == null) {
		ImportRewriteContext context= new ContextSensitiveImportRewriteContext(node, fCuRewrite.getImportRewrite());
		Type result= fCuRewrite.getImportRewrite().addImport(type, fCuRewrite.getAST(), context);
		fCuRewrite.getImportRemover().registerAddedImport(type.getQualifiedName());
		qualifier= ASTNodeFactory.newName(fCuRewrite.getAST(), ASTFlattener.asString(result));
		fCuRewrite.getASTRewrite().set(node, MemberRef.QUALIFIER_PROPERTY, qualifier, fCuRewrite.createGroupDescription(REFERENCE_UPDATE));
		fNeedsImport= true;
	} else {
		rewriteName(qualifier, type);
	}
	fProcessed.add(node.getName());
}
 
Example #6
Source File: ChangeSignatureProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected SimpleName getMethodNameNode() {
	if (fNode instanceof MemberRef)
		return ((MemberRef) fNode).getName();

	if (fNode instanceof MethodRef)
		return ((MethodRef) fNode).getName();

	return null;
}
 
Example #7
Source File: DelegateFieldCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected ASTNode createDocReference(BodyDeclaration declaration) {
	MemberRef ref= getAst().newMemberRef();
	ref.setName(getAst().newSimpleName(getNewElementName()));

	if (isMoveToAnotherFile())
		ref.setQualifier(createDestinationTypeName());
	return ref;
}
 
Example #8
Source File: ImportReferencesCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(MemberRef node) {
	Name qualifier= node.getQualifier();
	if (qualifier != null) {
		typeRefFound(qualifier);
	}
	return false;
}
 
Example #9
Source File: ReferenceAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(MemberRef node) {
	if (isMovedMember(node.resolveBinding()))
		rewrite(node, fTarget);
	return false;
}
 
Example #10
Source File: AstMatchingNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(MemberRef node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #11
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(MemberRef node) {
	endVisitNode(node);
}
 
Example #12
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(MemberRef node) {
	return visitNode(node);
}
 
Example #13
Source File: CopyQualifiedNameAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Object getSelectedElement(JavaEditor editor) {
	ISourceViewer viewer= editor.getViewer();
	if (viewer == null)
		return null;

	Point selectedRange= viewer.getSelectedRange();
	int length= selectedRange.y;
	int offset= selectedRange.x;

	ITypeRoot element= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
	if (element == null)
		return null;

	CompilationUnit ast= SharedASTProvider.getAST(element, SharedASTProvider.WAIT_YES, null);
	if (ast == null)
		return null;

	NodeFinder finder= new NodeFinder(ast, offset, length);
	ASTNode node= finder.getCoveringNode();

	IBinding binding= null;
	if (node instanceof Name) {
		binding= getConstructorBindingIfAvailable((Name)node);
		if (binding != null)
			return binding;
		binding= ((Name)node).resolveBinding();
	} else if (node instanceof MethodInvocation) {
		binding= ((MethodInvocation)node).resolveMethodBinding();
	} else if (node instanceof MethodDeclaration) {
		binding= ((MethodDeclaration)node).resolveBinding();
	} else if (node instanceof Type) {
		binding= ((Type)node).resolveBinding();
	} else if (node instanceof AnonymousClassDeclaration) {
		binding= ((AnonymousClassDeclaration)node).resolveBinding();
	} else if (node instanceof TypeDeclaration) {
		binding= ((TypeDeclaration)node).resolveBinding();
	} else if (node instanceof CompilationUnit) {
		return ((CompilationUnit)node).getJavaElement();
	} else if (node instanceof Expression) {
		binding= ((Expression)node).resolveTypeBinding();
	} else if (node instanceof ImportDeclaration) {
		binding= ((ImportDeclaration)node).resolveBinding();
	} else if (node instanceof MemberRef) {
		binding= ((MemberRef)node).resolveBinding();
	} else if (node instanceof MemberValuePair) {
		binding= ((MemberValuePair)node).resolveMemberValuePairBinding();
	} else if (node instanceof PackageDeclaration) {
		binding= ((PackageDeclaration)node).resolveBinding();
	} else if (node instanceof TypeParameter) {
		binding= ((TypeParameter)node).resolveBinding();
	} else if (node instanceof VariableDeclaration) {
		binding= ((VariableDeclaration)node).resolveBinding();
	}

	if (binding != null)
		return binding.getJavaElement();

	return null;
}
 
Example #14
Source File: SystemObject.java    From JDeodorant with MIT License 4 votes vote down vote up
private void inheritanceHierarchyMatchingWithStaticTypes(TypeCheckElimination typeCheckElimination,
		CompleteInheritanceDetection inheritanceDetection) {
	List<SimpleName> staticFields = typeCheckElimination.getStaticFields();
	String abstractClassType = typeCheckElimination.getAbstractClassType();
	InheritanceTree tree = null;
	if(abstractClassType != null)
		tree = inheritanceDetection.getTree(abstractClassType);
	if(tree != null) {
		DefaultMutableTreeNode rootNode = tree.getRootNode();
		DefaultMutableTreeNode leaf = rootNode.getFirstLeaf();
		List<String> inheritanceHierarchySubclassNames = new ArrayList<String>();
		while(leaf != null) {
			inheritanceHierarchySubclassNames.add((String)leaf.getUserObject());
			leaf = leaf.getNextLeaf();
		}
		int matchCounter = 0;
		for(SimpleName staticField : staticFields) {
			for(String subclassName : inheritanceHierarchySubclassNames) {
				ClassObject classObject = getClassObject(subclassName);
				AbstractTypeDeclaration abstractTypeDeclaration = classObject.getAbstractTypeDeclaration();
				if(abstractTypeDeclaration instanceof TypeDeclaration) {
					TypeDeclaration typeDeclaration = (TypeDeclaration)abstractTypeDeclaration;
					Javadoc javadoc = typeDeclaration.getJavadoc();
					if(javadoc != null) {
						List<TagElement> tagElements = javadoc.tags();
						for(TagElement tagElement : tagElements) {
							if(tagElement.getTagName() != null && tagElement.getTagName().equals(TagElement.TAG_SEE)) {
								List<ASTNode> fragments = tagElement.fragments();
								for(ASTNode fragment : fragments) {
									if(fragment instanceof MemberRef) {
										MemberRef memberRef = (MemberRef)fragment;
										IBinding staticFieldNameBinding = staticField.resolveBinding();
										ITypeBinding staticFieldNameDeclaringClass = null;
										if(staticFieldNameBinding != null && staticFieldNameBinding.getKind() == IBinding.VARIABLE) {
											IVariableBinding staticFieldNameVariableBinding = (IVariableBinding)staticFieldNameBinding;
											staticFieldNameDeclaringClass = staticFieldNameVariableBinding.getDeclaringClass();
										}
										if(staticFieldNameBinding.getName().equals(memberRef.getName().getIdentifier()) &&
												staticFieldNameDeclaringClass.getQualifiedName().equals(memberRef.getQualifier().getFullyQualifiedName())) {
											typeCheckElimination.putStaticFieldSubclassTypeMapping(staticField, subclassName);
											matchCounter++;
											break;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		if(matchCounter == staticFields.size()) {
			typeCheckElimination.setInheritanceTreeMatchingWithStaticTypes(tree);
			return;
		}
	}
}