コード例 #1
0
ファイル: TypeName.java プロジェクト: janblok/docgenerator-ui
 public TypeName(ITypeBinding binding, boolean varargs) {
   this.varargs = varargs;
   ITypeBinding inner = binding;
   if (varargs) {
     dimensions = 1;
   } else {
     int dims = 0;
     while (inner.isArray()) {
       inner = inner.getComponentType();
       dims += 1;
     }
     dimensions = dims;
   }
   if (inner.isParameterizedType()) {
     inner = inner.getErasure();
   }
   ITypeBinding parent = inner;
   int nesting = 0;
   while (parent.isNested()) {
     nesting++;
     parent = parent.getDeclaringClass();
   }
   nestingLevel = nesting;
   primitive = inner.isPrimitive();
   baseQualifiedName = adaptQualifiedName(inner.getQualifiedName());
   baseBinaryName = inner.getBinaryName();
   shortName = buildShortName();
   qualifiedName = buildQualifiedName();
   binaryName = buildBinaryName();
 }
コード例 #2
0
ファイル: BindingUtil.java プロジェクト: mmaxiaolei/j2objc
 /**
  * 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;
 }
コード例 #3
0
ファイル: TypeName.java プロジェクト: janblok/docgenerator-ui
 /**
  * Create an instance based on a JDT type.
  *
  * <p>The location, context and warnings parameters are used for raising warnings when the type
  * bindings cannot be resolved.
  */
 public TypeName(
     Type t,
     boolean varargs,
     String location,
     String context,
     Set<DocumentationWarning> warnings) {
   this.varargs = varargs;
   // Try to resolve the binding.
   ITypeBinding binding = t.resolveBinding();
   // If binding was resolved, then use it to extract the names.
   if (binding != null) {
     ITypeBinding inner = binding;
     if (varargs) {
       dimensions = 1;
     } else {
       int dims = 0;
       while (inner.isArray()) {
         inner = inner.getComponentType();
         dims += 1;
       }
       dimensions = dims;
     }
     if (inner.isParameterizedType()) {
       inner = inner.getErasure();
     }
     ITypeBinding parent = inner;
     int nesting = 0;
     while (parent.isNested()) {
       nesting++;
       parent = parent.getDeclaringClass();
     }
     nestingLevel = nesting;
     primitive = inner.isPrimitive();
     baseQualifiedName = adaptQualifiedName(inner.getQualifiedName());
     baseBinaryName = inner.getBinaryName();
   }
   // If the binding was not resolved, then use the type name anyway.
   // This may not be accurate, but is better than nothing.
   // Also raise a warning in this case.
   else {
     String rawName = t.toString();
     int idx = rawName.indexOf("[");
     if (idx >= 0) {
       baseQualifiedName = rawName.substring(0, idx);
       String dimPart = rawName.substring(idx);
       dimensions = dimPart.length() / 2;
     } else {
       baseQualifiedName = rawName;
       dimensions = 0;
     }
     nestingLevel = 0;
     baseBinaryName = baseQualifiedName;
     primitive = t.isPrimitiveType();
     DocumentationWarning dw =
         new DocumentationWarning(
             WarningType.UnresolvedBinding,
             location,
             "Cannot resolve binding for " + context + " type: '" + baseQualifiedName + "'.");
     warnings.add(dw);
   }
   shortName = buildShortName();
   qualifiedName = buildQualifiedName();
   binaryName = buildBinaryName();
 }