Example usage for org.eclipse.jdt.core.dom ASTNode TYPE_DECLARATION

List of usage examples for org.eclipse.jdt.core.dom ASTNode TYPE_DECLARATION

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ASTNode TYPE_DECLARATION.

Prototype

int TYPE_DECLARATION

To view the source code for org.eclipse.jdt.core.dom ASTNode TYPE_DECLARATION.

Click Source Link

Document

Node type constant indicating a node of type TypeDeclaration.

Usage

From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java

License:Open Source License

private boolean isNestedPublicStatic(TypeDeclaration type) {
    if (Modifier.isStatic(type.getModifiers())) {
        ASTNode parent = type.getParent();
        if (parent != null && parent.getNodeType() == ASTNode.TYPE_DECLARATION) {
            TypeDeclaration parentType = (TypeDeclaration) parent;
            if (Modifier.isPublic(parentType.getModifiers()))
                return parentType.isPackageMemberTypeDeclaration() || isNestedPublicStatic(parentType);
        }//w  ww.  j av  a  2s  .c o  m
    }

    return false;
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final MarkerAnnotation node) {
    final ITypeBinding binding = node.resolveTypeBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement annoteElem = ASTCrawler.convertBinding(binding);
    this.aDB.addElement(annoteElem, binding.getModifiers());

    final ASTNode annotatedNode = node.getParent();
    switch (annotatedNode.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode;
        final IMethodBinding mBinding = annotatedMethod.resolveBinding();
        return this.addAnnotationRelation(annoteElem, mBinding);

    }/*from  w ww .j a  va 2s.  co  m*/
    case ASTNode.ANNOTATION_TYPE_DECLARATION: {
        final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = annotatedAnnotation.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
        return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode);
    }
    case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
        return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode);
    }
    case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION: {
        AnnotationTypeMemberDeclaration atmd = (AnnotationTypeMemberDeclaration) annotatedNode;
        IMethodBinding methodBinding = atmd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, methodBinding);
    }

    case ASTNode.PACKAGE_DECLARATION: {
        final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode;
        final IPackageBinding pBinding = packDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, pBinding);
    }

    case ASTNode.SINGLE_VARIABLE_DECLARATION: {
        final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode;
        final IVariableBinding vBinding = svd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, vBinding);
    }
    case ASTNode.TYPE_DECLARATION: {
        final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = tDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.ENUM_DECLARATION: {
        final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode;
        final ITypeBinding tBinding = eDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }

    case ASTNode.FIELD_DECLARATION: {
        final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode;
        for (final Object obj : fieldDecl.fragments()) {
            final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj;
            final IVariableBinding vBinding = vdf.resolveBinding();
            return this.addAnnotationRelation(annoteElem, vBinding);
        }
    }

    default: {
        throw new IllegalStateException("Illegal annotated node type: " + annotatedNode);
    }
    }
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final NormalAnnotation node) {
    final ITypeBinding binding = node.resolveTypeBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement annoteElem = ASTCrawler.convertBinding(binding);
    this.aDB.addElement(annoteElem, binding.getModifiers());

    final ASTNode annotatedNode = node.getParent();
    switch (annotatedNode.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode;
        final IMethodBinding mBinding = annotatedMethod.resolveBinding();
        return this.addAnnotationRelation(annoteElem, mBinding);

    }//from   www .  ja v a2s .c o m
    case ASTNode.ANNOTATION_TYPE_DECLARATION: {
        final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = annotatedAnnotation.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
        return processVariableDeclarationStatement(annoteElem, (VariableDeclarationStatement) annotatedNode);
    }
    case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
        return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode);
    }

    case ASTNode.PACKAGE_DECLARATION: {
        final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode;
        final IPackageBinding pBinding = packDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, pBinding);
    }

    case ASTNode.SINGLE_VARIABLE_DECLARATION: {
        final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode;
        final IVariableBinding vBinding = svd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, vBinding);
    }
    case ASTNode.TYPE_DECLARATION: {
        final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = tDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.ENUM_DECLARATION: {
        final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode;
        final ITypeBinding tBinding = eDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.FIELD_DECLARATION: {
        final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode;
        for (final Object obj : fieldDecl.fragments()) {
            final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj;
            final IVariableBinding vBinding = vdf.resolveBinding();
            return this.addAnnotationRelation(annoteElem, vBinding);
        }
    }
    default: {
        throw new IllegalStateException("Illegal annotated node type: " + annotatedNode);
    }
    }
}

