Search in sources :

Example 11 with AbstractTypeDeclaration

use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project che by eclipse.

the class PromoteTempToFieldRefactoring method getNamesOfFieldsInDeclaringType.

private String[] getNamesOfFieldsInDeclaringType() {
    final AbstractTypeDeclaration type = getEnclosingType();
    if (type instanceof TypeDeclaration) {
        FieldDeclaration[] fields = ((TypeDeclaration) type).getFields();
        List<String> result = new ArrayList<String>(fields.length);
        for (int i = 0; i < fields.length; i++) {
            for (Iterator<VariableDeclarationFragment> iter = fields[i].fragments().iterator(); iter.hasNext(); ) {
                VariableDeclarationFragment field = iter.next();
                result.add(field.getName().getIdentifier());
            }
        }
        return result.toArray(new String[result.size()]);
    }
    return new String[] {};
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) ArrayList(java.util.ArrayList) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 12 with AbstractTypeDeclaration

use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project che by eclipse.

the class JavaTextSelection method resolveInClassInitializer.

public boolean resolveInClassInitializer() {
    if (fInClassInitializerRequested)
        return fInClassInitializer;
    fInClassInitializerRequested = true;
    resolveSelectedNodes();
    ASTNode node = getStartNode();
    if (node == null) {
        fInClassInitializer = true;
    } else {
        while (node != null) {
            int nodeType = node.getNodeType();
            if (node instanceof AbstractTypeDeclaration) {
                fInClassInitializer = false;
                break;
            } else if (nodeType == ASTNode.ANONYMOUS_CLASS_DECLARATION) {
                fInClassInitializer = false;
                break;
            } else if (nodeType == ASTNode.INITIALIZER) {
                fInClassInitializer = true;
                break;
            }
            node = node.getParent();
        }
    }
    return fInClassInitializer;
}
Also used : ASTNode(org.eclipse.jdt.core.dom.ASTNode) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 13 with AbstractTypeDeclaration

use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project che by eclipse.

the class JavaTextSelection method resolveInVariableInitializer.

public boolean resolveInVariableInitializer() {
    if (fInVariableInitializerRequested)
        return fInVariableInitializer;
    fInVariableInitializerRequested = true;
    resolveSelectedNodes();
    ASTNode node = getStartNode();
    ASTNode last = null;
    while (node != null) {
        int nodeType = node.getNodeType();
        if (node instanceof AbstractTypeDeclaration) {
            fInVariableInitializer = false;
            break;
        } else if (nodeType == ASTNode.ANONYMOUS_CLASS_DECLARATION) {
            fInVariableInitializer = false;
            break;
        } else if (nodeType == ASTNode.VARIABLE_DECLARATION_FRAGMENT && ((VariableDeclarationFragment) node).getInitializer() == last) {
            fInVariableInitializer = true;
            break;
        } else if (nodeType == ASTNode.SINGLE_VARIABLE_DECLARATION && ((SingleVariableDeclaration) node).getInitializer() == last) {
            fInVariableInitializer = true;
            break;
        } else if (nodeType == ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION && ((AnnotationTypeMemberDeclaration) node).getDefault() == last) {
            fInVariableInitializer = true;
            break;
        }
        last = node;
        node = node.getParent();
    }
    return fInVariableInitializer;
}
Also used : AnnotationTypeMemberDeclaration(org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration) VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 14 with AbstractTypeDeclaration

use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project che by eclipse.

the class JavadocContentAccess2 method getJavadocNode.

private static Javadoc getJavadocNode(IJavaElement element, String rawJavadoc) {
    //FIXME: take from SharedASTProvider if available
    //Caveat: Javadoc nodes are not available when Javadoc processing has been disabled!
    //https://bugs.eclipse.org/bugs/show_bug.cgi?id=212207
    //$NON-NLS-1$
    String source = rawJavadoc + "class C{}";
    CompilationUnit root = createAST(element, source);
    if (root == null)
        return null;
    List<AbstractTypeDeclaration> types = root.types();
    if (types.size() != 1)
        return null;
    AbstractTypeDeclaration type = types.get(0);
    return type.getJavadoc();
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Example 15 with AbstractTypeDeclaration

use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project che by eclipse.

the class DelegateCreator method getTypeBodyDeclarationsProperty.

private ChildListPropertyDescriptor getTypeBodyDeclarationsProperty() {
    ASTNode parent = fDeclaration.getParent();
    if (parent instanceof AbstractTypeDeclaration)
        return ((AbstractTypeDeclaration) parent).getBodyDeclarationsProperty();
    else if (parent instanceof AnonymousClassDeclaration)
        return AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY;
    Assert.isTrue(false);
    return null;
}
Also used : ASTNode(org.eclipse.jdt.core.dom.ASTNode) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration)

Aggregations

AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)61 ASTNode (org.eclipse.jdt.core.dom.ASTNode)36 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)25 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)17 AnonymousClassDeclaration (org.eclipse.jdt.core.dom.AnonymousClassDeclaration)17 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)17 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)17 AST (org.eclipse.jdt.core.dom.AST)15 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)12 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)12 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)11 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)11 Type (org.eclipse.jdt.core.dom.Type)10 ArrayList (java.util.ArrayList)9 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)9 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)9 IType (org.eclipse.jdt.core.IType)8 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)8 Expression (org.eclipse.jdt.core.dom.Expression)7 Javadoc (org.eclipse.jdt.core.dom.Javadoc)7