Java Code Examples for com.sun.tools.javac.code.Types

The following examples show how to use com.sun.tools.javac.code.Types. These examples are extracted from open source projects. 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 Project: hottub   Author: dsrg-uoft   File: LambdaToMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
private LambdaToMethod(Context context) {
    context.put(unlambdaKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    lower = Lower.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    make = TreeMaker.instance(context);
    types = Types.instance(context);
    transTypes = TransTypes.instance(context);
    analyzer = new LambdaAnalyzerPreprocessor();
    Options options = Options.instance(context);
    dumpLambdaToMethodStats = options.isSet("dumpLambdaToMethodStats");
    attr = Attr.instance(context);
    forceSerializable = options.isSet("forceSerializable");
}
 
Example #2
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: TestInvokeDynamic.java    License: GNU General Public License v2.0 6 votes vote down vote up
Object getValue(Symtab syms, Names names, Types types) {
    switch (this) {
        case STRING:
        case INTEGER:
        case LONG:
        case FLOAT:
        case DOUBLE:
            return value;
        case CLASS:
            return syms.stringType.tsym;
        case METHOD_HANDLE:
            return new Pool.MethodHandle(REF_invokeVirtual,
                    syms.arrayCloneMethod, types);
        case METHOD_TYPE:
            return syms.arrayCloneMethod.type;
        default:
            throw new AssertionError();
    }
}
 
Example #3
Source Project: TencentKona-8   Author: Tencent   File: LambdaToMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
private LambdaToMethod(Context context) {
    context.put(unlambdaKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    lower = Lower.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    make = TreeMaker.instance(context);
    types = Types.instance(context);
    transTypes = TransTypes.instance(context);
    analyzer = new LambdaAnalyzerPreprocessor();
    Options options = Options.instance(context);
    dumpLambdaToMethodStats = options.isSet("dumpLambdaToMethodStats");
    attr = Attr.instance(context);
    forceSerializable = options.isSet("forceSerializable");
}
 
Example #4
Source Project: manifold   Author: manifold-systems   File: DynamicProxyFactory.java    License: Apache License 2.0 6 votes vote down vote up
private static boolean hasCallHandlerFromExtension( Class rootClass )
{
  Boolean isCallHandler = ICALL_HANDLER_MAP.get( rootClass );
  if( isCallHandler != null )
  {
    return isCallHandler;
  }

  String fqn = rootClass.getCanonicalName();
  BasicJavacTask javacTask = RuntimeManifoldHost.get().getJavaParser().getJavacTask();
  Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> classSymbol = ClassSymbols.instance( RuntimeManifoldHost.get().getSingleModule() ).getClassSymbol( javacTask, fqn );
  Pair<Symbol.ClassSymbol, JCTree.JCCompilationUnit> callHandlerSymbol = ClassSymbols.instance( RuntimeManifoldHost.get().getSingleModule() ).getClassSymbol( javacTask, ICallHandler.class.getCanonicalName() );
  if( Types.instance( javacTask.getContext() ).isAssignable( classSymbol.getFirst().asType(), callHandlerSymbol.getFirst().asType() ) )
  {
    // Nominally implements ICallHandler
    isCallHandler = true;
  }
  else
  {
    // Structurally implements ICallHandler
    isCallHandler = hasCallMethod( javacTask, classSymbol.getFirst() );
  }
  ICALL_HANDLER_MAP.put( rootClass, isCallHandler );
  return isCallHandler;
}
 
Example #5
Source Project: javaide   Author: tranleduy2000   File: Enter.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected Enter(Context context) {
    context.put(enterKey, this);

    log = Log.instance(context);
    reader = ClassReader.instance(context);
    make = TreeMaker.instance(context);
    syms = Symtab.instance(context);
    chk = Check.instance(context);
    memberEnter = MemberEnter.instance(context);
    types = Types.instance(context);
    annotate = Annotate.instance(context);
    lint = Lint.instance(context);
    names = Names.instance(context);

    predefClassDef = make.ClassDef(
        make.Modifiers(PUBLIC),
        syms.predefClass.name, null, null, null, null);
    predefClassDef.sym = syms.predefClass;
    todo = Todo.instance(context);
    fileManager = context.get(JavaFileManager.class);

    Options options = Options.instance(context);
    pkginfoOpt = PkgInfo.get(options);
}
 
Example #6
Source Project: jdk8u60   Author: chenghanpeng   File: LambdaToMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
private LambdaToMethod(Context context) {
    context.put(unlambdaKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    lower = Lower.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    make = TreeMaker.instance(context);
    types = Types.instance(context);
    transTypes = TransTypes.instance(context);
    analyzer = new LambdaAnalyzerPreprocessor();
    Options options = Options.instance(context);
    dumpLambdaToMethodStats = options.isSet("dumpLambdaToMethodStats");
    attr = Attr.instance(context);
    forceSerializable = options.isSet("forceSerializable");
}
 
Example #7
Source Project: manifold   Author: manifold-systems   File: ExtensionTransformer.java    License: Apache License 2.0 6 votes vote down vote up
/** Unbox an object to a primitive value. */
private JCExpression unbox( Types types, TreeMaker make, Names names, JCExpression tree, Type primitive ) {
  Type unboxedType = types.unboxedType(tree.type);
  if (unboxedType.hasTag(NONE)) {
    unboxedType = primitive;
    if (!unboxedType.isPrimitive())
      throw new AssertionError(unboxedType);
    make.at(tree.pos());
    tree = make.TypeCast(types.boxedClass(unboxedType).type, tree);
  } else {
    // There must be a conversion from unboxedType to primitive.
    if (!types.isSubtype(unboxedType, primitive))
      throw new AssertionError(tree);
  }
  make.at(tree.pos());
  Symbol valueSym = resolveMethod(tree.pos(),
    unboxedType.tsym.name.append(names.Value), // x.intValue()
    tree.type,
    List.<Type>nil());
  return make.App(make.Select(tree, valueSym));
}
 
Example #8
Source Project: openjdk-8-source   Author: keerath   File: LambdaToMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
private LambdaToMethod(Context context) {
    context.put(unlambdaKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    lower = Lower.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    make = TreeMaker.instance(context);
    types = Types.instance(context);
    transTypes = TransTypes.instance(context);
    analyzer = new LambdaAnalyzerPreprocessor();
    Options options = Options.instance(context);
    dumpLambdaToMethodStats = options.isSet("dumpLambdaToMethodStats");
    attr = Attr.instance(context);
}
 
Example #9
Source Project: NullAway   Author: uber   File: OptionalEmptinessHandler.java    License: MIT License 6 votes vote down vote up
@Override
public NullnessHint onDataflowVisitMethodInvocation(
    MethodInvocationNode node,
    Types types,
    Context context,
    AccessPathNullnessPropagation.SubNodeValues inputs,
    AccessPathNullnessPropagation.Updates thenUpdates,
    AccessPathNullnessPropagation.Updates elseUpdates,
    AccessPathNullnessPropagation.Updates bothUpdates) {
  Symbol.MethodSymbol symbol = ASTHelpers.getSymbol(node.getTree());

  if (optionalIsPresentCall(symbol, types)) {
    updateNonNullAPsForOptionalContent(thenUpdates, node.getTarget().getReceiver());
  } else if (config.handleTestAssertionLibraries() && methodNameUtil.isMethodIsTrue(symbol)) {
    // we check for instance of AssertThat(optionalFoo.isPresent()).isTrue()
    updateIfAssertIsPresentTrueOnOptional(node, types, bothUpdates);
  }
  return NullnessHint.UNKNOWN;
}
 
Example #10
Source Project: NullAway   Author: uber   File: AccessPath.java    License: MIT License 6 votes vote down vote up
private static boolean isMapMethod(
    Symbol.MethodSymbol symbol, Types types, String methodName, int numParams) {
  if (!symbol.getSimpleName().toString().equals(methodName)) {
    return false;
  }
  if (symbol.getParameters().size() != numParams) {
    return false;
  }
  Symbol owner = symbol.owner;
  if (owner.getQualifiedName().toString().equals("java.util.Map")) {
    return true;
  }
  com.sun.tools.javac.util.List<Type> supertypes = types.closure(owner.type);
  for (Type t : supertypes) {
    if (t.asElement().getQualifiedName().toString().equals("java.util.Map")) {
      return true;
    }
  }
  return false;
}
 
Example #11
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: LambdaToMethod.java    License: GNU General Public License v2.0 6 votes vote down vote up
private LambdaToMethod(Context context) {
    context.put(unlambdaKey, this);
    diags = JCDiagnostic.Factory.instance(context);
    log = Log.instance(context);
    lower = Lower.instance(context);
    names = Names.instance(context);
    syms = Symtab.instance(context);
    rs = Resolve.instance(context);
    make = TreeMaker.instance(context);
    types = Types.instance(context);
    transTypes = TransTypes.instance(context);
    analyzer = new LambdaAnalyzerPreprocessor();
    Options options = Options.instance(context);
    dumpLambdaToMethodStats = options.isSet("dumpLambdaToMethodStats");
    attr = Attr.instance(context);
    forceSerializable = options.isSet("forceSerializable");
}
 
Example #12
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: MakeLiteralTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
void run() throws Exception {
    Context context = new Context();
    JavacFileManager.preRegister(context);
    Symtab syms = Symtab.instance(context);
    maker = TreeMaker.instance(context);
    types = Types.instance(context);

    test("abc",                     CLASS,      syms.stringType,    "abc");
    test(Boolean.FALSE,             BOOLEAN,    syms.booleanType,   Integer.valueOf(0));
    test(Boolean.TRUE,              BOOLEAN,    syms.booleanType,   Integer.valueOf(1));
    test(Byte.valueOf((byte) 1),    BYTE,       syms.byteType,      Byte.valueOf((byte) 1));
    test(Character.valueOf('a'),    CHAR,       syms.charType,      Integer.valueOf('a'));
    test(Double.valueOf(1d),        DOUBLE,     syms.doubleType,    Double.valueOf(1d));
    test(Float.valueOf(1f),         FLOAT,      syms.floatType,     Float.valueOf(1f));
    test(Integer.valueOf(1),        INT,        syms.intType,       Integer.valueOf(1));
    test(Long.valueOf(1),           LONG,       syms.longType,      Long.valueOf(1));
    test(Short.valueOf((short) 1),  SHORT,      syms.shortType,     Short.valueOf((short) 1));

    if (errors > 0)
        throw new Exception(errors + " errors found");
}
 
Example #13
Source Project: lua-for-android   Author: qtiuto   File: ClassWriter.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static boolean isSameType(Type t1, Type t2, Types types) {
    if (t1 == null) { return t2 == null; }
    if (t2 == null) { return false; }

    if (isInt(t1) && isInt(t2)) { return true; }

    if (t1.hasTag(UNINITIALIZED_THIS)) {
        return t2.hasTag(UNINITIALIZED_THIS);
    } else if (t1.hasTag(UNINITIALIZED_OBJECT)) {
        if (t2.hasTag(UNINITIALIZED_OBJECT)) {
            return ((UninitializedType)t1).offset == ((UninitializedType)t2).offset;
        } else {
            return false;
        }
    } else if (t2.hasTag(UNINITIALIZED_THIS) || t2.hasTag(UNINITIALIZED_OBJECT)) {
        return false;
    }

    return types.isSameType(t1, t2);
}
 
Example #14
Source Project: manifold   Author: manifold-systems   File: ExtensionTransformer.java    License: Apache License 2.0 6 votes vote down vote up
/** Expand a boxing or unboxing conversion if needed. */
<T extends JCTree> T boxUnboxIfNeeded( Types types, TreeMaker make, Names names, T tree, Type type) {
  boolean havePrimitive = tree.type.isPrimitive();
  if (havePrimitive == type.isPrimitive())
    return tree;
  if (havePrimitive) {
    Type unboxedTarget = types.unboxedType(type);
    if (!unboxedTarget.hasTag(NONE)) {
      if (!types.isSubtype(tree.type, unboxedTarget)) //e.g. Character c = 89;
        tree.type = unboxedTarget.constType(tree.type.constValue());
      return (T)boxPrimitive(types, make, names, (JCExpression)tree, type);
    } else {
      tree = (T)boxPrimitive(types, make, names, (JCExpression)tree);
    }
  } else {
    tree = (T)unbox(types, make, names, (JCExpression)tree, type);
  }
  return tree;
}
 
Example #15
Source Project: lua-for-android   Author: qtiuto   File: Pool.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** Place an object in the pool, unless it is already there.
 *  If object is a symbol also enter its owner unless the owner is a
 *  package.  Return the object's index in the pool.
 */
public int put(Object value) {
    value = makePoolValue(value);
    Assert.check(!(value instanceof Type.TypeVar));
    Assert.check(!(value instanceof Types.UniqueType &&
                   ((UniqueType) value).type instanceof Type.TypeVar));
    Integer index = indices.get(value);
    if (index == null) {
        index = pp;
        indices.put(value, index);
        pool = ArrayUtils.ensureCapacity(pool, pp);
        pool[pp++] = value;
        if (value instanceof Long || value instanceof Double) {
            pool = ArrayUtils.ensureCapacity(pool, pp);
            pool[pp++] = null;
        }
    }
    return index.intValue();
}
 
Example #16
Source Project: j2objc   Author: google   File: TreeConverter.java    License: Apache License 2.0 6 votes vote down vote up
private TreeNode convertFunctionalExpression(
    JCFunctionalExpression node, TreePath parent, FunctionalExpression newNode) {
  List<? extends TypeMirror> targets = getTargets(node, parent);
  for (TypeMirror type : targets) {
    newNode.addTargetType(type);
  }
  Types types =
      Types.instance(((com.sun.tools.javac.api.BasicJavacTask) env.task()).getContext());
  return newNode
      .setTypeMirror(targets.iterator().next())
      .setDescriptor(
          new ExecutablePair(
              (ExecutableElement) types
                  .findDescriptorSymbol(((com.sun.tools.javac.code.Type) targets.get(0)).tsym),
              (ExecutableType) node.getDescriptorType(types)));
}
 
Example #17
Source Project: TencentKona-8   Author: Tencent   File: Pool.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** Construct a pool with given number of elements and element array.
 */
public Pool(int pp, Object[] pool, Types types) {
    this.pp = pp;
    this.pool = pool;
    this.types = types;
    this.indices = new HashMap<Object,Integer>(pool.length);
    for (int i = 1; i < pp; i++) {
        if (pool[i] != null) indices.put(pool[i], i);
    }
}
 
Example #18
Source Project: openjdk-8   Author: bpupadhyaya   File: ImplementationCacheTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    List<? extends JavaFileObject> files = Arrays.asList(new SourceFile());
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, files);
    Context ctx = new Context();
    JavacFileManager.preRegister(ctx);
    checkImplementationCache(ct.analyze(), Types.instance(ctx));
}
 
Example #19
Source Project: lua-for-android   Author: qtiuto   File: MemberEnter.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected MemberEnter(Context context) {
    context.put(memberEnterKey, this);
    enter = Enter.instance(context);
    log = Log.instance(context);
    chk = Check.instance(context);
    attr = Attr.instance(context);
    syms = Symtab.instance(context);
    annotate = Annotate.instance(context);
    types = Types.instance(context);
    deferredLintHandler = DeferredLintHandler.instance(context);
}
 
Example #20
Source Project: lua-for-android   Author: qtiuto   File: Infer.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean accepts(UndetVar t, InferenceContext inferenceContext) {
    if (!t.isThrows()) {
        //not a throws undet var
        return false;
    }
    Types types = inferenceContext.types;
    Symtab syms = inferenceContext.infer.syms;
    return StreamSupport.stream(t.getBounds(InferenceBound.UPPER))
            .filter(b -> !inferenceContext.free(b))
            .allMatch(u -> types.isSubtype(syms.runtimeExceptionType, u));
}
 
Example #21
Source Project: TencentKona-8   Author: Tencent   File: TypeHarness.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected TypeHarness() {
    Context ctx = new Context();
    JavacFileManager.preRegister(ctx);
    types = Types.instance(ctx);
    chk = Check.instance(ctx);
    predef = Symtab.instance(ctx);
    names = Names.instance(ctx);
    fac = new Factory();
}
 
Example #22
Source Project: TencentKona-8   Author: Tencent   File: ImplementationCacheTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    List<? extends JavaFileObject> files = Arrays.asList(new SourceFile());
    JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, files);
    Context ctx = new Context();
    JavacFileManager.preRegister(ctx);
    checkImplementationCache(ct.analyze(), Types.instance(ctx));
}
 