From source file:ca.mcgill.cs.swevo.jayfx.ASTCrawler.java

License:Open Source License

@Override
public boolean visit(final SingleMemberAnnotation node) {
    final ITypeBinding binding = node.resolveTypeBinding();
    if (ASTCrawler.checkForNull(binding))
        return false;
    final IElement annoteElem = ASTCrawler.convertBinding(binding);
    this.aDB.addElement(annoteElem, binding.getModifiers());

    final ASTNode annotatedNode = node.getParent();
    switch (annotatedNode.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration annotatedMethod = (MethodDeclaration) annotatedNode;
        final IMethodBinding mBinding = annotatedMethod.resolveBinding();
        return this.addAnnotationRelation(annoteElem, mBinding);

    }//from w  ww .j av  a2 s .co m
    case ASTNode.ANNOTATION_TYPE_DECLARATION: {
        final AnnotationTypeDeclaration annotatedAnnotation = (AnnotationTypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = annotatedAnnotation.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }

    case ASTNode.VARIABLE_DECLARATION_STATEMENT: {
        VariableDeclarationStatement vds = (VariableDeclarationStatement) annotatedNode;
        return processVariableDeclarationStatement(annoteElem, vds);
    }

    case ASTNode.VARIABLE_DECLARATION_FRAGMENT: {
        return processVariableDeclarationFragment(annoteElem, (VariableDeclarationFragment) annotatedNode);
    }

    case ASTNode.PACKAGE_DECLARATION: {
        final PackageDeclaration packDecl = (PackageDeclaration) annotatedNode;
        final IPackageBinding pBinding = packDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, pBinding);
    }

    case ASTNode.SINGLE_VARIABLE_DECLARATION: {
        final SingleVariableDeclaration svd = (SingleVariableDeclaration) annotatedNode;
        final IVariableBinding vBinding = svd.resolveBinding();
        return this.addAnnotationRelation(annoteElem, vBinding);
    }
    case ASTNode.TYPE_DECLARATION: {
        final TypeDeclaration tDecl = (TypeDeclaration) annotatedNode;
        final ITypeBinding tBinding = tDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.ENUM_DECLARATION: {
        final EnumDeclaration eDecl = (EnumDeclaration) annotatedNode;
        final ITypeBinding tBinding = eDecl.resolveBinding();
        return this.addAnnotationRelation(annoteElem, tBinding);
    }
    case ASTNode.FIELD_DECLARATION: {
        final FieldDeclaration fieldDecl = (FieldDeclaration) annotatedNode;
        for (final Object obj : fieldDecl.fragments()) {
            final VariableDeclarationFragment vdf = (VariableDeclarationFragment) obj;
            final IVariableBinding vBinding = vdf.resolveBinding();
            return this.addAnnotationRelation(annoteElem, vBinding);
        }
    }
    default: {
        throw new IllegalStateException("Illegal annotated node type: " + annotatedNode);
    }
    }
}

From source file:cideplus.ui.astview.ASTViewLabelProvider.java

License:Open Source License

