use of com.sun.tools.javac.code.Symtab in project error-prone by google.
the class Template method infer.
/**
* Returns the inferred method type of the template based on the given actual argument types.
*
* @throws InferException if no instances of the specified type variables would allow the
* {@code actualArgTypes} to match the {@code expectedArgTypes}
*/
private Type infer(Warner warner, Inliner inliner, List<Type> freeTypeVariables, List<Type> expectedArgTypes, Type returnType, List<Type> actualArgTypes) throws InferException {
Symtab symtab = inliner.symtab();
Type methodType = new MethodType(expectedArgTypes, returnType, List.<Type>nil(), symtab.methodClass);
if (!freeTypeVariables.isEmpty()) {
methodType = new ForAll(freeTypeVariables, methodType);
}
Enter enter = inliner.enter();
MethodSymbol methodSymbol = new MethodSymbol(0, inliner.asName("__m__"), methodType, symtab.unknownSymbol);
Type site = symtab.methodClass.type;
Env<AttrContext> env = enter.getTopLevelEnv(TreeMaker.instance(inliner.getContext()).TopLevel(List.<JCTree>nil()));
// Set up the resolution phase:
try {
Field field = AttrContext.class.getDeclaredField("pendingResolutionPhase");
field.setAccessible(true);
field.set(env.info, newMethodResolutionPhase(autoboxing()));
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
Object resultInfo;
try {
Class<?> resultInfoClass = Class.forName("com.sun.tools.javac.comp.Attr$ResultInfo");
Constructor<?> resultInfoCtor = resultInfoClass.getDeclaredConstructor(Attr.class, KindSelector.class, Type.class);
resultInfoCtor.setAccessible(true);
resultInfo = resultInfoCtor.newInstance(Attr.instance(inliner.getContext()), KindSelector.PCK, Type.noType);
} catch (ReflectiveOperationException e) {
throw new LinkageError(e.getMessage(), e);
}
// Type inference sometimes produces diagnostics, so we need to catch them to avoid interfering
// with the enclosing compilation.
Log.DeferredDiagnosticHandler handler = new Log.DeferredDiagnosticHandler(Log.instance(inliner.getContext()));
try {
MethodType result = callCheckMethod(warner, inliner, resultInfo, actualArgTypes, methodSymbol, site, env);
if (!handler.getDiagnostics().isEmpty()) {
throw new InferException(handler.getDiagnostics());
}
return result;
} finally {
Log.instance(inliner.getContext()).popDiagnosticHandler(handler);
}
}
use of com.sun.tools.javac.code.Symtab in project ceylon-compiler by ceylon.
the class TestSymtabItems method run.
void run() throws Exception {
Context c = new Context();
JavacFileManager.preRegister(c);
Symtab syms = Symtab.instance(c);
JavacTypes types = JavacTypes.instance(c);
// will init ClassReader.sourceCompleter
JavaCompiler.instance(c);
for (Field f : Symtab.class.getDeclaredFields()) {
// during API evolution
if (f.getName().toLowerCase().contains("methodhandle"))
continue;
Class<?> ft = f.getType();
if (TypeMirror.class.isAssignableFrom(ft))
print(f.getName(), (TypeMirror) f.get(syms), types);
else if (Element.class.isAssignableFrom(ft))
print(f.getName(), (Element) f.get(syms));
}
if (errors > 0)
throw new Exception(errors + " errors occurred");
}
use of com.sun.tools.javac.code.Symtab in project ceylon-compiler by ceylon.
the class MakeLiteralTest method run.
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");
}
use of com.sun.tools.javac.code.Symtab in project bazel by bazelbuild.
the class TypesUtils method wildUpperBound.
// Version of com.sun.tools.javac.code.Types.wildUpperBound(Type)
// that works with both jdk8 (called upperBound there) and jdk8u.
// TODO: contrast to upperBound.
public static Type wildUpperBound(ProcessingEnvironment env, TypeMirror tm) {
Type t = (Type) tm;
if (t.hasTag(TypeTag.WILDCARD)) {
Context context = ((JavacProcessingEnvironment) env).getContext();
Type.WildcardType w = (Type.WildcardType) TypeAnnotationUtils.unannotatedType(t);
if (w.isSuperBound()) {
Symtab syms = Symtab.instance(context);
return w.bound == null ? syms.objectType : w.bound.bound;
} else {
return wildUpperBound(env, w.type);
}
} else {
return TypeAnnotationUtils.unannotatedType(t);
}
}
use of com.sun.tools.javac.code.Symtab in project error-prone by google.
the class BoxedPrimitiveConstructor method matchNewClass.
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(tree.getIdentifier());
if (sym == null) {
return NO_MATCH;
}
Types types = state.getTypes();
Symtab symtab = state.getSymtab();
// TODO(cushon): consider handling String also
if (sym.equals(types.boxedClass(symtab.byteType)) || sym.equals(types.boxedClass(symtab.charType)) || sym.equals(types.boxedClass(symtab.shortType)) || sym.equals(types.boxedClass(symtab.intType)) || sym.equals(types.boxedClass(symtab.longType)) || sym.equals(types.boxedClass(symtab.doubleType)) || sym.equals(types.boxedClass(symtab.floatType)) || sym.equals(types.boxedClass(symtab.booleanType))) {
return describeMatch(tree, buildFix(tree, state));
}
return NO_MATCH;
}
Aggregations