Example #23
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: JavacTrees.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void init(Context context) {
    attr = Attr.instance(context);
    enter = Enter.instance(context);
    elements = JavacElements.instance(context);
    log = Log.instance(context);
    resolve = Resolve.instance(context);
    treeMaker = TreeMaker.instance(context);
    memberEnter = MemberEnter.instance(context);
    names = Names.instance(context);
    types = Types.instance(context);

    JavacTask t = context.get(JavacTask.class);
    if (t instanceof JavacTaskImpl)
        javacTaskImpl = (JavacTaskImpl) t;
}
 
Example #24
Source Project: jdk8u60   Author: chenghanpeng   File: Pool.java    License: GNU General Public License v2.0 5 votes vote down vote up
private Object[] getUniqueTypeArray(Object[] objects, Types types) {
    Object[] result = new Object[objects.length];
    for (int i = 0; i < objects.length; i++) {
        if (objects[i] instanceof Type) {
            result[i] = new UniqueType((Type)objects[i], types);
        } else {
            result[i] = objects[i];
        }
    }
    return result;
}
 
Example #25
Source Project: openjdk-8   Author: bpupadhyaya   File: RichDiagnosticFormatter.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected RichDiagnosticFormatter(Context context) {
    super((AbstractDiagnosticFormatter)Log.instance(context).getDiagnosticFormatter());
    setRichPrinter(new RichPrinter());
    this.syms = Symtab.instance(context);
    this.diags = JCDiagnostic.Factory.instance(context);
    this.types = Types.instance(context);
    this.messages = JavacMessages.instance(context);
    whereClauses = new EnumMap<WhereClauseKind, Map<Type, JCDiagnostic>>(WhereClauseKind.class);
    configuration = new RichConfiguration(Options.instance(context), formatter);
    for (WhereClauseKind kind : WhereClauseKind.values())
        whereClauses.put(kind, new LinkedHashMap<Type, JCDiagnostic>());
}
 