public Image getImage(Object obj) {
    if (obj instanceof ASTNode) {
        int nodeType = ((ASTNode) obj).getNodeType();
        String image = ISharedImages.IMG_OBJS_CFILE;
        //new JavaElementImageDescriptor()
        switch (nodeType) {
        case ASTNode.ENUM_CONSTANT_DECLARATION:
            image = ISharedImages.IMG_OBJS_ENUM_DEFAULT;
            break;
        case ASTNode.FIELD_DECLARATION:
            image = ISharedImages.IMG_FIELD_DEFAULT;
            break;
        case ASTNode.METHOD_DECLARATION:
            image = ISharedImages.IMG_OBJS_PUBLIC;
            break;
        case ASTNode.MODIFIER:
            image = ISharedImages.IMG_OBJS_DEFAULT;
            break;
        case ASTNode.JAVADOC:
            image = ISharedImages.IMG_OBJS_JAVADOCTAG;
            break;
        case ASTNode.PACKAGE_DECLARATION:
            image = ISharedImages.IMG_OBJS_PACKDECL;
            break;
        case ASTNode.IMPORT_DECLARATION:
            image = ISharedImages.IMG_OBJS_IMPDECL;
            break;
        case ASTNode.ENUM_DECLARATION:
            image = ISharedImages.IMG_OBJS_ENUM;
            break;
        case ASTNode.TYPE_DECLARATION:
            if (((TypeDeclaration) obj).isInterface()) {
                image = ISharedImages.IMG_OBJS_INTERFACE;
            } else {
                image = ISharedImages.IMG_OBJS_CLASS;
            }//from www  .  jav  a  2 s. c om
            break;
        }
        if (image != null) {
            return JavaUI.getSharedImages().getImage(image);
        }
        return null;
    } else if (obj instanceof ASTAttribute) {
        Image image = ((ASTAttribute) obj).getImage();
        if (image == null) {
            if (((ASTAttribute) obj).getChildren().length > 0) {
                image = PlatformUI.getWorkbench().getSharedImages()
                        .getImage(org.eclipse.ui.ISharedImages.IMG_OBJ_FOLDER);
            } else {
                image = PlatformUI.getWorkbench().getSharedImages()
                        .getImage(org.eclipse.ui.ISharedImages.IMG_TOOL_FORWARD);
            }
        }
        return image;
    }

    return null;
    //      String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
    //      if (obj instanceof ASTNode) {
    //         imageKey = ISharedImages.IMG_OBJ_FOLDER;
    //      }
    //      return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
}

From source file:com.drgarbage.ast.ASTGraphUtil.java

License:Apache License

/**
 * Returns nodes description./*from   w  w w.j av  a2 s . c o  m*/
 * 
 * @param node the AST-node
 * @return description string
 */
