Java 类org.eclipse.jdt.core.dom.IAnnotationBinding 实例源码

项目:gw4e.project    文件:JDTManager.java   
/**
 * @param project
 * @param itype
 * @return
 * @throws JavaModelException
 */
private static IPath findPathInGeneratedAnnotation(IProject project, IType itype) throws JavaModelException {
    ICompilationUnit cu = itype.getCompilationUnit();
    List<IAnnotationBinding> annotations = resolveAnnotation(cu, Generated.class).getAnnotations();
    if ((annotations != null) && (annotations.size() > 0)) {
        IAnnotationBinding ab = annotations.get(0);
        IMemberValuePairBinding[] attributes = ab.getAllMemberValuePairs();
        for (int i = 0; i < attributes.length; i++) {
            IMemberValuePairBinding attribut = attributes[i];
            if (attribut.getName().equalsIgnoreCase("value")) {
                Object[] o = (Object[]) attribut.getValue();
                if (o != null && o.length > 0 && String.valueOf(o[0]).trim().length() > 0) {
                    try {
                        IPath p = ResourceManager.find(project, String.valueOf(o[0]).trim());
                        return p;
                    } catch (Exception e) {
                        ResourceManager.logException(e);
                        return null;
                    }
                }
            }
        }
    }
    return null;
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param project
 * @param itype
 * @return
 * @throws JavaModelException
 */
public static IPath findPathInModelAnnotation(IProject project, IType itype) throws JavaModelException {
    ICompilationUnit cu = itype.getCompilationUnit();
    List<IAnnotationBinding> annotations = resolveAnnotation(cu, Model.class).getAnnotations();
    if ((annotations != null) && (annotations.size() > 0)) {
        IAnnotationBinding ab = annotations.get(0);
        IMemberValuePairBinding[] attributes = ab.getAllMemberValuePairs();
        for (int i = 0; i < attributes.length; i++) {
            IMemberValuePairBinding attribut = attributes[i];
            if (attribut.getName().equalsIgnoreCase("value")) {
                Object[] o = (Object[]) attribut.getValue();
                if (o != null && o.length > 0 && String.valueOf(o[0]).trim().length() > 0) {
                    try {
                        IPath p = ResourceManager.find(project, String.valueOf(o[0]).trim());
                        return p;
                    } catch (Exception e) {
                        ResourceManager.logException(e);
                        return null;
                    }
                }
            }
        }
    }
    return null;
}
项目:gw4e.project    文件:JDTManager.java   
/**
 * @param cu
 * @return
 */
public static String findPathGeneratorInGraphWalkerAnnotation(ICompilationUnit cu) {
    CompilationUnit ast = parse(cu);
    Map<String, String> ret = new HashMap<String, String>();
    ast.accept(new ASTVisitor() {
        public boolean visit(MemberValuePair node) {
            String name = node.getName().getFullyQualifiedName();
            if ("value".equals(name) && node.getParent() != null && node.getParent() instanceof NormalAnnotation) {
                IAnnotationBinding annoBinding = ((NormalAnnotation) node.getParent()).resolveAnnotationBinding();
                String qname = annoBinding.getAnnotationType().getQualifiedName();
                if (GraphWalker.class.getName().equals(qname)) {
                    StringLiteral sl = (StringLiteral) node.getValue();
                    ret.put("ret", sl.getLiteralValue());
                }
            }
            return true;
        }
    });
    return ret.get("ret");
}
项目:gw4e.project    文件:JDTManager.java   
private static IType getClassesWithAnnotation(ICompilationUnit compilationUnit, Class annotationClass,
        String attributName, boolean valued) throws JavaModelException {
    List<IAnnotationBinding> annotations = resolveAnnotation(compilationUnit, annotationClass).getAnnotations();
    if ((annotations != null) && (annotations.size() > 0)) {
        IAnnotationBinding ab = annotations.get(0);
        IMemberValuePairBinding[] attributes = ab.getAllMemberValuePairs();
        for (int i = 0; i < attributes.length; i++) {
            IMemberValuePairBinding attribut = attributes[i];
            if (attribut.getName().equalsIgnoreCase(attributName)) {
                if (valued) {
                    if (String.valueOf(attribut.getValue()).trim().length() > 0) {
                        return compilationUnit.findPrimaryType();
                    }
                } else {
                    if (String.valueOf(attribut.getValue()).trim().length() == 0) {
                        return compilationUnit.findPrimaryType();
                    }
                }
            }
        }
    }
    return null;
}
项目:gw4e.project    文件:AnnotationParsing.java   
/**
 * @param index
 * @return
 */
public String getValue (int index) {
    if ((annotations != null) && annotations.size() > 0) {
        IAnnotationBinding generated = annotations.get(index);
        IMemberValuePairBinding[] vpb = generated.getAllMemberValuePairs();
        for (int i = 0; i < vpb.length; i++) {
            IMemberValuePairBinding pair = vpb[i];
            if ("value".equals(pair.getName())) {
                Object object =  pair.getValue();
                String value = null;
                if (object!=null && object.getClass().isArray()) {
                    Object [] values = (Object []) object;
                    value = (String) values[0];
                } else {
                    value = (String) object;
                }
                return value;
            }
        }
    }
    return null;
}
项目:gw4e.project    文件:AnnotationParsing.java   
public String getValue (String attribute, int index) {
    if ((annotations != null) && annotations.size() > 0) {
        IAnnotationBinding generated = annotations.get(index);
        IMemberValuePairBinding[] vpb = generated.getAllMemberValuePairs();
        for (int i = 0; i < vpb.length; i++) {
            IMemberValuePairBinding pair = vpb[i];
            if (attribute.equals(pair.getName())) {
                Object object =  pair.getValue();
                String value = null;
                if (object!=null && object.getClass().isArray()) {
                    Object [] values = (Object []) object;
                    value = (String) values[0];
                } else {
                    value = (String) object;
                }
                return value;
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:ASTNodeFactory.java   
/**
 * Create a Type suitable as the creationType in a ClassInstanceCreation expression.
 * @param ast The AST to create the nodes for.
 * @param typeBinding binding representing the given class type
 * @param importRewrite the import rewrite to use
 * @param importContext the import context used to determine which (null) annotations to consider
 * @return a Type suitable as the creationType in a ClassInstanceCreation expression.
 */
public static Type newCreationType(AST ast, ITypeBinding typeBinding, ImportRewrite importRewrite, ImportRewriteContext importContext) {
    if (typeBinding.isParameterizedType()) {
        Type baseType= newCreationType(ast, typeBinding.getTypeDeclaration(), importRewrite, importContext);
        IAnnotationBinding[] typeAnnotations= importContext.removeRedundantTypeAnnotations(typeBinding.getTypeAnnotations(), TypeLocation.NEW, typeBinding);
        for (IAnnotationBinding typeAnnotation : typeAnnotations) {
            ((AnnotatableType)baseType).annotations().add(importRewrite.addAnnotation(typeAnnotation, ast, importContext));
        }
        ParameterizedType parameterizedType= ast.newParameterizedType(baseType);
        for (ITypeBinding typeArgument : typeBinding.getTypeArguments()) {
            typeArgument= StubUtility2.replaceWildcardsAndCaptures(typeArgument);
            parameterizedType.typeArguments().add(importRewrite.addImport(typeArgument, ast, importContext, TypeLocation.TYPE_ARGUMENT));
        }
        return parameterizedType;
    } else {
        return importRewrite.addImport(typeBinding, ast, importContext, TypeLocation.NEW);
    }
}
项目:eclipse.jdt.ls    文件:StubUtility2.java   
public static boolean isCopyOnInheritAnnotation(ITypeBinding annotationType, IJavaProject project, IAnnotationBinding defaultNullness) {
    if (JavaCore.ENABLED.equals(project.getOption(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, true))) {
        return false;
    }
    if (defaultNullness != null && Bindings.isNonNullAnnotation(annotationType, project)) {
        IMemberValuePairBinding[] memberValuePairs= defaultNullness.getDeclaredMemberValuePairs();
        if (memberValuePairs.length == 1) {
            Object value= memberValuePairs[0].getValue();
            if (value instanceof Boolean) {
                return Boolean.FALSE.equals(value); // do copy within @NonNullByDefault(false)
            }
        }
        // missing or unrecognized value
        return false; // nonnull within the scope of @NonNullByDefault: don't copy
    }
    return Bindings.isAnyNullAnnotation(annotationType, project);
}
项目:code    文件:AnnotatMetrics.java   
/**
 * @param domain
 * @param ann finds a domain in annotation binding
 */
private boolean hasDomain(DomainParams domain, IAnnotationBinding ann) {
 IMemberValuePairBinding[] pairs = ann.getDeclaredMemberValuePairs();
 for (int i = 0; i < pairs.length; i++) {
    if (pairs[i].getValue() instanceof String) {
        String dname = (String)pairs[i].getValue();
        if (dname.equals(domain.getDomainName())) return true;
    }
    if (pairs[i].getValue() instanceof Object[]){
        Object[] objs = (Object[])pairs[i].getValue();
        for (int j = 0; j < objs.length; j++) {
            String dName = objs[j].toString();
            if (dName.equals(domain.getDomainName())) return true;
        }
    }
 }
 return false;
}
项目:j2objc    文件:ImplementationImportCollector.java   
private boolean visitAnnotation(Annotation node) {
  IAnnotationBinding binding = node.getAnnotationBinding();
  boolean needsReflection = false;
  AbstractTypeDeclaration owningType = TreeUtil.getOwningType(node);
  if (owningType != null) {
    needsReflection = TranslationUtil.needsReflection(owningType);
  } else {
    needsReflection = TranslationUtil.needsReflection(
        TreeUtil.getNearestAncestorWithType(PackageDeclaration.class, node));
  }
  if (!BindingUtil.isRuntimeAnnotation(binding) || !needsReflection) {
    return false;
  }
  for (IMemberValuePairBinding memberValuePair : binding.getAllMemberValuePairs()) {
    if (memberValuePair.isDefault()) {
      Object value = memberValuePair.getValue();
      if (value instanceof IVariableBinding) {
        addImports(((IVariableBinding) value).getType());
      } else if (value instanceof ITypeBinding) {
        addImports((ITypeBinding) value);
      }
    }
  }
  return true;
}
项目:j2objc    文件:BlockRewriter.java   
@Override
public void endVisit(MethodDeclaration node) {
  IMethodBinding binding = node.getMethodBinding();

  for (int i = 0; i < binding.getParameterTypes().length; i++) {
    IAnnotationBinding annotation = BindingUtil.getAnnotation(
        binding.getParameterAnnotations(i), com.google.j2objc.annotations.Block.class);
    if (annotation != null) {
      Block body = node.getBody();
      // allow for native methods
      if (body != null) {
        insertBlockWrappingStatement(node.getBody(), node, annotation, i);
      }
    }
  }
}
项目:j2objc    文件:BindingUtil.java   
/**
 * Returns true if the specified binding is of an annotation that has
 * a runtime retention policy.
 */
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;
}
项目:j2objc    文件:BindingUtil.java   
public static IOSBlockTypeBinding getBlockType(IAnnotationBinding[] annotations, ITypeBinding blockTpe) {
  IAnnotationBinding blockAnno = BindingUtil.getAnnotation(
      annotations,
      com.google.j2objc.annotations.Block.class
  );
  if (blockAnno == null) {
    return null;
  }
  if (blockTpe instanceof IOSBlockTypeBinding) {
    return (IOSBlockTypeBinding) blockTpe;
  }

  Object[] argObjs = BlockBridge.paramTypes(blockAnno, blockTpe);
  List<String> args = Lists.newArrayList();
  for (Object argObj : argObjs) {
    args.add((String) argObj);
  }
  IOSBlockTypeBinding nativeBlockType = new IOSBlockTypeBinding(
      BlockBridge.returnType(blockAnno, blockTpe),
      args,
      blockTpe
  );

  return nativeBlockType;
}
项目:j2objc    文件:BindingUtil.java   
public static String[] paramTypes(IAnnotationBinding blockAnnotation, ITypeBinding blockTpe) {
  IMethodBinding runMethod = runMethod(blockAnnotation, blockTpe);
  Object[] blockParams = (Object[]) BindingUtil.getAnnotationValue(blockAnnotation, "params");

  ITypeBinding[] paramTpes = runMethod.getParameterTypes();
  List<String> out = Lists.newArrayList();

  if (blockParams.length != paramTpes.length) {
    for (int i = 0; i < paramTpes.length; i++) {
      out.add(NameTable.getSpecificObjCType(paramTpes[i]));
    }
  } else {
    for (int i = 0; i < paramTpes.length; i++) {
      out.add((String) blockParams[i]);
    }
  }

  return out.toArray(new String[paramTpes.length]);
}
项目:che    文件:NullAnnotationsRewriteOperations.java   
boolean hasNonNullDefault(IBinding enclosingElement) {
  if (!fRemoveIfNonNullByDefault) return false;
  IAnnotationBinding[] annotations = enclosingElement.getAnnotations();
  for (int i = 0; i < annotations.length; i++) {
    IAnnotationBinding annot = annotations[i];
    if (annot.getAnnotationType().getQualifiedName().equals(fNonNullByDefaultName)) {
      IMemberValuePairBinding[] pairs = annot.getDeclaredMemberValuePairs();
      if (pairs.length > 0) {
        // is default cancelled by "false" or "value=false" ?
        for (int j = 0; j < pairs.length; j++)
          if (pairs[j].getKey() == null || pairs[j].getKey().equals("value")) // $NON-NLS-1$
          return (pairs[j].getValue() != Boolean.FALSE);
      }
      return true;
    }
  }
  if (enclosingElement instanceof IMethodBinding) {
    return hasNonNullDefault(((IMethodBinding) enclosingElement).getDeclaringClass());
  } else if (enclosingElement instanceof ITypeBinding) {
    ITypeBinding typeBinding = (ITypeBinding) enclosingElement;
    if (typeBinding.isLocal()) return hasNonNullDefault(typeBinding.getDeclaringMethod());
    else if (typeBinding.isMember()) return hasNonNullDefault(typeBinding.getDeclaringClass());
    else return hasNonNullDefault(typeBinding.getPackage());
  }
  return false;
}
项目:gwt-eclipse-plugin    文件:ValidationSuppressionVisitor.java   
private void processAnnotationBinding(
    IAnnotationBinding resolvedAnnotationBinding) {
  if (resolvedAnnotationBinding != null) {
    ITypeBinding annotationType = resolvedAnnotationBinding.getAnnotationType();
    if (annotationType != null) {
      if (annotationType.getQualifiedName().equals(
          SuppressWarnings.class.getName())) {
        IMemberValuePairBinding[] allMemberValuePairs = resolvedAnnotationBinding.getAllMemberValuePairs();
        for (IMemberValuePairBinding iMemberValuePairBinding : allMemberValuePairs) {
          if (computeSuppressWarning(iMemberValuePairBinding)) {
            suppressValidation = true;
            break;
          }
        }
      }
    }
  }
}
项目:txtUML    文件:ModelUtils.java   
/**
 * @return an empty optional if the given package binding is not the top
 *         package of a JtxtUML model; otherwise an optional of the name of
 *         the model (the name is the name of the package if not specified)
 */
public static Optional<String> findModelNameInTopPackage(IPackageBinding packageBinding) {
    List<IAnnotationBinding> annots = Stream.of(packageBinding.getAnnotations())
            .filter(a -> a.getAnnotationType().getQualifiedName().equals(Model.class.getCanonicalName()))
            .collect(Collectors.toList());

    if (annots.size() == 1) {
        Optional<String> name = Stream.of(annots.get(0).getDeclaredMemberValuePairs())
                .filter(p -> p.getName().equals("value")).map(p -> (String) p.getValue()).findAny();
        if (name.isPresent()) {
            return name;
        } else {
            return Optional.of(packageBinding.getName());
        }
    }

    return Optional.empty();
}
项目:jdt2famix    文件:InJavaImporter.java   
private void setUpMethodFromMethodBinding(Method method, IMethodBinding binding) {
    if (binding.isConstructor()) 
        method.setKind(CONSTRUCTOR_KIND);
    ITypeBinding returnType = binding.getReturnType();
    if ((returnType != null) && !(returnType.isPrimitive() && returnType.getName().equals("void")))
        //we do not want to set void as a return type
        method.setDeclaredType(ensureTypeFromTypeBinding(returnType));
    extractBasicModifiersFromBinding(binding.getModifiers(), method);
    if (Modifier.isStatic(binding.getModifiers()))
        method.setHasClassScope(true);
    try {
        IAnnotationBinding[] annotations = binding.getAnnotations();
        createAnnotationInstancesToEntityFromAnnotationBinding(method, annotations);
    } catch(NullPointerException e) {
        /* This happens in some very strange circumstances, likely due to missing dependencies.
         * The only solution I found was to catch the exception and log it and provide people
         * with a way to solve it by adding the missing dependencies to the import.
         */
        logNullBinding("annotation instances for method binding", Famix.qualifiedNameOf(method) , -1);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:JavadocHover.java   
private static void addAnnotation(StringBuffer buf, IJavaElement element, IAnnotationBinding annotation) throws URISyntaxException {
    IJavaElement javaElement= annotation.getAnnotationType().getJavaElement();
    buf.append('@');
    if (javaElement != null) {
        String uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, 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(JavaElementLinks.JAVADOC_SCHEME, mvPair.getMethodBinding().getJavaElement());
            addLink(buf, memberURI, mvPair.getName());
            buf.append('=');
            addValue(buf, element, mvPair.getValue());
        }
        buf.append(')');
    }
}
项目:mybatipse    文件:JavaMapperUtil.java   
@Override
public boolean matches(IMethodBinding method) throws JavaModelException
{
    for (IAnnotationBinding annotation : method.getAnnotations())
    {
        String annotationName = annotation.getAnnotationType().getQualifiedName();
        if (MybatipseConstants.ANNOTATION_RESULTS.equals(annotationName))
        {
            IMemberValuePairBinding[] valuePairs = annotation.getAllMemberValuePairs();
            for (IMemberValuePairBinding valuePair : valuePairs)
            {
                if ("id".equals(valuePair.getName()))
                {
                    String resultsId = (String)valuePair.getValue();
                    return nameMatches(resultsId, matchString, exactMatch);
                }
            }
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:Bindings.java   
public static boolean isClassOrRuntimeAnnotation(ITypeBinding annotationType) {
    IAnnotationBinding[] metaAnnotations= annotationType.getAnnotations();
    for (IAnnotationBinding metaAnnotation : metaAnnotations) {
        if ("java.lang.annotation.Retention".equals(metaAnnotation.getAnnotationType().getQualifiedName())) { //$NON-NLS-1$
            IMemberValuePairBinding[] mvps= metaAnnotation.getDeclaredMemberValuePairs();
            if (mvps.length == 1) {
                Object value= mvps[0].getValue();
                if (value instanceof IVariableBinding) {
                    String name= ((IVariableBinding) value).getName();
                    if ("RUNTIME".equals(name) || "CLASS".equals(name)) //$NON-NLS-1$ //$NON-NLS-2$
                        return true;
                }
            }
        }
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocHover.java   
private static void addAnnotation(StringBuffer buf, IJavaElement element, IAnnotationBinding annotation) throws URISyntaxException {
    String uri= JavaElementLinks.createURI(JavaElementLinks.JAVADOC_SCHEME, annotation.getAnnotationType().getJavaElement());
    buf.append('@');
    addLink(buf, uri, 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(JavaElementLinks.JAVADOC_SCHEME, mvPair.getMethodBinding().getJavaElement());
            addLink(buf, memberURI, mvPair.getName());
            buf.append('=');
            addValue(buf, element, mvPair.getValue());
        }
        buf.append(')');
    }
}
项目:sahagin-java    文件:ASTUtils.java   
public static IAnnotationBinding getAnnotationBinding(
        IAnnotationBinding[] annotations, String annotationClassName) {
    if (annotations == null) {
        return null;
    }
    if (annotationClassName == null) {
        throw new NullPointerException();
    }

    for (IAnnotationBinding annotation : annotations) {
        String qName = annotation.getAnnotationType().getBinaryName();
        assert qName != null;
        // TODO if multiple annotations for annotationClassName exists
        if (qName.equals(annotationClassName)) {
            return annotation;
        }
    }
    return null;
}
项目:sahagin-java    文件:ASTUtils.java   
private static Object getAnnotationValue(IAnnotationBinding annotation, String varName) {
    if (annotation == null) {
        throw new NullPointerException();
    }
    if (varName == null) {
        throw new NullPointerException();
    }
    for (IMemberValuePairBinding value : annotation.getDeclaredMemberValuePairs()) {
        if (value.getName() != null && value.getName().equals(varName)) {
            assert value.getValue() != null; // annotation value cannot be null
            assert !(value.getValue() instanceof IVariableBinding);
            return value.getValue();
        }
    }
    return null;
}
项目:sahagin-java    文件:ASTUtils.java   
private static String getEnumAnnotationFieldName(IAnnotationBinding annotation, String varName) {
    if (annotation == null) {
        throw new NullPointerException();
    }
    if (varName == null) {
        throw new NullPointerException();
    }
    for (IMemberValuePairBinding value : annotation.getDeclaredMemberValuePairs()) {
        if (value.getName() != null && value.getName().equals(varName)) {
            assert value.getValue() != null; // annotation value cannot be null
            assert value.getValue() instanceof IVariableBinding;
            IVariableBinding varBinding = (IVariableBinding) value.getValue();
            assert varBinding.isEnumConstant();
            return varBinding.getName();
        }
    }
    return null;
}
项目:sahagin-java    文件:ASTUtils.java   
private static Pair<String, CaptureStyle> getTestDoc(
        IAnnotationBinding[] annotations, AcceptableLocales locales) {
    Pair<Map<Locale, String>, CaptureStyle> allTestDocs = getAllTestDocs(annotations);
    Map<Locale, String> testDocMap = allTestDocs.getLeft();
    if (testDocMap.isEmpty()) {
        return Pair.of(null, CaptureStyle.getDefault()); // no @TestDoc found
    }

    String testDoc = null;
    for (Locale locale : locales.getLocales()) {
        String value = testDocMap.get(locale);
        if (value != null) {
            testDoc = value;
            break;
        }
    }
    if (testDoc == null) {
        // set empty string if no locale matched data is found
        return Pair.of("", allTestDocs.getRight());
    } else {
        return Pair.of(testDoc, allTestDocs.getRight());
    }
}
项目:sahagin-java    文件:ASTUtils.java   
private static String getPageDoc(
        IAnnotationBinding[] annotations, AcceptableLocales locales) {
    Map<Locale, String> allPages = getAllPageDocs(annotations);
    if (allPages.isEmpty()) {
        return null; // no @Page found
    }

    for (Locale locale : locales.getLocales()) {
        String value = allPages.get(locale);
        if (value != null) {
            return value;
        }
    }
    // set empty string if no locale matched data is found
    return "";
}
项目:eclipse.jdt.ls    文件:Bindings.java   
/**
 * Answer the annotation binding representing a nullness default
 * effective at the point denoted by 'contextBinding'.
 * @param contextBinding method binding or type binding denoting the location of interest
 * @param javaProject the containing java project, consulted for the actual name of
 *  the annotation used for nullness defaults (default: <code>@NonNullByDefault</code>).
 * @return binding for the effective nullness default annotation
 *  or null if no nullness default is effective at the context location.
 */
public static IAnnotationBinding findNullnessDefault(IBinding contextBinding, IJavaProject javaProject) {
    if (JavaCore.ENABLED.equals(javaProject.getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true))) {
        String annotationName= javaProject.getOption(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, true);
        while (contextBinding != null) {
            for (IAnnotationBinding annotation : contextBinding.getAnnotations()) {
                ITypeBinding annotationType= annotation.getAnnotationType();
                if (annotationType != null && annotationType.getQualifiedName().equals(annotationName)) {
                    return annotation;
                }
            }
            // travel out:
            switch (contextBinding.getKind()) {
            case IBinding.METHOD:
                IMethodBinding methodBinding= (IMethodBinding) contextBinding;
                contextBinding= methodBinding.getDeclaringMember();
                if (contextBinding == null) {
                    contextBinding= methodBinding.getDeclaringClass();
                }
                break;
            case IBinding.VARIABLE:
                IVariableBinding variableBinding= (IVariableBinding) contextBinding;
                contextBinding= variableBinding.getDeclaringMethod();
                if (contextBinding == null) {
                    contextBinding= variableBinding.getDeclaringClass();
                }
                break;
            case IBinding.TYPE:
                ITypeBinding currentClass= (ITypeBinding) contextBinding;
                contextBinding= currentClass.getDeclaringMember();
                if (contextBinding == null) {
                    contextBinding= currentClass.getDeclaringMethod();
                    if (contextBinding == null) {
                        contextBinding= currentClass.getDeclaringClass();
                        if (contextBinding == null) {
                            contextBinding= currentClass.getPackage();
                        }
                    }
                }
                break;
            default:
                contextBinding= null;
                break;
            }
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:TypeAnnotationRewrite.java   
private static boolean isPureTypeAnnotation(Annotation annotation) {
    IAnnotationBinding binding= annotation.resolveAnnotationBinding();
    if (binding == null) {
        return false;
    }
    IAnnotationBinding targetAnnotationBinding= findTargetAnnotation(binding.getAnnotationType().getAnnotations());

    if (targetAnnotationBinding == null) {
        return false;
    }
    return isTypeUseOnly(targetAnnotationBinding);
}
项目:eclipse.jdt.ls    文件:TypeAnnotationRewrite.java   
private static IAnnotationBinding findTargetAnnotation(IAnnotationBinding[] metaAnnotations) {
    for (int i= 0; i < metaAnnotations.length; i++) {
        IAnnotationBinding binding= metaAnnotations[i];
        ITypeBinding annotationType= binding.getAnnotationType();
        if (annotationType != null && annotationType.getQualifiedName().equals(Target.class.getName())) {
            return binding;
        }
    }
    return null;
}
项目:eclipse.jdt.ls    文件:RedundantNullnessTypeAnnotationsFilter.java   
public static EnumSet<TypeLocation> determineNonNullByDefaultLocations(ASTNode astNode, String nonNullByDefaultName) {
    // look for first @NonNullByDefault
    while (astNode != null) {
        IAnnotationBinding annot= getNNBDAnnotation(astNode, nonNullByDefaultName);
        if (annot != null) {
            return determineNNBDValue(annot);
        }
        astNode= astNode.getParent();
    }
    return EnumSet.noneOf(TypeLocation.class);
}
项目:eclipse.jdt.ls    文件:RedundantNullnessTypeAnnotationsFilter.java   
public IAnnotationBinding[] removeUnwantedTypeAnnotations(IAnnotationBinding[] annotations, TypeLocation location, ITypeBinding type) {
    if (location == TypeLocation.OTHER) {
        return NO_ANNOTATIONS;
    }
    if(type.isTypeVariable() || type.isWildcardType()) {
        return annotations;
    }
    boolean excludeAllNullAnnotations = NEVER_NULLNESS_LOCATIONS.contains(location);
    if (excludeAllNullAnnotations || fNonNullByDefaultLocations.contains(location)) {
        ArrayList<IAnnotationBinding> list= new ArrayList<>(annotations.length);
        for (IAnnotationBinding annotation : annotations) {
            ITypeBinding annotationType= annotation.getAnnotationType();
            if (annotationType != null) {
                if (annotationType.getQualifiedName().equals(fNonNullAnnotationName)) {
                    // ignore @NonNull
                } else if (excludeAllNullAnnotations && annotationType.getQualifiedName().equals(fNullableAnnotationName)) {
                    // also ignore @Nullable
                } else {
                    list.add(annotation);
                }
            } else {
                list.add(annotation);
            }
        }
        return list.size() == annotations.length ? annotations : list.toArray(new IAnnotationBinding[list.size()]);
    } else {
        return annotations;
    }
}
项目:eclipse.jdt.ls    文件:ContextSensitiveImportRewriteContext.java   
@Override
public IAnnotationBinding[] removeRedundantTypeAnnotations(IAnnotationBinding[] annotations, TypeLocation location, ITypeBinding type) {
    RedundantNullnessTypeAnnotationsFilter redundantTypeAnnotationsFilter= fRedundantTypeAnnotationsFilter;
    if (redundantTypeAnnotationsFilter != null) {
        annotations= redundantTypeAnnotationsFilter.removeUnwantedTypeAnnotations(annotations, location, type);
    }
    return super.removeRedundantTypeAnnotations(annotations, location, type);
}
项目:code    文件:AnnotatMetrics.java   
public boolean isDomain(ITypeBinding iTypeBinding, DomainParams domain) {
    if (domain.isLent()||domain.isUnique()||domain.isShared())
        return true;

    IAnnotationBinding[] annotations = iTypeBinding.getAnnotations();
    for (IAnnotationBinding ann : annotations) {
        if (ann.getName().equals("Domains")) {
            if (hasDomain(domain, ann)) return true;
        }
    }
    return false;
}
项目:code    文件:AnnotatMetrics.java   
public boolean isDomainParams(ITypeBinding iTypeBinding, DomainParams domain) {
    if (domain.isLent() || domain.isUnique() || domain.isShared() || domain.isOwned()) return false;
    if (domain.isOwner()) return true;

    IAnnotationBinding[] annotations = iTypeBinding.getAnnotations();
    for (IAnnotationBinding ann : annotations) {
        if (ann.getName().equals("DomainParams")) {
            if (hasDomain(domain, ann)) return true;                
        }
    }
    return false;
}
项目:j2objc    文件:GeneratedMethodBinding.java   
@Override
public IAnnotationBinding[] getParameterAnnotations(int paramIndex) {
  if (delegate == null) {
    return parameterAnnotations.get(paramIndex);
  } else {
    return delegate.getParameterAnnotations(paramIndex);
  }
}
项目:j2objc    文件:AbstractBinding.java   
public void addAnnotation(IAnnotationBinding binding) {
  if (binding != null) {
    if (!annotations.contains(binding)) {
      annotations.add(binding);
    }
  }
}
项目:j2objc    文件:RuntimeAnnotationGenerator.java   
private void printAnnotation(IAnnotationBinding annotation) {
  if (Options.useReferenceCounting()) {
    print('[');
  }
  printf("[[%s alloc] init", NameTable.getFullName(
      annotation.getAnnotationType()));
  printAnnotationParameters(annotation);
  print(']');
  if (Options.useReferenceCounting()) {
    print(" autorelease]");
  }
}
项目:j2objc    文件:RuntimeAnnotationGenerator.java   
private void printAnnotationParameters(IAnnotationBinding annotation) {
  IMemberValuePairBinding[] valueBindings = BindingUtil.getSortedMemberValuePairs(annotation);
  for (int i = 0; i < valueBindings.length; i++) {
    if (i > 0) {
      print(' ');
    }
    IMemberValuePairBinding valueBinding = valueBindings[i];
    print(i == 0 ? "With" : "with");
    printf("%s:", NameTable.capitalize(
        NameTable.getAnnotationPropertyName(valueBinding.getMethodBinding())));
    Object value = valueBinding.getValue();
    printAnnotationValue(value);
  }
}
项目:j2objc    文件:EnhancedForRewriter.java   
private boolean emitJavaIteratorLoop(IVariableBinding loopVariable) {
  IAnnotationBinding loopTranslation =
      BindingUtil.getAnnotation(loopVariable, LoopTranslation.class);
  if (loopTranslation == null) {
    return false;
  }
  Object style = BindingUtil.getAnnotationValue(loopTranslation, "value");
  if (style instanceof IVariableBinding
      && ((IVariableBinding) style).getName().equals(LoopStyle.JAVA_ITERATOR.name())) {
    return true;
  }
  return false;
}