Example #26
Source Project: java-n-IDE-for-Android   Author: shenghuntianlang   File: RichDiagnosticFormatter.java    License: Apache License 2.0 5 votes vote down vote up
protected RichDiagnosticFormatter(Context context) {
    super((AbstractDiagnosticFormatter) Log.instance(context).getDiagnosticFormatter());
    setRichPrinter(new RichPrinter());
    this.syms = Symtab.instance(context);
    this.diags = JCDiagnostic.Factory.instance(context);
    this.types = Types.instance(context);
    this.messages = JavacMessages.instance(context);
    whereClauses = new LinkedHashMap<WhereClauseKind, Map<Type, JCDiagnostic>>();
    configuration = new RichConfiguration(Options.instance(context), formatter);
    for (WhereClauseKind kind : WhereClauseKind.values())
        whereClauses.put(kind, new LinkedHashMap<Type, JCDiagnostic>());
}
 
Example #27
Source Project: manifold   Author: manifold-systems   File: ManAttr.java    License: Apache License 2.0 5 votes vote down vote up
static Symbol.MethodSymbol resolveOperatorMethod( Types types, Tag tag, Type left, Type right )
{
  String opName = BINARY_OP_TO_NAME.get( tag );
  if( opName == null )
  {
    if( isComparableOperator( tag ) )
    {
      opName = COMPARE_TO_USING;
    }
    else
    {
      return null;
    }
  }

  if( left instanceof Type.TypeVar )
  {
    left = types.erasure( left );
  }

  if( !(left.tsym instanceof Symbol.ClassSymbol) )
  {
    return null;
  }

  int paramCount = opName.equals( COMPARE_TO_USING ) ? 2 : 1;
  Symbol.MethodSymbol methodSymbol = getMethodSymbol( types, left, right, opName, (Symbol.ClassSymbol)left.tsym, paramCount );
  if( methodSymbol == null && paramCount == 2 && !left.isPrimitive() && isRelationalOperator( tag ) )
  {
    // Support > >= < <= on any Comparable implementor
    methodSymbol = getMethodSymbol( types, left, right, COMPARE_TO, (Symbol.ClassSymbol)left.tsym, 1 );

  }
  return methodSymbol;
}
 