public static String getNodeDescr(ASTNode node) {
    StringBuffer elementDescr = new StringBuffer(node.getClass().getSimpleName());
    elementDescr.append(": ");

    int nodeType = node.getNodeType();
    switch (nodeType) {
    case ASTNode.COMPILATION_UNIT:
        CompilationUnit cu = (CompilationUnit) node;
        elementDescr.append(cu.getJavaElement().getElementName());
        break;

    case ASTNode.PACKAGE_DECLARATION:
        PackageDeclaration pd = (PackageDeclaration) node;
        elementDescr.append(pd.getName());
        break;

    case ASTNode.TYPE_DECLARATION:
        TypeDeclaration td = (TypeDeclaration) node;
        appendModifiers(td.getModifiers(), elementDescr);
        elementDescr.append(" class ");
        elementDescr.append(td.getName());
        break;

    case ASTNode.METHOD_DECLARATION:
        MethodDeclaration md = (MethodDeclaration) node;
        appendModifiers(md.getModifiers(), elementDescr);
        elementDescr.append(md.getReturnType2() == null ? "" : md.getReturnType2().toString());
        elementDescr.append(' ');
        elementDescr.append(md.getName());
        elementDescr.append("()");
        break;

    case ASTNode.BLOCK:
        elementDescr.append("{...}");
        break;

    case ASTNode.IF_STATEMENT:
        IfStatement is = (IfStatement) node;
        elementDescr.append("if( ");
        elementDescr.append(is.getExpression().toString());
        elementDescr.append(")");
        break;

    case ASTNode.FOR_STATEMENT:
        ForStatement fs = (ForStatement) node;
        elementDescr.append("for (...; ");
        elementDescr.append(fs.getExpression().toString());
        elementDescr.append("; ...){...}");
        break;

    case ASTNode.WHILE_STATEMENT:
        WhileStatement ws = (WhileStatement) node;
        elementDescr.append("while ( ");
        elementDescr.append(ws.getExpression().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.DO_STATEMENT:
        DoStatement ds = (DoStatement) node;
        elementDescr.append("do {...} while (");
        elementDescr.append(ds.getExpression().toString());
        elementDescr.append(")");
        break;

    case ASTNode.LABELED_STATEMENT:
        LabeledStatement ls = (LabeledStatement) node;
        elementDescr.append(ls.getLabel().toString());
        elementDescr.append(":");
        break;

    case ASTNode.CATCH_CLAUSE:
        CatchClause cs = (CatchClause) node;
        elementDescr.append("catch (");
        elementDescr.append(cs.getException().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.SWITCH_STATEMENT:
        SwitchStatement ss = (SwitchStatement) node;
        elementDescr.append("switch (");
        elementDescr.append(ss.getExpression().toString());
        elementDescr.append("){...}");
        break;

    case ASTNode.SWITCH_CASE:
        SwitchCase sc = (SwitchCase) node;
        elementDescr.append("case ");
        elementDescr.append(sc.getExpression() == null ? "default" : sc.getExpression().toString());
        elementDescr.append(":");
        break;
    case ASTNode.JAVADOC:
    case ASTNode.BLOCK_COMMENT:
    case ASTNode.LINE_COMMENT:
    case ASTNode.TRY_STATEMENT:
        /* nothing to do */
        break;

    default:
        elementDescr.append(node.toString());
    }

    /* cut the string if it is too long */
    String str = elementDescr.toString();
    if (str.length() > 128) {
        str = str.substring(0, 128) + " ... ";
    }
    str = str.replaceAll("\n", "");
    return str;
}

From source file:com.drgarbage.ast.ASTGraphUtil.java

License:Apache License

/**
 * Returns an image corresponding to the AST element.
 * /*from w w w .j a  v a 2  s  . c  o  m*/
 * @param node the AST-node
 * @return the image
 */
@SuppressWarnings("restriction")
public static Image getImage(ASTNode node) {
    switch (node.getNodeType()) {
    case ASTNode.COMPILATION_UNIT:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CUNIT);

    case ASTNode.PACKAGE_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_PACKDECL);

    case ASTNode.IMPORT_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_IMPDECL);

    case ASTNode.TYPE_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_CLASS);

    case ASTNode.ANNOTATION_TYPE_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_ANNOTATION);

    case ASTNode.ANONYMOUS_CLASS_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_INNER_CLASS_DEFAULT);

    case ASTNode.ENUM_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_ENUM);

    case ASTNode.FIELD_DECLARATION:
    case ASTNode.ENUM_CONSTANT_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PROTECTED);

    case ASTNode.METHOD_DECLARATION:
        return JavaPluginImages.get(JavaPluginImages.IMG_MISC_PUBLIC);

    case ASTNode.JAVADOC:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVADOCTAG);

    case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_LOCAL_VARIABLE);

    case ASTNode.BLOCK:
        return blockImage;

    case ASTNode.MODIFIER:
        return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_DEFAULT);
    }

    /* default */
    return JavaPluginImages.get(JavaPluginImages.IMG_FIELD_PRIVATE);
}

From source file:com.github.parzonka.ccms.sorter.comparator.BodyDeclarationComparator.java

License:Open Source License

private boolean isSortPreserved(BodyDeclaration bodyDeclaration) {
    switch (bodyDeclaration.getNodeType()) {
    case ASTNode.FIELD_DECLARATION:
    case ASTNode.ENUM_CONSTANT_DECLARATION:
    case ASTNode.INITIALIZER:
    case ASTNode.TYPE_DECLARATION:
        return true;
    default:/*from   w  ww  .java 2  s  . c  o  m*/
        return false;
    }
}

