Java Code Examples for com.sun.tools.javac.code.Type#toString()

The following examples show how to use com.sun.tools.javac.code.Type#toString() . 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: SrcClassUtil.java    From manifold with Apache License 2.0 6 votes vote down vote up
private SrcType makeNestedType( Type type )
{
  String fqn = type.toString();
  Type enclosingType = type.getEnclosingType();
  SrcType srcType;
  if( enclosingType != null && !(enclosingType instanceof NoType) && fqn.length() > enclosingType.toString().length() )
  {
    String simpleName = fqn.substring( enclosingType.toString().length() + 1 );
    srcType = new SrcType( simpleName );
    srcType.setEnclosingType( makeNestedType( enclosingType ) );
  }
  else
  {
    srcType = new SrcType( fqn );
  }
  return srcType;
}
 
Example 2
Source File: SrcClassUtil.java    From manifold with Apache License 2.0 6 votes vote down vote up
private String getValueForType( Type type )
{
  if( type.toString().equals( "boolean" ) )
  {
    return "false";
  }
  else if( type.isPrimitive() )
  {
    return "0";
  }
  else
  {
    String fqn = type.toString();
    return "(" + fqn  + ")null"; // cast to disambiguate when used as an argument
  }
}
 
Example 3
Source File: TreeAnalyzer.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
private static void analyzeAnnotationTree(
    final Source src, final EndPosTable endPosTable, final AnnotationTree at) {
  if (at instanceof JCTree.JCAnnotation) {
    JCTree.JCAnnotation anno = (JCTree.JCAnnotation) at;
    int startPos = anno.getPreferredPosition();
    int endPos = anno.getEndPosition(endPosTable);
    JCTree annotationType = anno.getAnnotationType();
    int annotationTypeEndPosition = annotationType.getEndPosition(endPosTable);
    Range range;
    if (endPos != annotationTypeEndPosition) {
      startPos = annotationTypeEndPosition;
    }
    range = Range.create(src, startPos + 1, endPos);
    Type type = anno.type;
    Annotation annotation;
    if (nonNull(type)) {
      annotation = new Annotation(type.toString(), startPos, range);
    } else {
      annotation = new Annotation(annotationType.toString(), startPos, range);
    }
    src.annotationMap.put(range.begin.line, annotation);
  }
}
 
Example 4
Source File: T6889255.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 5
Source File: T6889255.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 6
Source File: T6889255.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 7
Source File: T6889255.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 8
Source File: T6889255.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 9
Source File: T6889255.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 10
Source File: T6889255.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 11
Source File: T6889255.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
String getExpectedName(VarSymbol v, int i) {
    // special cases:
    // synthetic method
    if (((v.owner.owner.flags() & Flags.ENUM) != 0)
            && v.owner.name.toString().equals("valueOf"))
        return "name";
    // interfaces don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.owner.flags() & Flags.INTERFACE) != 0)
        return "arg" + (i - 1);
    // abstract methods don't have saved names
    // -- no Code attribute for the LocalVariableTable attribute
    if ((v.owner.flags() & Flags.ABSTRACT) != 0)
        return "arg" + (i - 1);
    // bridge methods use argN. No LVT for them anymore
    if ((v.owner.flags() & Flags.BRIDGE) != 0)
        return "arg" + (i - 1);

    // The rest of this method assumes the local conventions in the test program
    Type t = v.type;
    String s;
    if (t.hasTag(TypeTag.CLASS))
        s = ((ClassType) t).tsym.name.toString();
    else
        s = t.toString();
    return String.valueOf(Character.toLowerCase(s.charAt(0))) + i;
}
 
