use of com.sun.tools.javac.util.Pair in project bazel by bazelbuild.
the class TypeAnnotationUtils method createCompoundFromAnnotationMirror.
/**
* Returns a newly created Attribute.Compound corresponding to an
* argument AnnotationMirror.
*
* @param am an AnnotationMirror, which may be part of an AST or an internally
* created subclass.
* @return a new Attribute.Compound corresponding to the AnnotationMirror
*/
public static Attribute.Compound createCompoundFromAnnotationMirror(ProcessingEnvironment env, AnnotationMirror am) {
// Create a new Attribute to match the AnnotationMirror.
List<Pair<Symbol.MethodSymbol, Attribute>> values = List.nil();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
Attribute attribute = attributeFromAnnotationValue(env, entry.getKey(), entry.getValue());
values = values.append(new Pair<>((Symbol.MethodSymbol) entry.getKey(), attribute));
}
return new Attribute.Compound((Type.ClassType) am.getAnnotationType(), values);
}
use of com.sun.tools.javac.util.Pair in project ceylon-compiler by ceylon.
the class Attr method getSyntheticScopeMapping.
/** Creates a synthetic scope containing fake generic constructors.
* Assuming that the original scope contains a constructor of the kind:
* Foo(X x, Y y), where X,Y are class type-variables declared in Foo,
* the synthetic scope is added a generic constructor of the kind:
* <X,Y>Foo<X,Y>(X x, Y y). This is crucial in order to enable diamond
* inference. The inferred return type of the synthetic constructor IS
* the inferred type for the diamond operator.
*/
private Pair<Scope, Scope> getSyntheticScopeMapping(Type ctype) {
if (ctype.tag != CLASS) {
return erroneousMapping;
}
Pair<Scope, Scope> mapping = new Pair<Scope, Scope>(ctype.tsym.members(), new Scope(ctype.tsym));
//declared, and insert it into the new scope.
for (Scope.Entry e = mapping.fst.lookup(names.init); e.scope != null; e = e.next()) {
Type synthRestype = new ClassType(ctype.getEnclosingType(), ctype.tsym.type.getTypeArguments(), ctype.tsym);
MethodSymbol synhConstr = new MethodSymbol(e.sym.flags(), names.init, types.createMethodTypeWithReturn(e.sym.type, synthRestype), e.sym.owner);
mapping.snd.enter(synhConstr);
}
return mapping;
}
use of com.sun.tools.javac.util.Pair in project ceylon-compiler by ceylon.
the class CheckAttributedTree method read.
/**
* Read a file.
* @param file the file to be read
* @return the tree for the content of the file
* @throws IOException if any IO errors occur
* @throws TreePosTest.ParseException if any errors occur while parsing the file
*/
List<Pair<JCCompilationUnit, JCTree>> read(File file) throws IOException, AttributionException {
JavacTool tool = JavacTool.create();
r.errors = 0;
Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(file);
String[] opts = { "-XDshouldStopPolicy=ATTR", "-XDverboseCompilePolicy" };
JavacTask task = tool.getTask(pw, fm, r, Arrays.asList(opts), null, files);
final List<Element> analyzedElems = new ArrayList<>();
task.setTaskListener(new TaskListener() {
public void started(TaskEvent e) {
if (e.getKind() == TaskEvent.Kind.ANALYZE)
analyzedElems.add(e.getTypeElement());
}
public void finished(TaskEvent e) {
}
});
try {
Iterable<? extends CompilationUnitTree> trees = task.parse();
task.analyze();
List<Pair<JCCompilationUnit, JCTree>> res = new ArrayList<>();
//System.out.println("Try to add pairs. Elems are " + analyzedElems);
for (CompilationUnitTree t : trees) {
JCCompilationUnit cu = (JCCompilationUnit) t;
for (JCTree def : cu.defs) {
if (def.getTag() == JCTree.CLASSDEF && analyzedElems.contains(((JCTree.JCClassDecl) def).sym)) {
//System.out.println("Adding pair...");
res.add(new Pair<>(cu, def));
}
}
}
return res;
} catch (Throwable t) {
throw new AttributionException("Exception while attributing file: " + file);
}
}
use of com.sun.tools.javac.util.Pair in project bazel by bazelbuild.
the class TypeAnnotationUtils method createTypeCompoundFromAnnotationMirror.
/**
* Returns a newly created Attribute.TypeCompound corresponding to an
* argument AnnotationMirror.
*
* @param am an AnnotationMirror, which may be part of an AST or an internally
* created subclass.
* @param tapos the type annotation position to use.
* @return a new Attribute.TypeCompound corresponding to the AnnotationMirror
*/
public static Attribute.TypeCompound createTypeCompoundFromAnnotationMirror(ProcessingEnvironment env, AnnotationMirror am, TypeAnnotationPosition tapos) {
// Create a new Attribute to match the AnnotationMirror.
List<Pair<Symbol.MethodSymbol, Attribute>> values = List.nil();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
Attribute attribute = attributeFromAnnotationValue(env, entry.getKey(), entry.getValue());
values = values.append(new Pair<>((Symbol.MethodSymbol) entry.getKey(), attribute));
}
return new Attribute.TypeCompound((Type.ClassType) am.getAnnotationType(), values, tapos);
}
Aggregations