コード例 #1
0
ファイル: TypeURIHelper.java プロジェクト: iloveeclipse/xtext
 /** @since 2.4 */
 protected URI getFullURI(ITypeBinding typeBinding, SegmentSequence.Builder builder) {
   if (typeBinding.isPrimitive()) {
     builder.append(PRIMITIVE_URIS[typeBinding.getKey().charAt(0) - 'B'].fragment());
     return PRIMITIVES_URI;
   }
   if (typeBinding.isClass()
       || typeBinding.isInterface()
       || typeBinding.isAnnotation()
       || typeBinding.isEnum()) {
     ITypeBinding declaringClass = typeBinding.getDeclaringClass();
     if (declaringClass != null) {
       URI uri = getFullURI(declaringClass, builder);
       builder.append("$");
       builder.append(typeBinding.getName());
       return uri;
     }
     String qualifiedName = typeBinding.getErasure().getQualifiedName();
     URI uri = COMMON_URIS.get(qualifiedName);
     if (uri == null) {
       uri = OBJECTS_URI.appendSegment(qualifiedName);
     }
     builder.append(uri.lastSegment());
     return uri;
   }
   if (typeBinding.isArray()) {
     URI uri = getFullURI(typeBinding.getComponentType(), builder);
     builder.append("[]");
     return uri;
   }
   if (typeBinding.isTypeVariable()) {
     ITypeBinding declaringClass = typeBinding.getDeclaringClass();
     if (declaringClass != null) {
       URI uri = getFullURI(declaringClass, builder);
       builder.append("/");
       builder.append(typeBinding.getName());
       return uri;
     }
     IMethodBinding declaringMethod = typeBinding.getDeclaringMethod();
     URI uri = getFullURI(declaringMethod.getDeclaringClass(), builder);
     builder.append(".");
     builder.append(declaringMethod.getName());
     builder.append("(");
     ITypeBinding[] parameterTypes = declaringMethod.getParameterTypes();
     for (int i = 0; i < parameterTypes.length; i++) {
       if (i != 0) {
         builder.append(",");
       }
       getQualifiedName(parameterTypes[i], builder);
     }
     builder.append(")");
     builder.append("/");
     builder.append(typeBinding.getName());
     return uri;
   }
   throw new IllegalStateException("Unexpected type: " + typeBinding);
 }
コード例 #2
0
ファイル: TypeURIHelper.java プロジェクト: iloveeclipse/xtext
 protected void createResourceURIForTypeVariable(
     ITypeBinding typeBinding, StringBuilder uriBuilder) {
   if (typeBinding.getDeclaringClass() != null) {
     ITypeBinding declaringClass = typeBinding.getDeclaringClass();
     createResourceURIForClass(declaringClass, uriBuilder);
   } else {
     IMethodBinding declaringMethod = typeBinding.getDeclaringMethod();
     ITypeBinding declaringClass = declaringMethod.getDeclaringClass();
     createResourceURIForClass(declaringClass, uriBuilder);
   }
 }
コード例 #3
0
ファイル: TypeURIHelper.java プロジェクト: iloveeclipse/xtext
 public URI getFullURI(ITypeBinding typeBinding) {
   // The URIs for primitive types are cached and indexed by their one character key
   // representation.
   //
   if (typeBinding.isPrimitive()) {
     return PRIMITIVE_URIS[typeBinding.getKey().charAt(0) - 'B'];
   }
   if (typeBinding.isClass()
       || typeBinding.isInterface()
       || typeBinding.isAnnotation()
       || typeBinding.isEnum()) {
     ITypeBinding declaringClass = typeBinding.getDeclaringClass();
     if (declaringClass == null) {
       // This special case handling for common case of top level types that avoids creating a
       // builder.
       //
       String qualifiedName = typeBinding.getErasure().getQualifiedName();
       URI uri = COMMON_URIS.get(qualifiedName);
       if (uri != null) {
         return uri;
       }
       uri = OBJECTS_URI.appendSegment(qualifiedName);
       return uri.appendFragment(uri.lastSegment());
     }
     SegmentSequence.Builder builder = SegmentSequence.newBuilder("");
     URI uri = getFullURI(declaringClass, builder);
     builder.append("$");
     builder.append(typeBinding.getName());
     return uri.appendFragment(builder.toString());
   }
   SegmentSequence.Builder builder = SegmentSequence.newBuilder("");
   URI uri = getFullURI(typeBinding, builder);
   return uri.appendFragment(builder.toString());
 }