Example 12
Source File: JNIWriter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@SuppressWarnings("fallthrough")
protected final String jniType(Type t) {
    switch (t.getKind()) {
        case ARRAY: {
            Type ct = ((Type.ArrayType)t).getComponentType();
            switch (ct.getKind()) {
                case BOOLEAN:  return "jbooleanArray";
                case BYTE:     return "jbyteArray";
                case CHAR:     return "jcharArray";
                case SHORT:    return "jshortArray";
                case INT:      return "jintArray";
                case LONG:     return "jlongArray";
                case FLOAT:    return "jfloatArray";
                case DOUBLE:   return "jdoubleArray";
                case ARRAY:
                case DECLARED: return "jobjectArray";
                default: throw new Error(ct.toString());
            }
        }

        case VOID:     return "void";
        case BOOLEAN:  return "jboolean";
        case BYTE:     return "jbyte";
        case CHAR:     return "jchar";
        case SHORT:    return "jshort";
        case INT:      return "jint";
        case LONG:     return "jlong";
        case FLOAT:    return "jfloat";
        case DOUBLE:   return "jdouble";
        case DECLARED: {
            if (t.tsym.type == syms.stringType) {
                return "jstring";
            } else if (types.isAssignable(t, syms.throwableType)) {
                return "jthrowable";
            } else if (types.isAssignable(t, syms.classType)) {
                return "jclass";
            } else {
                return "jobject";
            }
        }
    }

    Assert.check(false, "jni unknown type");
    return null; /* dead code. */
}
 
Example 13
Source File: JNIWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("fallthrough")
protected final String jniType(Type t) {
    switch (t.getKind()) {
        case ARRAY: {
            Type ct = ((Type.ArrayType)t).getComponentType();
            switch (ct.getKind()) {
                case BOOLEAN:  return "jbooleanArray";
                case BYTE:     return "jbyteArray";
                case CHAR:     return "jcharArray";
                case SHORT:    return "jshortArray";
                case INT:      return "jintArray";
                case LONG:     return "jlongArray";
                case FLOAT:    return "jfloatArray";
                case DOUBLE:   return "jdoubleArray";
                case ARRAY:
                case DECLARED: return "jobjectArray";
                default: throw new Error(ct.toString());
            }
        }

        case VOID:     return "void";
        case BOOLEAN:  return "jboolean";
        case BYTE:     return "jbyte";
        case CHAR:     return "jchar";
        case SHORT:    return "jshort";
        case INT:      return "jint";
        case LONG:     return "jlong";
        case FLOAT:    return "jfloat";
        case DOUBLE:   return "jdouble";
        case DECLARED: {
            if (t.tsym.type == syms.stringType) {
                return "jstring";
            } else if (types.isAssignable(t, syms.throwableType)) {
                return "jthrowable";
            } else if (types.isAssignable(t, syms.classType)) {
                return "jclass";
            } else {
                return "jobject";
            }
        }
    }

    Assert.check(false, "jni unknown type");
    return null; /* dead code. */
}
 
Example 14
Source File: SrcClassUtil.java    From manifold with Apache License 2.0 4 votes vote down vote up
private String typeNoAnnotations( Type type )
{
  if( isJava8() )
  {
    return type.toString();
  }

  StringBuilder sb = new StringBuilder();
  if( type instanceof Type.ClassType )
  {
    if( type.getEnclosingType().hasTag( CLASS ) &&
        ReflectUtil.field( type.tsym.owner, "kind" ).get() == ReflectUtil.field( "com.sun.tools.javac.code.Kinds$Kind", "TYP" ).getStatic() )
    {
      sb.append( typeNoAnnotations( type.getEnclosingType() ) );
      sb.append( "." );
      sb.append( ReflectUtil.method( type, "className", Symbol.class, boolean.class ).invoke( type.tsym, false ) );
    }
    else
    {
      sb.append( ReflectUtil.method( type, "className", Symbol.class, boolean.class ).invoke( type.tsym, true ) );
    }

    List<Type> typeArgs = type.getTypeArguments();
    if( typeArgs.nonEmpty() )
    {
      sb.append( '<' );
      for( int i = 0; i < typeArgs.size(); i++ )
      {
        if( i > 0 )
        {
          sb.append( ", " );
        }
        Type typeArg = typeArgs.get( i );
        sb.append( typeNoAnnotations( typeArg ) );
      }
      sb.append( ">" );
    }
  }
  else if( type instanceof Type.ArrayType )
  {
    sb.append( typeNoAnnotations( ((Type.ArrayType)type).getComponentType() ) ).append( "[]" );
  }
  else if( type instanceof Type.WildcardType )
  {
    Type.WildcardType wildcardType = (Type.WildcardType)type;
    BoundKind kind = wildcardType.kind;
    sb.append( kind.toString() );
    if( kind != BoundKind.UNBOUND )
    {
      sb.append( typeNoAnnotations( wildcardType.type ) );
    }
  }
  else
  {
    sb.append( type.toString() );
  }
  return sb.toString();
}