use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class RootDocImpl method setClasses.
/**
* Initialize classes information. Those classes are input from
* command line.
*
* @param env the compilation environment
* @param classes a list of ClassDeclaration
*/
private void setClasses(DocEnv env, List<JCClassDecl> classes) {
ListBuffer<ClassDocImpl> result = new ListBuffer<ClassDocImpl>();
for (JCClassDecl def : classes) {
//### Do we want modifier check here?
if (env.shouldDocument(def.sym)) {
ClassDocImpl cd = env.getClassDoc(def.sym);
if (cd != null) {
cd.isIncluded = true;
result.append(cd);
}
//else System.out.println(" (classdoc is null)");//DEBUG
}
//else System.out.println(" (env.shouldDocument() returned false)");//DEBUG
}
cmdLineClasses = result.toList();
}
use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class ClassTransformer method transformAnnotationClassConstructor.
/**
* Generates a constructor for an annotation class which takes the
* annotation type as parameter.
* @param classBuilder
*/
private void transformAnnotationClassConstructor(Tree.AnyClass def, ClassDefinitionBuilder classBuilder) {
Class klass = def.getDeclarationModel();
MethodDefinitionBuilder annoCtor = classBuilder.addConstructor();
annoCtor.ignoreModelAnnotations();
// constructors are never final
annoCtor.modifiers(transformClassDeclFlags(klass) & ~FINAL);
ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.systemParameter(this, "anno");
pdb.type(makeJavaType(klass.getType(), JT_ANNOTATION), null);
annoCtor.parameter(pdb);
// It's up to the caller to invoke value() on the Java annotation for a sequenced
// annotation
ListBuffer<JCExpression> args = ListBuffer.lb();
for (Tree.Parameter parameter : def.getParameterList().getParameters()) {
at(parameter);
Parameter parameterModel = parameter.getParameterModel();
JCExpression annoAttr = make().Apply(null, naming.makeQuotedQualIdent(naming.makeUnquotedIdent("anno"), parameter.getParameterModel().getName()), List.<JCExpression>nil());
Type parameterType = parameterModel.getType();
JCExpression argExpr;
if (typeFact().isIterableType(parameterType) && !isCeylonString(parameterType)) {
// Convert from array to Sequential
Type iteratedType = typeFact().getIteratedType(parameterType);
boolean nonEmpty = typeFact().isNonemptyIterableType(parameterType);
if (isCeylonBasicType(iteratedType)) {
argExpr = utilInvocation().sequentialWrapperBoxed(annoAttr);
} else if (Decl.isAnnotationClass(iteratedType.getDeclaration())) {
// Can't use Util.sequentialAnnotation becase we need to 'box'
// the Java annotations in their Ceylon annotation class
argExpr = make().Apply(null, naming.makeUnquotedIdent(naming.getAnnotationSequenceMethodName()), List.of(annoAttr));
ListBuffer<JCStatement> stmts = ListBuffer.lb();
SyntheticName array = naming.synthetic(Unfix.$array$);
SyntheticName sb = naming.synthetic(Unfix.$sb$);
SyntheticName index = naming.synthetic(Unfix.$index$);
SyntheticName element = naming.synthetic(Unfix.$element$);
stmts.append(makeVar(FINAL, sb, make().TypeArray(make().Type(syms().objectType)), make().NewArray(make().Type(syms().objectType), List.of(naming.makeQualIdent(array.makeIdent(), "length")), null)));
stmts.append(makeVar(index, make().Type(syms().intType), make().Literal(0)));
stmts.append(make().ForeachLoop(makeVar(element, makeJavaType(iteratedType, JT_ANNOTATION), null), array.makeIdent(), make().Exec(make().Assign(make().Indexed(sb.makeIdent(), make().Unary(JCTree.POSTINC, index.makeIdent())), instantiateAnnotationClass(iteratedType, element.makeIdent())))));
stmts.append(make().Return(make().NewClass(null, null, make().QualIdent(syms().ceylonTupleType.tsym), List.of(makeReifiedTypeArgument(iteratedType), sb.makeIdent(), makeEmpty(), make().Literal(false)), null)));
classBuilder.method(MethodDefinitionBuilder.systemMethod(this, naming.getAnnotationSequenceMethodName()).ignoreModelAnnotations().modifiers(PRIVATE | STATIC).resultType(null, makeJavaType(typeFact().getSequentialType(iteratedType))).parameter(ParameterDefinitionBuilder.systemParameter(this, array.getName()).type(make().TypeArray(makeJavaType(iteratedType, JT_ANNOTATION)), null)).body(stmts.toList()));
} else if (isCeylonMetamodelDeclaration(iteratedType)) {
argExpr = makeMetamodelInvocation("parseMetamodelReferences", List.<JCExpression>of(makeReifiedTypeArgument(iteratedType), annoAttr), List.<JCExpression>of(makeJavaType(iteratedType, JT_TYPE_ARGUMENT)));
} else if (Decl.isEnumeratedTypeWithAnonCases(iteratedType)) {
argExpr = makeMetamodelInvocation("parseEnumerationReferences", List.<JCExpression>of(makeReifiedTypeArgument(iteratedType), annoAttr), List.<JCExpression>of(makeJavaType(iteratedType, JT_TYPE_ARGUMENT)));
} else {
argExpr = makeErroneous(parameter, "compiler bug");
}
if (nonEmpty) {
argExpr = make().TypeCast(makeJavaType(parameterType), argExpr);
}
} else if (Decl.isAnnotationClass(parameterType.getDeclaration())) {
argExpr = instantiateAnnotationClass(parameterType, annoAttr);
} else if (isCeylonMetamodelDeclaration(parameterType)) {
argExpr = makeMetamodelInvocation("parseMetamodelReference", List.<JCExpression>of(annoAttr), List.<JCExpression>of(makeJavaType(parameterType, JT_TYPE_ARGUMENT)));
} else if (Decl.isEnumeratedTypeWithAnonCases(parameterType)) {
argExpr = makeMetamodelInvocation("parseEnumerationReference", List.<JCExpression>of(annoAttr), null);
} else {
argExpr = annoAttr;
argExpr = expressionGen().applyErasureAndBoxing(annoAttr, parameterType.withoutUnderlyingType(), false, BoxingStrategy.UNBOXED, parameterType);
}
args.add(argExpr);
}
annoCtor.body(at(def).Exec(make().Apply(null, naming.makeThis(), args.toList())));
}
use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class JavacPathFileManager method list.
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException {
// validatePackageName(packageName);
nullCheck(packageName);
nullCheck(kinds);
Iterable<? extends Path> paths = getLocation(location);
if (paths == null)
return List.nil();
ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
for (Path path : paths) list(path, packageName, kinds, recurse, results);
return results.toList();
}
use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class JavacPathFileManager method getClassLoader.
@Override
public ClassLoader getClassLoader(Location location) {
nullCheck(location);
Iterable<? extends Path> path = getLocation(location);
if (path == null)
return null;
ListBuffer<URL> lb = new ListBuffer<URL>();
for (Path p : path) {
try {
lb.append(p.toUri().toURL());
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
}
return getClassLoader(lb.toArray(new URL[lb.size()]));
}
use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class ExpressionTransformer method transformLet.
// this one trusts the expected type
private JCExpression transformLet(LetExpression op, Type expectedType) {
ListBuffer<JCStatement> defs = new ListBuffer<JCStatement>();
for (Tree.Statement stmt : op.getLetClause().getVariables()) {
defs.addAll(statementGen().transformVariableOrDestructure(stmt));
}
Tree.Term term = op.getLetClause().getExpression().getTerm();
BoxingStrategy boxingStrategy = CodegenUtil.getBoxingStrategy(term);
JCExpression expr = transformExpression(term, boxingStrategy, expectedType);
at(op);
if (isAnything(op.getTypeModel()) && CodegenUtil.isUnBoxed(term)) {
defs.add(make().Exec(expr));
expr = makeNull();
}
return make().LetExpr(defs.toList(), expr);
}
Aggregations