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

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

Introduction

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

Prototype

public final int getLength() 

Source Link

Document

Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.

Usage

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public NormalAnnotation convert(org.eclipse.jdt.internal.compiler.ast.NormalAnnotation annotation) {
    final NormalAnnotation normalAnnotation = new NormalAnnotation(this.ast);
    setTypeNameForAnnotation(annotation, normalAnnotation);

    int start = annotation.sourceStart;
    int end = annotation.declarationSourceEnd;

    org.eclipse.jdt.internal.compiler.ast.MemberValuePair[] memberValuePairs = annotation.memberValuePairs;
    if (memberValuePairs != null) {
        for (int i = 0, max = memberValuePairs.length; i < max; i++) {
            MemberValuePair memberValuePair = convert(memberValuePairs[i]);
            int memberValuePairEnd = memberValuePair.getStartPosition() + memberValuePair.getLength() - 1;
            if (end == memberValuePairEnd) {
                normalAnnotation.setFlags(normalAnnotation.getFlags() | ASTNode.RECOVERED);
            }/*from w  w w. j  a v  a  2  s . co  m*/
            normalAnnotation.values().add(memberValuePair);
        }
    }

    normalAnnotation.setSourceRange(start, end - start + 1);
    if (this.resolveBindings) {
        recordNodes(normalAnnotation, annotation);
        normalAnnotation.resolveAnnotationBinding();
    }
    return normalAnnotation;
}

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

License:Open Source License

/**
 * @param cu/*  w w w .  ja v a  2 s . co 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;
}

From source file:org.jboss.tools.ws.jaxrs.core.jdt.MemberValuePairLocationRetriever.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MemberValuePair)
 *//*w  w w .  j av  a2  s. c  om*/
@Override
public boolean visit(MemberValuePair node) {
    if (node.getName().getFullyQualifiedName().equals(memberName)) {
        this.locatedSourceRange = new SourceRange(node.getStartPosition(), node.getLength());
    }
    // no need to drill down from here anyway
    return false;
}

From source file:org.mapstruct.eclipse.internal.MapStructCompletionProposalComputer.java

License:Apache License

/**
 * Creates an {@link ASTVisitor} that discovers all properties for a <code>Mapping</code>'s <code>source</code> and
 * <code>target</code> method for the given invocation offset.
 *//*  w  w  w  . ja v  a2  s .  c  o  m*/
private ASTVisitor createVisitor(final int invocationOffset, final AtomicBoolean isValidValue,
        final AtomicBoolean isSource, final Set<String> sourceProperties, final Set<String> targetProperties) {

    return new ASTVisitor(false) {

        @Override
        public boolean visit(MemberValuePair node) {

            String annotationQualifiedName = getAnnotationQualifiedName(node.resolveMemberValuePairBinding());

            if (MAPPING_ANNOTATION_QUALIFIED_NAME.equals(annotationQualifiedName) && isInRange(invocationOffset,
                    node.getValue().getStartPosition(), node.getValue().getLength())
                    && isMappingAnnotationMethod(node)) {

                isValidValue.set(true);

                if (SOURCE_ANNOTATION_METHOD.equals(node.getName().toString())) {
                    isSource.set(true);
                }

            }

            return false;

        }

        @Override
        public boolean visit(MethodDeclaration node) {

            if (isInRange(invocationOffset, node.getStartPosition(), node.getLength())) {

                IMethodBinding binding = node.resolveBinding();

                ITypeBinding returnType = binding.getReturnType();
                targetProperties.addAll(findProperties(returnType.getDeclaredMethods(), SET_PREFIX));

                ITypeBinding[] parameterTypes = binding.getParameterTypes();
                if (parameterTypes.length == 1) {
                    IMethodBinding[] declaredMethods = parameterTypes[0].getDeclaredMethods();
                    sourceProperties.addAll(findProperties(declaredMethods, GET_PREFIX));
                    sourceProperties.addAll(findProperties(declaredMethods, IS_PREFIX));
                }

                return true;

            }

            return false;

        }

    };

}