public static org.eclipse.jdt.core.dom.MethodDeclaration getRealMethodDeclarationNode(org.eclipse.jdt.core.IMethod sourceMethod, org.eclipse.jdt.core.dom.CompilationUnit cuUnit) throws JavaModelException { MethodDeclaration methodDeclarationNode = ASTNodeSearchUtil.getMethodDeclarationNode(sourceMethod, cuUnit); if (isGenerated(methodDeclarationNode)) { IType declaringType = sourceMethod.getDeclaringType();
public static ASTNode[] findNodes(SearchMatch[] searchResults, CompilationUnit cuNode) { List<ASTNode> result= new ArrayList<>(searchResults.length); for (int i= 0; i < searchResults.length; i++) { ASTNode node= findNode(searchResults[i], cuNode); if (node != null) result.add(node); } return result.toArray(new ASTNode[result.size()]); }
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode) throws JavaModelException { switch(element.getElementType()){ case IJavaElement.FIELD: return new ASTNode[]{getFieldOrEnumConstantDeclaration((IField) element, cuNode)}; case IJavaElement.IMPORT_CONTAINER: return getImportNodes((IImportContainer)element, cuNode); case IJavaElement.IMPORT_DECLARATION: return new ASTNode[]{getImportDeclarationNode((IImportDeclaration)element, cuNode)}; case IJavaElement.INITIALIZER: return new ASTNode[]{getInitializerNode((IInitializer)element, cuNode)}; case IJavaElement.METHOD: return new ASTNode[]{getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)}; case IJavaElement.PACKAGE_DECLARATION: return new ASTNode[]{getPackageDeclarationNode((IPackageDeclaration)element, cuNode)}; case IJavaElement.TYPE: return new ASTNode[]{getAbstractTypeDeclarationNode((IType) element, cuNode)}; default: Assert.isTrue(false, String.valueOf(element.getElementType())); return null; } }
public static BodyDeclaration getMethodOrAnnotationTypeMemberDeclarationNode(IMethod iMethod, CompilationUnit cuNode) throws JavaModelException { if (JdtFlags.isAnnotation(iMethod.getDeclaringType())) return getAnnotationTypeMemberDeclarationNode(iMethod, cuNode); else return getMethodDeclarationNode(iMethod, cuNode); }
private ASTNode getDestinationNode(IJavaElement destination, CompilationUnit target) throws JavaModelException { switch (destination.getElementType()) { case IJavaElement.INITIALIZER: return ASTNodeSearchUtil.getInitializerNode((IInitializer) destination, target); case IJavaElement.FIELD: return ASTNodeSearchUtil.getFieldOrEnumConstantDeclaration((IField) destination, target); case IJavaElement.METHOD: return ASTNodeSearchUtil.getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) destination, target); case IJavaElement.TYPE: IType typeDestination= (IType) destination; if (typeDestination.isAnonymous()) { return ASTNodeSearchUtil.getClassInstanceCreationNode(typeDestination, target).getAnonymousClassDeclaration(); } else { return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(typeDestination, target); } case IJavaElement.COMPILATION_UNIT: IType mainType= JavaElementUtil.getMainType((ICompilationUnit) destination); if (mainType != null) { return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(mainType, target); } //$FALL-THROUGH$ default: return null; } }
private static ASTNode[] getNodesToDelete(IJavaElement element, CompilationUnit cuNode) throws JavaModelException { // fields are different because you don't delete the whole declaration but only a fragment of it if (element.getElementType() == IJavaElement.FIELD) { if (JdtFlags.isEnum((IField) element)) return new ASTNode[] { ASTNodeSearchUtil.getEnumConstantDeclaration((IField) element, cuNode)}; else return new ASTNode[] { ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) element, cuNode)}; } if (element.getElementType() == IJavaElement.TYPE && ((IType) element).isLocal()) { IType type= (IType) element; if (type.isAnonymous()) { if (type.getParent().getElementType() == IJavaElement.FIELD) { final ISourceRange range= type.getSourceRange(); if (range != null) { final ASTNode node= ASTNodeSearchUtil.getAstNode(cuNode, range.getOffset(), range.getLength()); if (node instanceof AnonymousClassDeclaration) return new ASTNode[] { node}; } } return new ASTNode[] { ASTNodeSearchUtil.getClassInstanceCreationNode(type, cuNode)}; } else { ASTNode[] nodes= ASTNodeSearchUtil.getDeclarationNodes(element, cuNode); // we have to delete the TypeDeclarationStatement nodes[0]= nodes[0].getParent(); return nodes; } } return ASTNodeSearchUtil.getDeclarationNodes(element, cuNode); }
protected static List getDeclarationNodes(final CompilationUnit cuNode, final List members) throws JavaModelException { final List result= new ArrayList(members.size()); for (final Iterator iterator= members.iterator(); iterator.hasNext();) { final IMember member= (IMember) iterator.next(); ASTNode node= null; if (member instanceof IField) { if (Flags.isEnum(member.getFlags())) node= ASTNodeSearchUtil.getEnumConstantDeclaration((IField) member, cuNode); else node= ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) member, cuNode); } else if (member instanceof IType) node= ASTNodeSearchUtil.getAbstractTypeDeclarationNode((IType) member, cuNode); else if (member instanceof IMethod) node= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) member, cuNode); if (node != null) result.add(node); } return result; }
public static ASTNode[] getAstNodes(SearchMatch[] searchResults, CompilationUnit cuNode) { List result= new ArrayList(searchResults.length); for (int i= 0; i < searchResults.length; i++) { ASTNode node= getAstNode(searchResults[i], cuNode); if (node != null) result.add(node); } return (ASTNode[]) result.toArray(new ASTNode[result.size()]); }
public static List<BodyDeclaration> getBodyDeclarationList(IType iType, CompilationUnit cuNode) throws JavaModelException { if (iType.isAnonymous()) return getClassInstanceCreationNode(iType, cuNode).getAnonymousClassDeclaration().bodyDeclarations(); else return getAbstractTypeDeclarationNode(iType, cuNode).bodyDeclarations(); }
private static ASTNode[] getReferenceNodesIn(CompilationUnit cuNode, Map<ICompilationUnit, SearchMatch[]> references, ICompilationUnit cu) { SearchMatch[] results= references.get(cu); if (results == null) return new ASTNode[0]; return ASTNodeSearchUtil.getAstNodes(results, cuNode); }
final int visibility= fKeyword != null ? fKeyword.toFlagValue() : Modifier.NONE; if (fMember instanceof IField && !Flags.isEnum(fMember.getFlags())) { final VariableDeclarationFragment fragment= ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) fMember, root); final FieldDeclaration declaration= (FieldDeclaration) fragment.getParent(); VariableDeclarationFragment[] fragmentsToChange= new VariableDeclarationFragment[] { fragment }; adjustor.fStatus.merge(status); } else if (fMember != null) { final BodyDeclaration declaration= ASTNodeSearchUtil.getBodyDeclarationNode(fMember, root); if (declaration != null) { ModifierRewrite.create(rewrite, declaration).setVisibility(visibility, group);
cuRewrite.getASTRewrite().setTargetSourceRangeComputer(new TightSourceRangeComputer()); ASTNode[] nodes= ASTNodeSearchUtil.findNodes(group.getSearchResults(), cuRewrite.getRoot()); for (Iterator<IType> iter= subtypes.iterator(); iter.hasNext();) { IType subtype= iter.next(); AbstractTypeDeclaration subtypeNode= ASTNodeSearchUtil.getAbstractTypeDeclarationNode(subtype, cuRewrite.getRoot()); if (subtypeNode != null) modifyImplicitCallsToNoArgConstructor(subtypeNode, cuRewrite);
/** * @return an AbstractTypeDeclaration, a CompilationUnit, or null */ private ASTNode getDestinationNodeForSourceElement(IJavaElement destination, int kind, CompilationUnit unit) throws JavaModelException { final IType ancestor= getAncestorType(destination); if (ancestor != null) return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(ancestor, unit); if (kind == IJavaElement.TYPE || kind == IJavaElement.PACKAGE_DECLARATION || kind == IJavaElement.IMPORT_DECLARATION || kind == IJavaElement.IMPORT_CONTAINER) return unit; return null; }
for (int index= 0; index < members.length; index++) { try { BodyDeclaration decl= ASTNodeSearchUtil.getBodyDeclarationNode(members[index], sourceRewriter.getRoot()); if (decl != null) { for (final Iterator iterator= decl.modifiers().iterator(); iterator.hasNext();) {
private ASTNode getDestinationNode(IJavaElement destination, CompilationUnit target) throws JavaModelException { switch (destination.getElementType()) { case IJavaElement.INITIALIZER: return ASTNodeSearchUtil.getInitializerNode((IInitializer) destination, target); case IJavaElement.FIELD: return ASTNodeSearchUtil.getFieldOrEnumConstantDeclaration((IField) destination, target); case IJavaElement.METHOD: return ASTNodeSearchUtil.getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) destination, target); case IJavaElement.TYPE: IType typeDestination= (IType) destination; if (typeDestination.isAnonymous()) { return ASTNodeSearchUtil.getClassInstanceCreationNode(typeDestination, target).getAnonymousClassDeclaration(); } else { return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(typeDestination, target); } case IJavaElement.COMPILATION_UNIT: IType mainType= JavaElementUtil.getMainType((ICompilationUnit) destination); if (mainType != null) { return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(mainType, target); } //$FALL-THROUGH$ default: return null; } }
return new ASTNode[] { ASTNodeSearchUtil.getEnumConstantDeclaration((IField) element, cuNode)}; else return new ASTNode[] { ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) element, cuNode)}; if (type.isAnonymous()) { if (type.getParent().getElementType() == IJavaElement.FIELD) { EnumConstantDeclaration enumDecl= ASTNodeSearchUtil.getEnumConstantDeclaration((IField) element.getParent(), cuNode); if (enumDecl != null && enumDecl.getAnonymousClassDeclaration() != null) { return new ASTNode[] { enumDecl.getAnonymousClassDeclaration() }; ClassInstanceCreation creation= ASTNodeSearchUtil.getClassInstanceCreationNode(type, cuNode); if (creation != null) { if (creation.getLocationInParent() == ExpressionStatement.EXPRESSION_PROPERTY) { ASTNode[] nodes= ASTNodeSearchUtil.getDeclarationNodes(element, cuNode); return ASTNodeSearchUtil.getDeclarationNodes(element, cuNode);
protected static List<ASTNode> getDeclarationNodes(final CompilationUnit cuNode, final List<IMember> members) throws JavaModelException { final List<ASTNode> result= new ArrayList<>(members.size()); for (final Iterator<IMember> iterator= members.iterator(); iterator.hasNext();) { final IMember member= iterator.next(); ASTNode node= null; if (member instanceof IField) { if (Flags.isEnum(member.getFlags())) node= ASTNodeSearchUtil.getEnumConstantDeclaration((IField) member, cuNode); else node= ASTNodeSearchUtil.getFieldDeclarationFragmentNode((IField) member, cuNode); } else if (member instanceof IType) node= ASTNodeSearchUtil.getAbstractTypeDeclarationNode((IType) member, cuNode); else if (member instanceof IMethod) node= ASTNodeSearchUtil.getMethodDeclarationNode((IMethod) member, cuNode); if (node != null) result.add(node); } return result; }
public static BodyDeclaration getMethodOrAnnotationTypeMemberDeclarationNode(IMethod iMethod, CompilationUnit cuNode) throws JavaModelException { if (JdtFlags.isAnnotation(iMethod.getDeclaringType())) return getAnnotationTypeMemberDeclarationNode(iMethod, cuNode); else return getMethodDeclarationNode(iMethod, cuNode); }
public static ASTNode[] getAstNodes(SearchMatch[] searchResults, CompilationUnit cuNode) { List<ASTNode> result= new ArrayList<>(searchResults.length); for (int i= 0; i < searchResults.length; i++) { ASTNode node= getAstNode(searchResults[i], cuNode); if (node != null) result.add(node); } return result.toArray(new ASTNode[result.size()]); }
public static List getBodyDeclarationList(IType iType, CompilationUnit cuNode) throws JavaModelException { if (iType.isAnonymous()) return getClassInstanceCreationNode(iType, cuNode).getAnonymousClassDeclaration().bodyDeclarations(); else return getAbstractTypeDeclarationNode(iType, cuNode).bodyDeclarations(); }