use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.
the class JavacParser method parseCompilationUnit.
/**
* CompilationUnit = [ { "@" Annotation } PACKAGE Qualident ";"] {ImportDeclaration} {TypeDeclaration}
*/
public JCTree.JCCompilationUnit parseCompilationUnit() {
Token firstToken = token;
JCExpression pid = null;
JCModifiers mods = null;
boolean consumedToplevelDoc = false;
boolean seenImport = false;
boolean seenPackage = false;
List<JCAnnotation> packageAnnotations = List.nil();
if (token.kind == MONKEYS_AT)
mods = modifiersOpt();
if (token.kind == PACKAGE) {
seenPackage = true;
if (mods != null) {
checkNoMods(mods.flags);
packageAnnotations = mods.annotations;
mods = null;
}
nextToken();
pid = qualident(false);
accept(SEMI);
}
ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
boolean checkForImports = true;
boolean firstTypeDecl = true;
while (token.kind != EOF) {
if (token.pos > 0 && token.pos <= endPosTable.errorEndPos) {
// error recovery
skip(checkForImports, false, false, false);
if (token.kind == EOF)
break;
}
if (checkForImports && mods == null && token.kind == IMPORT) {
seenImport = true;
defs.append(importDeclaration());
} else {
Comment docComment = token.comment(CommentStyle.JAVADOC);
if (firstTypeDecl && !seenImport && !seenPackage) {
docComment = firstToken.comment(CommentStyle.JAVADOC);
consumedToplevelDoc = true;
}
JCTree def = typeDeclaration(mods, docComment);
if (def instanceof JCExpressionStatement)
def = ((JCExpressionStatement) def).expr;
defs.append(def);
if (def instanceof JCClassDecl)
checkForImports = false;
mods = null;
firstTypeDecl = false;
}
}
JCTree.JCCompilationUnit toplevel = F.at(firstToken.pos).TopLevel(packageAnnotations, pid, defs.toList());
if (!consumedToplevelDoc)
attach(toplevel, firstToken.comment(CommentStyle.JAVADOC));
if (defs.isEmpty())
storeEnd(toplevel, S.prevToken().endPos);
if (keepLineMap)
toplevel.lineMap = S.getLineMap();
// remove reference to parser
this.endPosTable.setParser(null);
toplevel.endPositions = this.endPosTable;
return toplevel;
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.
the class JCTypeResetter method visitMethodDef.
@Override
public void visitMethodDef(JCMethodDecl that) {
super.visitMethodDef(that);
that.sym = null;
// do arguments
for (JCTree param : that.params) {
param.accept(this);
}
// return type
if (that.restype != null)
that.restype.accept(this);
// type params
for (JCTree tyParam : that.typarams) {
tyParam.accept(this);
}
that.mods.accept(this);
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.
the class JCTypeResetter method visitTypeApply.
@Override
public void visitTypeApply(JCTypeApply that) {
super.visitTypeApply(that);
that.clazz.accept(this);
for (JCTree arg : that.arguments) {
arg.accept(this);
}
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.
the class JCTypeResetter method visitClassDef.
@Override
public void visitClassDef(JCClassDecl that) {
super.visitClassDef(that);
that.sym = null;
// reset this type
if (that.extending != null)
that.extending.accept(this);
for (JCTree impl : that.implementing) {
impl.accept(this);
}
for (JCTree tyParam : that.typarams) {
tyParam.accept(this);
}
// do the class body
for (JCTree def : that.defs) {
def.accept(this);
}
that.mods.accept(this);
}
use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.
the class JCTypeResetter method visitTopLevel.
@Override
public void visitTopLevel(JCCompilationUnit that) {
super.visitTopLevel(that);
// do all toplevels
for (JCTree tree : that.defs) tree.accept(this);
that.namedImportScope = null;
that.starImportScope = null;
that.packge = null;
}
Aggregations