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;
}
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;
}
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;
}
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(')');
}
}
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;
}
Aggregations