コード例 #4
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();
 }
コード例 #5
0
ファイル: TypeURIHelper.java プロジェクト: iloveeclipse/xtext
 protected void createResourceURIForClass(ITypeBinding typeBinding, StringBuilder uriBuilder) {
   ITypeBinding declaringClass = typeBinding.getDeclaringClass();
   if (declaringClass != null) {
     createResourceURIForClass(declaringClass, uriBuilder);
   } else {
     createResourceURIForClassImpl2(typeBinding.getErasure().getQualifiedName(), uriBuilder);
   }
 }
コード例 #6
0
ファイル: TypeURIHelper.java プロジェクト: iloveeclipse/xtext
 protected void createFragmentForTypeVariable(ITypeBinding typeBinding, StringBuilder uriBuilder) {
   if (typeBinding.getDeclaringMethod() != null) {
     createFragmentForMethod(typeBinding.getDeclaringMethod(), uriBuilder);
   } else {
     createFragment(typeBinding.getDeclaringClass(), uriBuilder);
   }
   uriBuilder.append('/');
   uriBuilder.append(typeBinding.getName());
 }
コード例 #7
0
ファイル: BindingUtil.java プロジェクト: mmaxiaolei/j2objc
 /**
  * Tests if this type is private to it's source file. A public type declared within a private type
  * is considered private.
  */
 public static boolean isPrivateInnerType(ITypeBinding type) {
   if (isPrivate(type) || type.isLocal() || type.isAnonymous()) {
     return true;
   }
   ITypeBinding declaringClass = type.getDeclaringClass();
   if (declaringClass != null) {
     return isPrivateInnerType(declaringClass);
   }
   return false;
 }
コード例 #8
0
ファイル: BindingUtil.java プロジェクト: mmaxiaolei/j2objc
 /** Determines if a type can access fields and methods from an outer class. */
 public static boolean hasOuterContext(ITypeBinding type) {
   if (type.getDeclaringClass() == null) {
     return false;
   }
   // Local types can't be declared static, but if the declaring method is
   // static then the local type is effectively static.
   IMethodBinding declaringMethod = type.getTypeDeclaration().getDeclaringMethod();
   if (declaringMethod != null) {
     return !BindingUtil.isStatic(declaringMethod);
   }
   return !BindingUtil.isStatic(type);
 }
コード例 #9
0
 private static String fqTypeName(ITypeBinding type) {
   type = canonicalType(type);
   // TODO Need to get rid of type variables
   String type_name = type.getQualifiedName();
   if ("".equals(type_name)) {
     // only okay if this is a top-level class.
     if (type.getDeclaringClass() != null) {
       return null;
     }
     // Will the 'else' branch _ever_ be taken?
   }
   return type.getQualifiedName();
 }
コード例 #10
0
ファイル: TypeURIHelper.java プロジェクト: iloveeclipse/xtext
 /** @since 2.4 */
 protected SegmentSequence.Builder getQualifiedName(
     ITypeBinding binding, SegmentSequence.Builder builder) {
   if (binding.isParameterizedType()) {
     getQualifiedName(binding.getErasure(), builder);
   } else if (binding.isArray()) {
     getQualifiedName(binding.getComponentType(), builder).append("[]");
   } else if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive()) {
     builder.append(binding.getQualifiedName());
   } else {
     getQualifiedName(binding.getDeclaringClass(), builder).append('$').append(binding.getName());
   }
   return builder;
 }
