Example usage for org.eclipse.jdt.core.dom MemberValuePair getStructuralProperty

List of usage examples for org.eclipse.jdt.core.dom MemberValuePair getStructuralProperty

Introduction

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

Prototype

public final Object getStructuralProperty(StructuralPropertyDescriptor property) 

Source Link

Document

Returns the value of the given structural property for this node.

Usage

From source file:org.gw4e.eclipse.facade.JDTManager.java

License:Open Source License

/**
 * @param cu//from www .j  a  va 2s .  c  o m
 * @param annotationName
 * @return
 * @throws JavaModelException
 */
public static AnnotationParsing resolveAnnotation(ICompilationUnit cu, Class inputClass,
        final String attribut) {

    CompilationUnit ast = parse(cu);
    AnnotationParsing ret = new AnnotationParsing();
    String annotationName = inputClass.getName();
    ast.accept(new ASTVisitor() {
        public boolean visit(MemberValuePair node) {
            String name = node.getName().getFullyQualifiedName();
            if (attribut.equals(name) && node.getParent() != null
                    && node.getParent() instanceof NormalAnnotation) {
                IAnnotationBinding annoBinding = ((NormalAnnotation) node.getParent())
                        .resolveAnnotationBinding();
                String qname = annoBinding.getAnnotationType().getQualifiedName();
                if (inputClass.getName().equals(qname)) {
                    int start = node.getStartPosition();
                    int end = start + node.getLength();
                    int lineNumber = ast.getLineNumber(start);
                    Location location = new Location(lineNumber, start, end);
                    ret.setLocation(location);
                }
            }
            return true;
        }

        public final boolean visit(final TypeDeclaration node) {
            List<?> modifiers = (List<?>) node.getStructuralProperty(TypeDeclaration.MODIFIERS2_PROPERTY);
            for (Object modifier : modifiers) {
                if (modifier instanceof org.eclipse.jdt.core.dom.Annotation) {
                    IAnnotationBinding annotationBinding = ((org.eclipse.jdt.core.dom.Annotation) modifier)
                            .resolveAnnotationBinding();

                    if (annotationBinding != null) {
                        final String qualifiedName = annotationBinding.getAnnotationType().getQualifiedName();
                        if (annotationName.equalsIgnoreCase(qualifiedName))
                            ret.add(annotationBinding);

                    }
                }
            }
            return true;
        }
    });
    return ret;
}