org.eclipse.jdt.core.dom.AbstractTypeDeclaration typeDeclaration = findTypeDeclaration(rootType, cuUnit.types()); while (!typeStack.isEmpty() && typeDeclaration != null) { typeDeclaration = findTypeDeclaration(typeStack.pop(), typeDeclaration.bodyDeclarations()); for (Object declaration : typeDeclaration.bodyDeclarations()) { if (declaration instanceof org.eclipse.jdt.core.dom.MethodDeclaration) { org.eclipse.jdt.core.dom.MethodDeclaration methodDeclaration = (org.eclipse.jdt.core.dom.MethodDeclaration) declaration;
if (type.getNodeType() == ASTNode.TYPE_DECLARATION) { List<BodyDeclaration> bodies = type.bodyDeclarations(); for (BodyDeclaration body : bodies) { if (body.getNodeType() == ASTNode.METHOD_DECLARATION) {
/** * Generecized version of the equivalent JDT method. * * @param node the node on which to call the equivalent JDT method * @return a List of body declarations * @see TypeDeclaration#bodyDeclarations() */ @SuppressWarnings("unchecked") public static List<BodyDeclaration> bodyDeclarations(AbstractTypeDeclaration node) { return node.bodyDeclarations(); }
private int findFirstMethodIndex(AbstractTypeDeclaration typeDeclaration) { for (int i= 0, n= typeDeclaration.bodyDeclarations().size(); i < n; i++) { if (typeDeclaration.bodyDeclarations().get(i) instanceof MethodDeclaration) return i; } return -1; }
@Override public O removeNestedType(JavaSource<?> type) { if (type instanceof AbstractJavaSource) { BodyDeclaration bodyDeclaration = ((AbstractJavaSource<?>) type).body; List<Object> bodyDeclarations = getDeclaration().bodyDeclarations(); bodyDeclarations.remove(bodyDeclaration); } return (O) this; }
private void addMethods(AbstractTypeDeclaration node) { @SuppressWarnings("unchecked") final List<BodyDeclaration> bodyDeclarations = node.bodyDeclarations(); addMethods(bodyDeclarations); }
private MethodDeclaration[] getAllConstructors(AbstractTypeDeclaration typeDeclaration) { BodyDeclaration decl; List<BodyDeclaration> result= new ArrayList<>(1); for (Iterator<BodyDeclaration> it = typeDeclaration.bodyDeclarations().listIterator(); it.hasNext(); ) { decl= it.next(); if (decl instanceof MethodDeclaration && ((MethodDeclaration) decl).isConstructor()) result.add(decl); } return result.toArray(new MethodDeclaration[result.size()]); }
private int computeInsertIndexForNewConstructor(AbstractTypeDeclaration declaration) { List declarations= declaration.bodyDeclarations(); if (declarations.isEmpty()) return 0; int index= findFirstMethodIndex(declaration); if (index == -1) return declarations.size(); else return index; }
private MethodDeclaration[] getAllConstructors(AbstractTypeDeclaration typeDeclaration) { BodyDeclaration decl; List result= new ArrayList(1); for (Iterator it = typeDeclaration.bodyDeclarations().listIterator(); it.hasNext(); ) { decl= (BodyDeclaration) it.next(); if (decl instanceof MethodDeclaration && ((MethodDeclaration) decl).isConstructor()) result.add(decl); } return (MethodDeclaration[]) result.toArray(new MethodDeclaration[result.size()]); }
@Override public JavaAnnotationSource removeAnnotationElement(AnnotationElement<?> annotationElement) { getDeclaration().bodyDeclarations().remove(annotationElement.getInternal()); return this; }
@Override @SuppressWarnings("unchecked") public O removeMethod(final Method<O, ?> method) { getDeclaration().bodyDeclarations().remove(method.getInternal()); return (O) this; }
@Override @SuppressWarnings("unchecked") public MethodSource<O> addMethod(Method<?, ?> method) { MethodSource<O> m = new MethodImpl<>((O) this, method.toString()); getDeclaration().bodyDeclarations().add(m.getInternal()); return m; }
@Override @SuppressWarnings("unchecked") public MethodSource<O> addMethod(final String method) { MethodSource<O> m = new MethodImpl<>((O) this, method); getDeclaration().bodyDeclarations().add(m.getInternal()); return m; }
@Override @SuppressWarnings("unchecked") public MethodSource<O> addMethod(java.lang.reflect.Method method) { MethodSource<O> m = new MethodImpl<>((O) this, method); getDeclaration().bodyDeclarations().add(m.getInternal()); return m; }
@Override @SuppressWarnings("unchecked") public MethodSource<O> addMethod() { MethodSource<O> m = new MethodImpl<>((O) this); getDeclaration().bodyDeclarations().add(m.getInternal()); return m; }
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(); } }
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(); }
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(); }
private void addNestedClass(CompilationUnitRewrite rewrite, ITypeBinding[] typeParameters) throws CoreException { final AbstractTypeDeclaration declarations= ASTNodes.getParent(fAnonymousInnerClassNode, AbstractTypeDeclaration.class); int index= findIndexOfFistNestedClass(declarations.bodyDeclarations()); if (index == -1) index= 0; rewrite.getASTRewrite().getListRewrite(declarations, declarations.getBodyDeclarationsProperty()).insertAt(createNewNestedClass(rewrite, typeParameters), index, null); }
private void addNestedClass(CompilationUnitRewrite rewrite, ITypeBinding[] typeParameters) throws CoreException { final AbstractTypeDeclaration declarations= (AbstractTypeDeclaration) ASTNodes.getParent(fAnonymousInnerClassNode, AbstractTypeDeclaration.class); int index= findIndexOfFistNestedClass(declarations.bodyDeclarations()); if (index == -1) index= 0; rewrite.getASTRewrite().getListRewrite(declarations, declarations.getBodyDeclarationsProperty()).insertAt(createNewNestedClass(rewrite, typeParameters), index, null); }