List of usage examples for org.eclipse.jdt.core.dom IAnnotationBinding getName
@Override
public String getName();
From source file:cc.kave.eclipse.namefactory.NodeFactory.java
License:Apache License
private static boolean hasOverrideAnnotation(IMethodBinding method) { for (IAnnotationBinding iAnnotationBinding : method.getAnnotations()) { if (iAnnotationBinding.getName().equals("Override")) return true; }/*from w w w. j a v a2 s. co m*/ return false; }
From source file:com.codenvy.ide.ext.java.server.JavadocFinder.java
License:Open Source License
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 {/* w w w . ja v a2s .c o m*/ 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(')'); } }
From source file:com.google.devtools.j2objc.util.BindingUtil.java
License:Apache License
/** * Less strict version of the above where we don't care about the annotation's package. *//*from ww w.j ava 2 s .c o m*/ public static boolean hasNamedAnnotation(IBinding binding, String annotationName) { for (IAnnotationBinding annotation : binding.getAnnotations()) { if (annotation.getName().equals(annotationName)) { return true; } } return false; }
From source file:com.google.devtools.j2objc.util.BindingUtil.java
License:Apache License
/** * Returns true if the specified binding is of an annotation that has * a runtime retention policy.//w w w. j a v a 2s.c om */ public static boolean isRuntimeAnnotation(ITypeBinding binding) { if (binding != null && binding.isAnnotation()) { for (IAnnotationBinding ann : binding.getAnnotations()) { if (ann.getName().equals("Retention")) { IVariableBinding retentionBinding = (IVariableBinding) ann.getDeclaredMemberValuePairs()[0] .getValue(); return retentionBinding.getName().equals(RetentionPolicy.RUNTIME.name()); } } if (binding.isNested()) { return BindingUtil.isRuntimeAnnotation(binding.getDeclaringClass()); } } return false; }
From source file:com.google.devtools.j2objc.util.NameTable.java
License:Open Source License
/** * Return the prefix for a specified package. If a prefix was specified * for the package, then that prefix is returned. Otherwise, a camel-cased * prefix is created from the package name. */// w w w. ja v a2 s .c om public String getPrefix(IPackageBinding packageBinding) { String packageName = packageBinding.getName(); if (hasPrefix(packageName)) { return prefixMap.get(packageName); } for (IAnnotationBinding annotation : packageBinding.getAnnotations()) { if (annotation.getName().endsWith("ObjectiveCName")) { String prefix = (String) BindingUtil.getAnnotationValue(annotation, "value"); prefixMap.put(packageName, prefix); // Don't return, as there may be a prefix annotation that overrides this value. } } String prefix = getPrefixFromPackageInfoSource(packageBinding); if (prefix == null) { prefix = getPrefixFromPackageInfoClass(packageName); } if (prefix == null) { prefix = camelCaseQualifiedName(packageName); } prefixMap.put(packageName, prefix); return prefix; }
From source file:com.google.devtools.j2objc.util.PackagePrefixes.java
License:Apache License
/** * Return the prefix for a specified package. If a prefix was specified * for the package, then that prefix is returned. Otherwise, a camel-cased * prefix is created from the package name. *///from w ww .j a v a 2s . c o m public String getPrefix(IPackageBinding packageBinding) { if (packageBinding == null) { return ""; } String packageName = packageBinding.getName(); if (hasPrefix(packageName)) { return getPrefix(packageName); } for (IAnnotationBinding annotation : packageBinding.getAnnotations()) { if (annotation.getName().endsWith("ObjectiveCName")) { String prefix = (String) BindingUtil.getAnnotationValue(annotation, "value"); addPrefix(packageName, prefix); // Don't return, as there may be a prefix annotation that overrides this value. } } String prefix = getPrefixFromPackageInfoSource(packageName); if (prefix == null) { prefix = getPrefixFromPackageInfoClass(packageName); } if (prefix == null) { prefix = NameTable.camelCaseQualifiedName(packageName); } addPrefix(packageName, prefix); return prefix; }
From source file:com.j2swift.util.BindingUtil.java
License:Apache License
/** * Returns the attributes of a Property annotation. *//*from w ww.ja v a 2 s .c o m*/ public static Set<String> parseAttributeString(IAnnotationBinding propertyAnnotation) { assert propertyAnnotation.getName().equals("Property"); String attributesStr = (String) getAnnotationValue(propertyAnnotation, "value"); Set<String> attributes = Sets.newHashSet(); attributes.addAll(Arrays.asList(attributesStr.split(",\\s*"))); attributes.remove(""); // Clear any empty strings. return attributes; }
From source file:com.servoy.eclipse.docgenerator.parser.JavadocExtractor.java
License:Open Source License
private Object extractAnnotationValue(Object value) { if (value instanceof IVariableBinding) { IVariableBinding varBinding = (IVariableBinding) value; String typeQualifiedName = null; String typeSimpleName = null; if (varBinding.getDeclaringClass() != null) { typeQualifiedName = varBinding.getDeclaringClass().getQualifiedName(); typeSimpleName = varBinding.getDeclaringClass().getName(); }/*w w w. java 2s. c o m*/ return new ReferenceMetaModel(typeQualifiedName, typeSimpleName, varBinding.getName(), null, QualifiedNameDisplayState.Simple); } else if (value instanceof IAnnotationBinding) { IAnnotationBinding annBinding = (IAnnotationBinding) value; AnnotationMetaModel annot = new AnnotationMetaModel(annBinding.getName()); for (IMemberValuePairBinding attr : annBinding.getAllMemberValuePairs()) { try { String key = attr.getName(); Object val = extractAnnotationValue(attr.getValue()); annot.addAttribute(key, val); } catch (Exception e) { System.err.println("Attribute " + attr.getName() + " value is null (annotation binding " + annBinding.getName() + ")"); } } return annot; } else if (value.getClass().isArray()) { Object[] values = (Object[]) value; Object[] extractedValues = new Object[values.length]; for (int i = 0; i < values.length; i++) { extractedValues[i] = extractAnnotationValue(values[i]); } return extractedValues; } else { return value; } }
From source file:edu.cmu.cs.crystal.annotations.AnnotationDatabase.java
License:Open Source License
protected List<ICrystalAnnotation> createAnnotations(IAnnotationBinding binding) { if (isMulti(binding)) { for (IMemberValuePairBinding pair : binding.getAllMemberValuePairs()) { Object value;//from www . j ava 2s . c o m if ("value".equals(pair.getName())) value = pair.getValue(); else if ("annos".equals(pair.getName())) value = pair.getValue(); else { log.warning("Ignore extra attribute in multi-annotation " + binding.getName() + ": " + pair.toString()); continue; } if (value instanceof Object[]) { Object[] array = (Object[]) value; List<ICrystalAnnotation> result = new ArrayList<ICrystalAnnotation>(array.length); for (Object o : array) { result.add(createAnnotation((IAnnotationBinding) o)); } return Collections.unmodifiableList(result); } else { // Eclipse doesn't desugar single-element arrays with omitted braces as arrays // https://bugs.eclipse.org/bugs/show_bug.cgi?id=223225 return Collections.singletonList(createAnnotation((IAnnotationBinding) value)); } } log.warning("Couldn't find annotation array in: " + binding); } return Collections.singletonList(createAnnotation(binding)); }
From source file:edu.cmu.cs.plural.track.IndicatesAnnotation.java
License:Open Source License
/** * @param anno/*ww w. ja va2 s . com*/ * @return * @deprecated Use {@link IndicatesAnnotation#getBooleanIndicatorOnReceiverIfAny(AnnotationSummary, boolean) instead. */ public static IndicatesAnnotation createBooleanIndicatorIfPossible(IAnnotationBinding anno) { boolean bool = false; String state = "alive"; if ("Indicates".equals(anno.getName()) == false) return null; for (IMemberValuePairBinding p : anno.getAllMemberValuePairs()) { if ("bool".equals(p.getName())) { bool = (Boolean) p.getValue(); } if ("state".equals(p.getName())) { state = (String) p.getValue(); } } return new IndicatesAnnotation(bool, state); }