From source file:com.github.parzonka.ccms.sorter.comparator.BodyDeclarationComparator.java

License:Open Source License

private int category(BodyDeclaration bodyDeclaration) {
    switch (bodyDeclaration.getNodeType()) {
    case ASTNode.METHOD_DECLARATION: {
        final MethodDeclaration method = (MethodDeclaration) bodyDeclaration;
        if (method.isConstructor()) {
            return getMemberCategory(MembersOrderPreferenceCache.CONSTRUCTORS_INDEX);
        } else//w ww . j a  va 2s . c om
            return getMemberCategory(MembersOrderPreferenceCache.METHOD_INDEX);
    }
    case ASTNode.FIELD_DECLARATION: {
        return getMemberCategory(MembersOrderPreferenceCache.FIELDS_INDEX);
    }
    case ASTNode.INITIALIZER: {
        final int flags = ((Initializer) bodyDeclaration).getModifiers();
        if (Modifier.isStatic(flags))
            return getMemberCategory(MembersOrderPreferenceCache.STATIC_INIT_INDEX);
        else
            return getMemberCategory(MembersOrderPreferenceCache.INIT_INDEX);
    }
    case ASTNode.TYPE_DECLARATION:
    case ASTNode.ENUM_DECLARATION:
    case ASTNode.ANNOTATION_TYPE_DECLARATION:
        return getMemberCategory(MembersOrderPreferenceCache.TYPE_INDEX);
    case ASTNode.ENUM_CONSTANT_DECLARATION:
        return getMemberCategory(MembersOrderPreferenceCache.ENUM_CONSTANTS_INDEX);
    case ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION:
        return getMemberCategory(MembersOrderPreferenceCache.METHOD_INDEX);

    }
    throw new IllegalStateException();
}

From source file:com.google.currysrc.api.process.ast.BodyDeclarationLocators.java

License:Apache License

/**
 * Creates {@link BodyDeclarationLocator} objects that can find the supplied
 * {@link BodyDeclaration}. Usually returns a single element, except for fields declarations.
 *//* ww  w.j a  va2s.c  o m*/
public static List<BodyDeclarationLocator> createLocators(BodyDeclaration bodyDeclaration) {
    AbstractTypeDeclaration typeDeclaration = TypeLocator.findTypeDeclarationNode(bodyDeclaration);
    if (typeDeclaration == null) {
        throw new AssertionError("Unable to find type declaration for " + typeDeclaration);
    }
    TypeLocator typeLocator = new TypeLocator(typeDeclaration);

    int nodeType = bodyDeclaration.getNodeType();
    switch (nodeType) {
    case ASTNode.FIELD_DECLARATION:
        List<String> fieldNames = FieldLocator.getFieldNames((FieldDeclaration) bodyDeclaration);
        List<BodyDeclarationLocator> fieldLocators = new ArrayList<>(fieldNames.size());
        for (String fieldName : fieldNames) {
            fieldLocators.add(new FieldLocator(typeLocator, fieldName));
        }
        return fieldLocators;
    case ASTNode.METHOD_DECLARATION:
        MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
        List<String> parameterTypeNames = ParameterMatcher.getParameterTypeNames(methodDeclaration);
        return ImmutableList.<BodyDeclarationLocator>of(new MethodLocator(typeLocator,
                methodDeclaration.getName().getIdentifier(), parameterTypeNames));
    case ASTNode.TYPE_DECLARATION:
    case ASTNode.ENUM_DECLARATION:
        return ImmutableList.<BodyDeclarationLocator>of(typeLocator);
    case ASTNode.ENUM_CONSTANT_DECLARATION:
        EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) bodyDeclaration;
        String constantName = enumConstantDeclaration.getName().getIdentifier();
        return ImmutableList.<BodyDeclarationLocator>of(new EnumConstantLocator(typeLocator, constantName));
    default:
        throw new IllegalArgumentException("Unsupported node type: " + nodeType);
    }
}