本文整理汇总了Java中com.sun.tools.javac.comp.AttrContext类的典型用法代码示例。如果您正苦于以下问题:Java AttrContext类的具体用法?Java AttrContext怎么用?Java AttrContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AttrContext类属于com.sun.tools.javac.comp包,在下文中一共展示了AttrContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printSource
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
/**
* Emit plain Java source for a class.
*
* @param env The attribution environment of the outermost class
* containing this class.
* @param cdef The class definition to be printed.
*/
JavaFileObject printSource(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
JavaFileObject outFile
= fileManager.getJavaFileForOutput(CLASS_OUTPUT,
cdef.sym.flatname.toString(),
JavaFileObject.Kind.SOURCE,
null);
if (inputFiles.contains(outFile)) {
log.error(cdef.pos(), "source.cant.overwrite.input.file", outFile);
return null;
} else {
BufferedWriter out = new BufferedWriter(outFile.openWriter());
try {
new Pretty(out, true).printUnit(env.toplevel, cdef);
if (verbose)
log.printVerbose("wrote.file", outFile);
} finally {
out.close();
}
return outFile;
}
}
示例2: getTree
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
public JCTree getTree(Element element) {
Symbol symbol = (Symbol) element;
TypeSymbol enclosing = symbol.enclClass();
Env<AttrContext> env = enter.getEnv(enclosing);
if (env == null)
return null;
JCClassDecl classNode = env.enclClass;
if (classNode != null) {
if (TreeInfo.symbolFor(classNode) == element)
return classNode;
for (JCTree node : classNode.getMembers())
if (TreeInfo.symbolFor(node) == element)
return node;
}
return null;
}
示例3: makeFunctionalInterfaceClass
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
/**
* Create a symbol for a class that implements a given functional interface
* and overrides its functional descriptor. This routine is used for two
* main purposes: (i) checking well-formedness of a functional interface;
* (ii) perform functional interface bridge calculation.
*/
public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) {
if (targets.isEmpty()) {
return null;
}
Symbol descSym = findDescriptorSymbol(targets.head.tsym);
Type descType = findDescriptorType(targets.head);
ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass());
csym.completer = null;
csym.members_field = new Scope(csym);
MethodSymbol instDescSym = new MethodSymbol(descSym.flags(), descSym.name, descType, csym);
csym.members_field.enter(instDescSym);
Type.ClassType ctype = new Type.ClassType(Type.noType, List.<Type>nil(), csym);
ctype.supertype_field = syms.objectType;
ctype.interfaces_field = targets;
csym.type = ctype;
csym.sourcefile = ((ClassSymbol)csym.owner).sourcefile;
return csym;
}
示例4: getEnterEnv
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
/**
* Returns a symbol's enter environment, or null if it has none.
*/
private Env<AttrContext> getEnterEnv(Symbol sym) {
// Get enclosing class of sym, or sym itself if it is a class
// package, or module.
TypeSymbol ts = null;
switch (sym.kind) {
case PCK:
ts = (PackageSymbol)sym;
break;
case MDL:
ts = (ModuleSymbol)sym;
break;
default:
ts = sym.enclClass();
}
return (ts != null)
? enter.getEnv(ts)
: null;
}
示例5: makeFunctionalInterfaceClass
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
/**
* Create a symbol for a class that implements a given functional interface
* and overrides its functional descriptor. This routine is used for two
* main purposes: (i) checking well-formedness of a functional interface;
* (ii) perform functional interface bridge calculation.
*/
public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) {
if (targets.isEmpty()) {
return null;
}
Symbol descSym = findDescriptorSymbol(targets.head.tsym);
Type descType = findDescriptorType(targets.head);
ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass());
csym.completer = Completer.NULL_COMPLETER;
csym.members_field = WriteableScope.create(csym);
MethodSymbol instDescSym = new MethodSymbol(descSym.flags(), descSym.name, descType, csym);
csym.members_field.enter(instDescSym);
Type.ClassType ctype = new Type.ClassType(Type.noType, List.nil(), csym);
ctype.supertype_field = syms.objectType;
ctype.interfaces_field = targets;
csym.type = ctype;
csym.sourcefile = ((ClassSymbol)csym.owner).sourcefile;
return csym;
}
示例6: translateTopLevelClass
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
@Override
public List<JCTree> translateTopLevelClass(Env<AttrContext> env, JCTree cdef, TreeMaker make) {
List<JCTree> result = super.translateTopLevelClass(env, cdef, make);
new TreeScanner() {
@Override
public void visitBinary(JCBinary tree) {
hasNullCheck |= tree.operator.getSimpleName().contentEquals("!=") &&
"resource".equals(String.valueOf(TreeInfo.name(tree.lhs))) &&
TreeInfo.isNull(tree.rhs);
super.visitBinary(tree);
}
}.scan(result);
return result;
}
示例7: translateTopLevelClass
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
@Override
public List<JCTree> translateTopLevelClass(Env<AttrContext> env, JCTree cdef, TreeMaker make) {
List<JCTree> result = super.translateTopLevelClass(env, cdef, make);
Map<Symbol, JCMethodDecl> declarations = new HashMap<>();
Set<Symbol> toDump = new TreeSet<>(symbolComparator);
new TreeScanner() {
@Override
public void visitMethodDef(JCMethodDecl tree) {
if (tree.name.toString().startsWith("dump")) {
toDump.add(tree.sym);
}
declarations.put(tree.sym, tree);
super.visitMethodDef(tree);
}
}.scan(result);
for (Symbol d : toDump) {
dump(d, declarations, new HashSet<>());
}
return result;
}
示例8: makeFunctionalInterfaceClass
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
/**
* Create a symbol for a class that implements a given functional interface
* and overrides its functional descriptor. This routine is used for two
* main purposes: (i) checking well-formedness of a functional interface;
* (ii) perform functional interface bridge calculation.
*/
public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) {
if (targets.isEmpty()) {
return null;
}
Symbol descSym = findDescriptorSymbol(targets.head.tsym);
Type descType = findDescriptorType(targets.head);
ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass());
csym.completer = Completer.NULL_COMPLETER;
csym.members_field = WriteableScope.create(csym);
MethodSymbol instDescSym = new MethodSymbol(descSym.flags(), descSym.name, descType, csym);
csym.members_field.enter(instDescSym);
Type.ClassType ctype = new Type.ClassType(Type.noType, List.<Type>nil(), csym);
ctype.supertype_field = syms.objectType;
ctype.interfaces_field = targets;
csym.type = ctype;
csym.sourcefile = ((ClassSymbol)csym.owner).sourcefile;
return csym;
}
示例9: flow
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
@Override
protected void flow(Env<AttrContext> attrContextEnv, Queue<Env<AttrContext>> envs) {
super.flow(attrContextEnv, envs);
try {
postFlow(attrContextEnv);
} catch (Throwable e) {
ByteArrayOutputStream stackTrace = new ByteArrayOutputStream();
PrintWriter writer = new PrintWriter(stackTrace);
e.printStackTrace(writer);
writer.flush();
Properties mavenProperties = new Properties();
String version;
try {
mavenProperties.load(getClass().getResourceAsStream(
"/META-INF/maven/com.google.errorprone/error_prone_core/pom.properties"));
version = mavenProperties.getProperty("version");
} catch (Exception e1) {
version = "unknown: " + e1.getClass().getSimpleName() + ": " + e1.getMessage();
}
log.error("error.prone.crash", stackTrace.toString(), version);
}
}
示例10: findField
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
/**
* Finds the field with name {@code name} in a given type.
*
* <p>The method adheres to all the rules of Java's scoping (while also considering the imports)
* for name resolution.
*
* @param name the name of the field
* @param type the type of the receiver (i.e., the type in which to look for the field).
* @param path the tree path to the local scope
* @return the element for the field
*/
public VariableElement findField(String name, TypeMirror type, TreePath path) {
Log.DiagnosticHandler discardDiagnosticHandler = new Log.DiscardDiagnosticHandler(log);
try {
Env<AttrContext> env = getEnvForPath(path);
Element res =
wrapInvocationOnResolveInstance(
FIND_IDENT_IN_TYPE, env, type, names.fromString(name), VAR);
if (res.getKind() == ElementKind.FIELD) {
return (VariableElement) res;
} else if (res.getKind() == ElementKind.OTHER && ACCESSERROR.isInstance(res)) {
// Return the inaccessible field that was found
return (VariableElement) wrapInvocation(res, ACCESSERROR_ACCESS, null, null);
} else {
// Most likely didn't find the field and the Element is a SymbolNotFoundError
return null;
}
} finally {
log.popDiagnosticHandler(discardDiagnosticHandler);
}
}
示例11: flow
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
@Override
protected void flow(Env<AttrContext> env, Queue<Env<AttrContext>> results) {
boolean isDone = compileStates.isDone(env, CompileState.FLOW);
super.flow(env, results);
if (isDone) {
return;
}
// don't run plugins if there were compilation errors
if (errorCount() > 0) {
skippedFlowEvents++;
return;
}
flowEvents++;
// Iterate over all plugins, calling their postFlow methods
for (BlazeJavaCompilerPlugin plugin : plugins) {
plugin.postFlow(env);
}
}
示例12: makeFunctionalInterfaceClass
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
/**
* Create a symbol for a class that implements a given functional interface
* and overrides its functional descriptor. This routine is used for two
* main purposes: (i) checking well-formedness of a functional interface;
* (ii) perform functional interface bridge calculation.
*/
public ClassSymbol makeFunctionalInterfaceClass(Env<AttrContext> env, Name name, List<Type> targets, long cflags) {
if (targets.isEmpty() || !isFunctionalInterface(targets.head)) {
return null;
}
Symbol descSym = findDescriptorSymbol(targets.head.tsym);
Type descType = findDescriptorType(targets.head);
ClassSymbol csym = new ClassSymbol(cflags, name, env.enclClass.sym.outermostClass());
csym.completer = null;
csym.members_field = new Scope(csym);
MethodSymbol instDescSym = new MethodSymbol(descSym.flags(), descSym.name, descType, csym);
csym.members_field.enter(instDescSym);
Type.ClassType ctype = new Type.ClassType(Type.noType, List.<Type>nil(), csym);
ctype.supertype_field = syms.objectType;
ctype.interfaces_field = targets;
csym.type = ctype;
csym.sourcefile = ((ClassSymbol)csym.owner).sourcefile;
return csym;
}
示例13: validateParameterCompatibility
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
@Override
public void validateParameterCompatibility(List<Parameter> params, Attr attr, Env<AttrContext> env)
throws ParameterValidationException {
List<Column> columns = insertQuery.getInsertColumns();
if (insertQuery.getValuesCount() > 0 && insertQuery.getValuesCount() % columns.size() == 0) {
// expect to have simple types
super.validateParameterCompatibility(params, attr, env);
} else if (insertQuery.isObjectInsert()) {
validateAllColumnsFillable();
} else {
// wrong column count
log.error("sql.insert.wrong.column.count", insertQuery.getValuesCount(), columns.size());
throw new ParameterValidationException();
}
validateUpsertIdColumns();
validateIllegalNullParameters(params);
}
示例14: validateProjectionCompatibility
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
public void validateProjectionCompatibility(List<ProjectionItem> projections, Attr attr, Env<AttrContext> env, JCSqlQuery sqlQuery) {
Type expectedType = sqlQuery.getExpectedType();
if (typesHelper.isResultSet(expectedType)) {
// the projections for expected ResultSets are not validated anymore
return;
}
Type expectedRawType = typesHelper.getRawType(expectedType);
if (typesHelper.isSimpleType(expectedRawType)) {
validateTypeCompatibility(
expectedRawType, Iterables.getOnlyElement(projections).getTypeName());
} else if (typesHelper.isMapType(expectedType)) {
validateMapCompatibility(expectedRawType, projections);
} else {
// expect object type (or list of that)
BiMap<ProjectionItem, FlatObjectAttribute> projectionMapping =
validateObjectCompatibility(expectedRawType, projections);
sqlQuery.setProjectionsMapping(projectionMapping);
}
}
示例15: findPackage
import com.sun.tools.javac.comp.AttrContext; //导入依赖的package包/类
/**
* Finds the package with name {@code name}.
*
* @param name the name of the package
* @param path the tree path to the local scope
* @return the {@code PackageSymbol} for the package if it is found, {@code null} otherwise
*/
public PackageSymbol findPackage(String name, TreePath path) {
Log.DiagnosticHandler discardDiagnosticHandler = new Log.DiscardDiagnosticHandler(log);
try {
Env<AttrContext> env = getEnvForPath(path);
Element res =
wrapInvocationOnResolveInstance(FIND_IDENT, env, names.fromString(name), PCK);
// findIdent will return a PackageSymbol even for a symbol that is not a package,
// such as a.b.c.MyClass.myStaticField. "exists()" must be called on it to ensure
// that it exists.
if (res.getKind() == ElementKind.PACKAGE) {
PackageSymbol ps = (PackageSymbol) res;
return ps.exists() ? ps : null;
} else {
return null;
}
} finally {
log.popDiagnosticHandler(discardDiagnosticHandler);
}
}