Example #28
Source Project: manifold   Author: manifold-systems   File: ManAttr.java    License: Apache License 2.0 5 votes vote down vote up
static boolean isAssignableWithGenerics( Types types, Type t1, Type t2 )
{
  if( t2 instanceof Type.TypeVar )
  {
    Type parameterizedParamType = types.asSuper( t1, t2.getUpperBound().tsym );
    return parameterizedParamType != null;
  }
  return false;
}
 
Example #29
Source Project: openjdk-8   Author: bpupadhyaya   File: TypeHarness.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected TypeHarness() {
    Context ctx = new Context();
    JavacFileManager.preRegister(ctx);
    types = Types.instance(ctx);
    chk = Check.instance(ctx);
    predef = Symtab.instance(ctx);
    names = Names.instance(ctx);
    fac = new Factory();
}
 
Example #30
Source Project: manifold   Author: manifold-systems   File: ManAttr.java    License: Apache License 2.0 5 votes vote down vote up
static Symbol.MethodSymbol resolveNegationMethod( Types types, Tag tag, Type expr )
{
  if( expr instanceof Type.TypeVar )
  {
    expr = types.erasure( expr );
  }

  if( !(expr.tsym instanceof Symbol.ClassSymbol) )
  {
    return null;
  }

  return getMethodSymbol( types, expr, null, UNARY_MINUS, (Symbol.ClassSymbol)expr.tsym, 0 );
}