コード例 #11
0
ファイル: TypeURIHelper.java プロジェクト: iloveeclipse/xtext
 /** @since 2.4 */
 public StringBuilder getQualifiedName(ITypeBinding binding, StringBuilder stringBuilder) {
   if (binding.isParameterizedType()) {
     getQualifiedName(binding.getErasure(), stringBuilder);
   } else if (binding.isArray()) {
     getQualifiedName(binding.getComponentType(), stringBuilder).append("[]");
   } else if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive()) {
     stringBuilder.append(binding.getQualifiedName());
   } else {
     getQualifiedName(binding.getDeclaringClass(), stringBuilder)
         .append('$')
         .append(binding.getName());
   }
   return stringBuilder;
 }
コード例 #12
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;
 }
コード例 #13
0
ファイル: TypeURIHelper.java プロジェクト: iloveeclipse/xtext
 public String getQualifiedName(ITypeBinding binding) {
   if (binding.isParameterizedType()) {
     return getQualifiedName(binding.getErasure());
   }
   if (binding.isArray()) {
     return getQualifiedName(binding.getComponentType(), new StringBuilder())
         .append("[]")
         .toString();
   }
   if (binding.isTopLevel() || binding.isTypeVariable() || binding.isPrimitive())
     return binding.getQualifiedName();
   return getQualifiedName(binding.getDeclaringClass(), new StringBuilder())
       .append('$')
       .append(binding.getName())
       .toString();
 }
コード例 #14
0
ファイル: BindingUtil.java プロジェクト: mmaxiaolei/j2objc
  /**
   * Get a method's signature for dead code elimination purposes.
   *
   * <p>Since DeadCodeEliminator runs before InnerClassExtractor, inner class constructors do not
   * yet have the parameter for capturing outer class, and therefore we need this special case.
   */
  public static String getProGuardSignature(IMethodBinding binding) {
    StringBuilder sb = new StringBuilder("(");

    // If the method is an inner class constructor, prepend the outer class type.
    if (binding.isConstructor()) {
      ITypeBinding declClass = binding.getDeclaringClass();
      ITypeBinding outerClass = declClass.getDeclaringClass();
      if (outerClass != null
          && !declClass.isInterface()
          && !declClass.isAnnotation()
          && !Modifier.isStatic(declClass.getModifiers())) {
        appendParameterSignature(outerClass.getErasure(), sb);
      }
    }

    appendParametersSignature(binding, sb);
    sb.append(')');
    appendReturnTypeSignature(binding, sb);
    return sb.toString();
  }
コード例 #15
0
  @Override
  public boolean visit(ClassInstanceCreation node) {
    ITypeBinding newType = node.getTypeBinding().getTypeDeclaration();
    ITypeBinding declaringClass = newType.getDeclaringClass();
    if (Modifier.isStatic(newType.getModifiers()) || declaringClass == null) {
      return true;
    }

    GeneratedMethodBinding binding =
        new GeneratedMethodBinding(node.getMethodBinding().getMethodDeclaration());
    node.setMethodBinding(binding);
    addOuterArg(node, binding, declaringClass);

    for (IVariableBinding capturedVar : getCapturedVariables(node)) {
      node.getArguments().add(new SimpleName(capturedVar));
      binding.addParameter(capturedVar.getType());
    }

    assert binding.isVarargs() || node.getArguments().size() == binding.getParameterTypes().length;
    return true;
  }
コード例 #16
0
 protected Import getReference(ITypeBinding binding) {
   if (!binding.isTypeVariable()
       && !binding.isPrimitive()
       && !binding.isAnnotation()
       // Don't import IOS types, other than the IOS array types,
       // since they have header files.
       && (binding instanceof IOSArrayTypeBinding || !(binding instanceof IOSTypeBinding))) {
     binding = Types.mapType(binding);
     String typeName = NameTable.getFullName(binding);
     boolean isInterface = binding.isInterface();
     while (!binding.isTopLevel()) {
       binding = binding.getDeclaringClass();
     }
     return getReference(typeName, binding.getErasure().getQualifiedName(), isInterface);
   } else if (binding.isTypeVariable()) {
     ITypeBinding[] typeBounds = binding.getTypeBounds();
     if (typeBounds.length > 0 && !Types.isJavaObjectType(typeBounds[0])) {
       return getReference(typeBounds[0]);
     }
   }
   return NULL_IMPORT;
 }
コード例 #17
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();
 }