use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class Attr method attribClass.
/**
* Attribute class definition associated with given class symbol.
* @param c The class symbol whose definition will be attributed.
*/
void attribClass(ClassSymbol c) throws CompletionFailure {
if (c.type.hasTag(ERROR))
return;
// Check for cycles in the inheritance graph, which can arise from
// ill-formed class files.
chk.checkNonCyclic(null, c.type);
Type st = types.supertype(c.type);
if ((c.flags_field & Flags.COMPOUND) == 0) {
// First, attribute superclass.
if (st.hasTag(CLASS))
attribClass((ClassSymbol) st.tsym);
// Next attribute owner, if it is a class.
if (c.owner.kind == TYP && c.owner.type.hasTag(CLASS))
attribClass((ClassSymbol) c.owner);
}
// UNATTRIBUTED.
if ((c.flags_field & UNATTRIBUTED) != 0) {
c.flags_field &= ~UNATTRIBUTED;
// Get environment current at the point of class definition.
Env<AttrContext> env = typeEnvs.get(c);
// The info.lint field in the envs stored in typeEnvs is deliberately uninitialized,
// because the annotations were not available at the time the env was created. Therefore,
// we look up the environment chain for the first enclosing environment for which the
// lint value is set. Typically, this is the parent env, but might be further if there
// are any envs created as a result of TypeParameter nodes.
Env<AttrContext> lintEnv = env;
while (lintEnv.info.lint == null) lintEnv = lintEnv.next;
// Having found the enclosing lint value, we can initialize the lint value for this class
env.info.lint = lintEnv.info.lint.augment(c);
Lint prevLint = chk.setLint(env.info.lint);
JavaFileObject prev = log.useSource(c.sourcefile);
ResultInfo prevReturnRes = env.info.returnResult;
try {
deferredLintHandler.flush(env.tree);
env.info.returnResult = null;
// java.lang.Enum may not be subclassed by a non-enum
if (st.tsym == syms.enumSym && ((c.flags_field & (Flags.ENUM | Flags.COMPOUND)) == 0))
log.error(env.tree.pos(), "enum.no.subclassing");
// Enums may not be extended by source-level classes
if (st.tsym != null && ((st.tsym.flags_field & Flags.ENUM) != 0) && ((c.flags_field & (Flags.ENUM | Flags.COMPOUND)) == 0)) {
log.error(env.tree.pos(), "enum.types.not.extensible");
}
if (isSerializable(c.type)) {
env.info.isSerializable = true;
}
attribClassBody(env, c);
chk.checkDeprecatedAnnotation(env.tree.pos(), c);
chk.checkClassOverrideEqualsAndHashIfNeeded(env.tree.pos(), c);
chk.checkFunctionalInterface((JCClassDecl) env.tree, c);
} finally {
env.info.returnResult = prevReturnRes;
log.useSource(prev);
chk.setLint(prevLint);
}
}
}
use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class Attr method attribStatToTree.
public Env<AttrContext> attribStatToTree(JCTree stmt, Env<AttrContext> env, JCTree tree) {
breakTree = tree;
JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
try {
attribStat(stmt, env);
} catch (BreakAttr b) {
return b.env;
} catch (AssertionError ae) {
if (ae.getCause() instanceof BreakAttr) {
return ((BreakAttr) (ae.getCause())).env;
} else {
throw ae;
}
} finally {
breakTree = null;
log.useSource(prev);
}
return env;
}
use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class ClassReader method fillIn.
/**
* Fill in definition of class `c' from corresponding class or
* source file.
*/
private void fillIn(ClassSymbol c) {
if (completionFailureName == c.fullname) {
throw new CompletionFailure(c, "user-selected completion failure by class name");
}
currentOwner = c;
warnedAttrs.clear();
JavaFileObject classfile = c.classfile;
if (classfile != null) {
JavaFileObject previousClassFile = currentClassFile;
try {
if (filling) {
Assert.error("Filling " + classfile.toUri() + " during " + previousClassFile);
}
currentClassFile = classfile;
if (verbose) {
log.printVerbose("loading", currentClassFile.toString());
}
if (classfile.getKind() == JavaFileObject.Kind.CLASS) {
filling = true;
try {
bp = 0;
buf = readInputStream(buf, classfile.openInputStream());
readClassFile(c);
if (!missingTypeVariables.isEmpty() && !foundTypeVariables.isEmpty()) {
List<Type> missing = missingTypeVariables;
List<Type> found = foundTypeVariables;
missingTypeVariables = List.nil();
foundTypeVariables = List.nil();
filling = false;
ClassType ct = (ClassType) currentOwner.type;
ct.supertype_field = types.subst(ct.supertype_field, missing, found);
ct.interfaces_field = types.subst(ct.interfaces_field, missing, found);
} else if (missingTypeVariables.isEmpty() != foundTypeVariables.isEmpty()) {
Name name = missingTypeVariables.head.tsym.name;
throw badClassFile("undecl.type.var", name);
}
} finally {
missingTypeVariables = List.nil();
foundTypeVariables = List.nil();
filling = false;
}
} else {
if (sourceCompleter != null) {
sourceCompleter.complete(c);
} else {
throw new IllegalStateException("Source completer required to read " + classfile.toUri());
}
}
return;
} catch (IOException ex) {
throw badClassFile("unable.to.access.file", ex.getMessage());
} finally {
currentClassFile = previousClassFile;
}
} else {
JCDiagnostic diag = diagFactory.fragment("class.file.not.found", c.flatname);
throw newCompletionFailure(c, diag);
}
}
use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class Enter method complete.
/**
* Main method: enter one class from a list of toplevel trees and
* place the rest on uncompleted for later processing.
* @param trees The list of trees to be processed.
* @param c The class symbol to be processed.
*/
public void complete(List<JCCompilationUnit> trees, ClassSymbol c) {
annotate.enterStart();
ListBuffer<ClassSymbol> prevUncompleted = uncompleted;
if (memberEnter.completionEnabled)
uncompleted = new ListBuffer<ClassSymbol>();
try {
// enter all classes, and construct uncompleted list
classEnter(trees, null);
// complete all uncompleted classes in memberEnter
if (memberEnter.completionEnabled) {
while (uncompleted.nonEmpty()) {
ClassSymbol clazz = uncompleted.next();
if (c == null || c == clazz || prevUncompleted == null)
clazz.complete();
else
// defer
prevUncompleted.append(clazz);
}
// no classes at all), process their import statements as well.
for (JCCompilationUnit tree : trees) {
if (tree.starImportScope.elems == null) {
JavaFileObject prev = log.useSource(tree.sourcefile);
Env<AttrContext> topEnv = topLevelEnv(tree);
memberEnter.memberEnter(tree, topEnv);
log.useSource(prev);
}
}
}
} finally {
uncompleted = prevUncompleted;
annotate.enterDone();
}
}
use of org.eclipse.ceylon.javax.tools.JavaFileObject in project ceylon by eclipse.
the class SymbolMetadata method complete.
/*
* Replace Placeholders for repeating annotations with their containers
*/
private <T extends Attribute.Compound> void complete(Annotate.AnnotateRepeatedContext<T> ctx) {
Log log = ctx.log;
Env<AttrContext> env = ctx.env;
JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile);
try {
// TODO: can we reduce duplication in the following branches?
if (ctx.isTypeCompound) {
Assert.check(!isTypesEmpty());
if (isTypesEmpty()) {
return;
}
List<Attribute.TypeCompound> result = List.nil();
for (Attribute.TypeCompound a : getTypeAttributes()) {
if (a instanceof Placeholder) {
@SuppressWarnings("unchecked") Placeholder<Attribute.TypeCompound> ph = (Placeholder<Attribute.TypeCompound>) a;
Attribute.TypeCompound replacement = replaceOne(ph, ph.getRepeatedContext());
if (null != replacement) {
result = result.prepend(replacement);
}
} else {
result = result.prepend(a);
}
}
type_attributes = result.reverse();
Assert.check(SymbolMetadata.this.getTypePlaceholders().isEmpty());
} else {
Assert.check(!pendingCompletion());
if (isEmpty()) {
return;
}
List<Attribute.Compound> result = List.nil();
for (Attribute.Compound a : getDeclarationAttributes()) {
if (a instanceof Placeholder) {
@SuppressWarnings("unchecked") Attribute.Compound replacement = replaceOne((Placeholder<T>) a, ctx);
if (null != replacement) {
result = result.prepend(replacement);
}
} else {
result = result.prepend(a);
}
}
attributes = result.reverse();
Assert.check(SymbolMetadata.this.getPlaceholders().isEmpty());
}
} finally {
log.useSource(oldSource);
}
}
Aggregations