Search in sources :

Example 1 with IMemberValuePairBinding

use of org.eclipse.jdt.core.dom.IMemberValuePairBinding in project j2objc by google.

the class JdtAnnotationMirror method getElementValues.

@Override
public Map<? extends ExecutableElement, ? extends AnnotationValue> getElementValues() {
    Map<ExecutableElement, AnnotationValue> elementValues = new HashMap<>();
    for (IMemberValuePairBinding pair : binding.getAllMemberValuePairs()) {
        ExecutableElement element = new JdtExecutableElement(pair.getMethodBinding());
        AnnotationValue value = new JdtAnnotationValue(pair.getValue());
        elementValues.put(element, value);
    }
    return elementValues;
}
Also used : HashMap(java.util.HashMap) ExecutableElement(javax.lang.model.element.ExecutableElement) AnnotationValue(javax.lang.model.element.AnnotationValue) IMemberValuePairBinding(org.eclipse.jdt.core.dom.IMemberValuePairBinding)

Example 2 with IMemberValuePairBinding

use of org.eclipse.jdt.core.dom.IMemberValuePairBinding in project xtext-eclipse by eclipse.

the class JdtBasedTypeFactory method createAnnotationReference.

/**
 * @since 2.4
 */
protected JvmAnnotationReference createAnnotationReference(/* @NonNull */
IAnnotationBinding annotation) {
    JvmAnnotationReference annotationReference = TypesFactory.eINSTANCE.createJvmAnnotationReference();
    ITypeBinding annotationType = annotation.getAnnotationType();
    annotationReference.setAnnotation(createAnnotationProxy(annotationType));
    InternalEList<JvmAnnotationValue> values = (InternalEList<JvmAnnotationValue>) annotationReference.getExplicitValues();
    IMemberValuePairBinding[] allMemberValuePairs = annotation.getDeclaredMemberValuePairs();
    for (IMemberValuePairBinding memberValuePair : allMemberValuePairs) {
        IMethodBinding methodBinding = memberValuePair.getMethodBinding();
        if (methodBinding != null) {
            try {
                values.addUnique(createAnnotationValue(annotationType, memberValuePair.getValue(), methodBinding));
            } catch (NullPointerException npe) {
                // memberValuePair#getValue may throw an NPE if the methodBinding has no return type
                if (methodBinding.getReturnType() != null) {
                    throw npe;
                } else {
                    if (log.isDebugEnabled()) {
                        log.debug(npe.getMessage(), npe);
                    }
                }
            }
        }
    }
    return annotationReference;
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) InternalEList(org.eclipse.emf.ecore.util.InternalEList) IMemberValuePairBinding(org.eclipse.jdt.core.dom.IMemberValuePairBinding) JvmAnnotationReference(org.eclipse.xtext.common.types.JvmAnnotationReference) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue)

Example 3 with IMemberValuePairBinding

use of org.eclipse.jdt.core.dom.IMemberValuePairBinding in project eclipse.jdt.ls by eclipse.

the class RedundantNullnessTypeAnnotationsFilter method determineNNBDValue.

