Java Code Examples for org.eclipse.jdt.core.IAnnotation#getMemberValuePairs()
The following examples show how to use
org.eclipse.jdt.core.IAnnotation#getMemberValuePairs() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private static boolean isSilencedGeneratedAnnotation(IAnnotation annotation) throws JavaModelException { if ("javax.annotation.Generated".equals(annotation.getElementName()) || "javax.annotation.processing.Generated".equals(annotation.getElementName())) { IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); for (IMemberValuePair m : memberValuePairs) { if ("value".equals(m.getMemberName()) && IMemberValuePair.K_STRING == m.getValueKind()) { if (m.getValue() instanceof String) { return SILENCED_CODEGENS.contains(m.getValue()); } else if (m.getValue() instanceof Object[]) { for (Object val : (Object[])m.getValue()) { if(SILENCED_CODEGENS.contains(val)) { return true; } } } } } } return false; }
Example 2
Source File: JavaElementLabelComposer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException { fBuilder.append('@'); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags); IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs(); if (memberValuePairs.length == 0) { return; } fBuilder.append('('); for (int i= 0; i < memberValuePairs.length; i++) { if (i > 0) { fBuilder.append(JavaElementLabels.COMMA_STRING); } IMemberValuePair memberValuePair= memberValuePairs[i]; fBuilder.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName())); fBuilder.append('='); appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags); } fBuilder.append(')'); }
Example 3
Source File: StubCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void appendAnnotation(IAnnotation annotation) throws JavaModelException { String name= annotation.getElementName(); if (!fStubInvisible && name.startsWith("sun.")) //$NON-NLS-1$ return; // skip Sun-internal annotations fBuffer.append('@'); fBuffer.append(name); fBuffer.append('('); IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs(); for (IMemberValuePair pair : memberValuePairs) { fBuffer.append(pair.getMemberName()); fBuffer.append('='); appendAnnotationValue(pair.getValue(), pair.getValueKind()); fBuffer.append(','); } if (memberValuePairs.length > 0) fBuffer.deleteCharAt(fBuffer.length() - 1); fBuffer.append(')').append('\n'); }
Example 4
Source File: JavaElementLabelComposer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void appendAnnotationLabel(IAnnotation annotation, long flags) throws JavaModelException { fBuffer.append('@'); appendTypeSignatureLabel(annotation, Signature.createTypeSignature(annotation.getElementName(), false), flags); IMemberValuePair[] memberValuePairs= annotation.getMemberValuePairs(); if (memberValuePairs.length == 0) return; fBuffer.append('('); for (int i= 0; i < memberValuePairs.length; i++) { if (i > 0) fBuffer.append(JavaElementLabels.COMMA_STRING); IMemberValuePair memberValuePair= memberValuePairs[i]; fBuffer.append(getMemberName(annotation, annotation.getElementName(), memberValuePair.getMemberName())); fBuffer.append('='); appendAnnotationValue(annotation, memberValuePair.getValue(), memberValuePair.getValueKind(), flags); } fBuffer.append(')'); }
Example 5
Source File: PipelineOptionsProperty.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private static Requirement fromAnnotation( IAnnotation requiredAnnotation, MajorVersion majorVersion) { if (!requiredAnnotation.exists()) { return new Requirement(false, Collections.<String>emptySet()); } IMemberValuePair[] memberValuePairs; try { memberValuePairs = requiredAnnotation.getMemberValuePairs(); } catch (JavaModelException e) { DataflowCorePlugin.logError(e, "Error while retrieving Member Value Pairs for" + " Validation.Required annotation %s in Java Element %s", requiredAnnotation, requiredAnnotation.getParent()); return new Requirement(true, Collections.<String>emptySet()); } for (IMemberValuePair memberValuePair : memberValuePairs) { String memberName = memberValuePair.getMemberName(); Object memberValueObj = memberValuePair.getValue(); if (memberName.equals(PipelineOptionsNamespaces.validationRequiredGroupField(majorVersion)) && memberValueObj instanceof Object[] && memberValuePair.getValueKind() == IMemberValuePair.K_STRING) { Set<String> groups = new HashSet<>(); for (Object group : (Object[]) memberValueObj) { groups.add(group.toString()); } return new Requirement(true, groups); } } return new Requirement(true, Collections.<String>emptySet()); }
Example 6
Source File: ResourceTypeDefaultExtensions.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Find the default extensions declared directly by this type. */ private static String[] getDeclaredDefaultExtensions(IType resourceType) throws JavaModelException { // Find the @DefaultExtensions annotation IAnnotation[] annotations = resourceType.getAnnotations(); for (IAnnotation annotation : annotations) { if (isDefaultExtensionsAnnotation(annotation)) { // @DefaultExtensions should have single member-value pair: "value" IMemberValuePair[] values = annotation.getMemberValuePairs(); if (values.length == 1) { if (values[0].getMemberName().equals("value")) { Object value = values[0].getValue(); // The extensions will be stored as Object[] of strings if (value instanceof Object[]) { List<String> extensions = new ArrayList<String>(); for (Object extension : (Object[]) value) { assert (extension instanceof String); extensions.add((String) extension); } return extensions.toArray(new String[0]); } } } } } return new String[0]; }