本文整理汇总了Java中com.sun.tools.javac.code.Types类的典型用法代码示例。如果您正苦于以下问题:Java Types类的具体用法?Java Types怎么用?Java Types使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Types类属于com.sun.tools.javac.code包,在下文中一共展示了Types类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDataflowVisitMethodInvocation
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
@Override
public Nullness onDataflowVisitMethodInvocation(
MethodInvocationNode node,
Types types,
AccessPathNullnessPropagation.Updates thenUpdates,
AccessPathNullnessPropagation.Updates elseUpdates,
AccessPathNullnessPropagation.Updates bothUpdates) {
Nullness nullness = Nullness.NONNULL;
for (Handler h : handlers) {
Nullness n =
h.onDataflowVisitMethodInvocation(node, types, thenUpdates, elseUpdates, bothUpdates);
// If any handler says this is @Nullable, then it is @Nullable
if (n == Nullness.NULLABLE) {
nullness = Nullness.NULLABLE;
}
}
return nullness;
}
示例2: isMapMethod
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
private static boolean isMapMethod(Symbol.MethodSymbol symbol, Types types, String methodName) {
if (!symbol.getSimpleName().toString().equals(methodName)) {
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;
}
示例3: getClosestOverriddenMethod
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
/**
* find the closest ancestor method in a superclass or superinterface that method overrides
*
* @param method the subclass method
* @param types the types data structure from javac
* @return closest overridden ancestor method, or <code>null</code> if method does not override
* anything
*/
@Nullable
private Symbol.MethodSymbol getClosestOverriddenMethod(Symbol.MethodSymbol method, Types types) {
// taken from Error Prone MethodOverrides check
Symbol.ClassSymbol owner = method.enclClass();
for (Type s : types.closure(owner.type)) {
if (s.equals(owner.type)) {
continue;
}
for (Symbol m : s.tsym.members().getSymbolsByName(method.name)) {
if (!(m instanceof Symbol.MethodSymbol)) {
continue;
}
Symbol.MethodSymbol msym = (Symbol.MethodSymbol) m;
if (msym.isStatic()) {
continue;
}
if (method.overrides(msym, owner, types, /*checkReturn*/ false)) {
return msym;
}
}
}
return null;
}
示例4: findSuperConstructorInType
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
/**
* based heavily on {@link ASTHelpers#findSuperMethodInType(Symbol.MethodSymbol, Type, Types)},
* but works for constructors
*/
@Nullable
private static Symbol.MethodSymbol findSuperConstructorInType(
Symbol.MethodSymbol methodSymbol, Type superType, Types types) {
Preconditions.checkArgument(methodSymbol.isConstructor(), "only accepts constructor methods");
Scope scope = superType.tsym.members();
for (Symbol sym : scope.getSymbolsByName(methodSymbol.name)) {
if (sym != null
&& sym.isConstructor()
&& ((sym.flags() & Flags.SYNTHETIC) == 0)
&& hasSameArgTypes((Symbol.MethodSymbol) sym, methodSymbol, types)) {
return (Symbol.MethodSymbol) sym;
}
}
return null;
}
示例5: Enter
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
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);
}
示例6: LambdaToMethod
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
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");
}
示例7: put
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
/** 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();
}
示例8: init
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
private void init(Context context) {
modules = Modules.instance(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);
docTreeMaker = DocTreeMaker.instance(context);
parser = ParserFactory.instance(context);
syms = Symtab.instance(context);
fileManager = context.get(JavaFileManager.class);
JavacTask t = context.get(JavacTask.class);
if (t instanceof JavacTaskImpl)
javacTaskImpl = (JavacTaskImpl) t;
}
示例9: Analyzer
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
protected Analyzer(Context context) {
context.put(analyzerKey, this);
types = Types.instance(context);
log = Log.instance(context);
attr = Attr.instance(context);
deferredAttr = DeferredAttr.instance(context);
argumentAttr = ArgumentAttr.instance(context);
make = TreeMaker.instance(context);
names = Names.instance(context);
Options options = Options.instance(context);
String findOpt = options.get("find");
//parse modes
Source source = Source.instance(context);
allowDiamondWithAnonymousClassCreation = source.allowDiamondWithAnonymousClassCreation();
analyzerModes = AnalyzerMode.getAnalyzerModes(findOpt, source);
}
示例10: LambdaToMethod
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
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);
operators = Operators.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("debug.dumpLambdaToMethodStats");
attr = Attr.instance(context);
forceSerializable = options.isSet("forceSerializable");
}
示例11: run
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
public void run(JavaCompiler comp) {
JavaSource source = new JavaSource();
JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, null, dc,
Arrays.asList("-g"), null, Arrays.asList(source));
Context context = ct.getContext();
Symtab syms = Symtab.instance(context);
Names names = Names.instance(context);
Types types = Types.instance(context);
ct.addTaskListener(new Indifier(syms, names, types));
try {
ct.generate();
} catch (Throwable t) {
t.printStackTrace();
throw new AssertionError(
String.format("Error thrown when compiling following code\n%s",
source.source));
}
if (dc.diagFound) {
throw new AssertionError(
String.format("Diags found when compiling following code\n%s\n\n%s",
source.source, dc.printDiags()));
}
verifyBytecode();
}
示例12: getValue
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
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();
}
}
示例13: run
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
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");
}
示例14: clear
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
void clear() {
drop(Arguments.argsKey);
drop(DiagnosticListener.class);
drop(Log.outKey);
drop(Log.errKey);
drop(JavaFileManager.class);
drop(JavacTask.class);
if (ht.get(Log.logKey) instanceof ReusableLog) {
//log already inited - not first round
((ReusableLog)Log.instance(this)).clear();
Enter.instance(this).newRound();
((ReusableJavaCompiler)ReusableJavaCompiler.instance(this)).clear();
Types.instance(this).newRound();
Check.instance(this).newRound();
Modules.instance(this).newRound();
Annotate.instance(this).newRound();
CompileStates.instance(this).clear();
MultiTaskListener.instance(this).clear();
//find if any of the roots have redefined java.* classes
Symtab syms = Symtab.instance(this);
pollutionScanner.scan(roots, syms);
roots.clear();
}
}
示例15: CompiledTypeProcessor
import com.sun.tools.javac.code.Types; //导入依赖的package包/类
CompiledTypeProcessor( JavacTask javacTask )
{
_javacTask = javacTask;
javacTask.addTaskListener( this );
Context context = ((BasicJavacTask)javacTask).getContext();
JavaCompiler compiler = JavaCompiler.instance( context );
compiler.shouldStopPolicyIfNoError = CompileState.max( compiler.shouldStopPolicyIfNoError, CompileState.FLOW );
_issueReporter = new IssueReporter<>( Log.instance( context ) );
_types = Types.instance( context );
// DiagnosticListener dl = context.get( DiagnosticListener.class );
// context.put( DiagnosticListener.class, (DiagnosticListener)null );
// context.put( DiagnosticListener.class, new WrappedDiagnosticListener( dl ) );
_typesToProcess = new HashMap<>();
_innerClassForGeneration = new HashMap<>();
}