private static EnumSet<TypeLocation> determineNNBDValue(IAnnotationBinding annot) {
    EnumSet<TypeLocation> result = EnumSet.noneOf(TypeLocation.class);
    IMemberValuePairBinding[] pairs = annot.getAllMemberValuePairs();
    for (final IMemberValuePairBinding pair : pairs) {
        if (pair.getKey() == null || pair.getKey().equals("value")) {
            // $NON-NLS-1$
            Object value = pair.getValue();
            if (value instanceof Object[]) {
                Object[] values = (Object[]) value;
                for (int k = 0; k < values.length; k++) {
                    if (values[k] instanceof IVariableBinding) {
                        String name = ((IVariableBinding) values[k]).getName();
                        try {
                            result.add(TypeLocation.valueOf(name));
                        } catch (IllegalArgumentException e) {
                        // ignore
                        }
                    }
                }
            } else if (value instanceof IVariableBinding) {
                String name = ((IVariableBinding) value).getName();
                try {
                    result.add(TypeLocation.valueOf(name));
                } catch (IllegalArgumentException e) {
                // ignore
                }
            }
        }
    }
    return result;
}
Also used : TypeLocation(org.eclipse.jdt.core.dom.rewrite.ImportRewrite.TypeLocation) IMemberValuePairBinding(org.eclipse.jdt.core.dom.IMemberValuePairBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Example 4 with IMemberValuePairBinding

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

the class JavadocFinder method addAnnotation.

private void addAnnotation(StringBuffer buf, IJavaElement element, IAnnotationBinding annotation) throws URISyntaxException {
    IJavaElement javaElement = annotation.getAnnotationType().getJavaElement();
    buf.append('@');
    if (javaElement != null) {
        String uri = JavaElementLinks.createURI(baseHref, javaElement);
        addLink(buf, uri, annotation.getName());
    } else {
        buf.append(annotation.getName());
    }
    IMemberValuePairBinding[] mvPairs = annotation.getDeclaredMemberValuePairs();
    if (mvPairs.length > 0) {
        buf.append('(');
        for (int j = 0; j < mvPairs.length; j++) {
            if (j > 0) {
                buf.append(JavaElementLabels.COMMA_STRING);
            }
            IMemberValuePairBinding mvPair = mvPairs[j];
            String memberURI = JavaElementLinks.createURI(baseHref, mvPair.getMethodBinding().getJavaElement());
            addLink(buf, memberURI, mvPair.getName());
            buf.append('=');
            addValue(buf, element, mvPair.getValue());
        }
        buf.append(')');
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IMemberValuePairBinding(org.eclipse.jdt.core.dom.IMemberValuePairBinding)

Example 5 with IMemberValuePairBinding

use of org.eclipse.jdt.core.dom.IMemberValuePairBinding in project eclipse.jdt.ls by eclipse.

the class TypeAnnotationRewrite method isTypeUseOnly.

private static boolean isTypeUseOnly(IAnnotationBinding binding) {
    IMemberValuePairBinding[] pairs = binding.getAllMemberValuePairs();
    boolean typeUseSeen = false;
    boolean otherSeen = false;
    for (final IMemberValuePairBinding pair : pairs) {
        if (pair.getKey() == null || pair.getKey().equals("value")) {
            // $NON-NLS-1$
            Object value = pair.getValue();
            if (value instanceof Object[]) {
                Object[] values = (Object[]) value;
                for (int k = 0; k < values.length; k++) {
                    if (values[k] instanceof IVariableBinding) {
                        String name = ((IVariableBinding) values[k]).getName();
                        if (name.equals(ElementType.TYPE_USE.name())) {
                            typeUseSeen = true;
                        } else if (!name.equals(ElementType.TYPE_PARAMETER.name())) {
                            otherSeen = true;
                        }
                    }
                }
            } else if (value instanceof IVariableBinding) {
                String name = ((IVariableBinding) value).getName();
                if (name.equals(ElementType.TYPE_USE.name())) {
                    typeUseSeen = true;
                } else if (!name.equals(ElementType.TYPE_PARAMETER.name())) {
                    otherSeen = true;
                }
            }
        }
    }
    return typeUseSeen && !otherSeen;
}
Also used : IMemberValuePairBinding(org.eclipse.jdt.core.dom.IMemberValuePairBinding) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding)

Aggregations

IMemberValuePairBinding (org.eclipse.jdt.core.dom.IMemberValuePairBinding)5 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)2 HashMap (java.util.HashMap)1 AnnotationValue (javax.lang.model.element.AnnotationValue)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 InternalEList (org.eclipse.emf.ecore.util.InternalEList)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)1 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)1 TypeLocation (org.eclipse.jdt.core.dom.rewrite.ImportRewrite.TypeLocation)1 JvmAnnotationReference (org.eclipse.xtext.common.types.JvmAnnotationReference)1 JvmAnnotationValue (org.eclipse.xtext.common.types.JvmAnnotationValue)1