use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class AbstractTransformer method makeAtAnnotation.
private JCExpression makeAtAnnotation(Annotation annotation) {
JCExpression valueAttribute = make().Assign(naming.makeUnquotedIdent("value"), make().Literal(annotation.getName()));
List<JCExpression> attributes;
if (!annotation.getPositionalArguments().isEmpty()) {
java.util.List<String> positionalArguments = annotation.getPositionalArguments();
ListBuffer<JCExpression> array = new ListBuffer<JCTree.JCExpression>();
for (String val : positionalArguments) array.add(make().Literal(val));
JCExpression argumentsAttribute = make().Assign(naming.makeUnquotedIdent("arguments"), make().NewArray(null, null, array.toList()));
attributes = List.of(valueAttribute, argumentsAttribute);
} else if (!annotation.getNamedArguments().isEmpty()) {
Map<String, String> namedArguments = annotation.getNamedArguments();
ListBuffer<JCExpression> array = new ListBuffer<JCTree.JCExpression>();
for (Entry<String, String> entry : namedArguments.entrySet()) {
JCExpression argNameAttribute = make().Assign(naming.makeUnquotedIdent("name"), make().Literal(entry.getKey()));
JCExpression argValueAttribute = make().Assign(naming.makeUnquotedIdent("value"), make().Literal(entry.getValue()));
JCAnnotation namedArg = make().Annotation(makeIdent(syms().ceylonAtNamedArgumentType), List.of(argNameAttribute, argValueAttribute));
array.add(namedArg);
}
JCExpression argumentsAttribute = make().Assign(naming.makeUnquotedIdent("namedArguments"), make().NewArray(null, null, array.toList()));
attributes = List.of(valueAttribute, argumentsAttribute);
} else
attributes = List.of(valueAttribute);
return make().Annotation(makeIdent(syms().ceylonAtAnnotationType), attributes);
}
use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class AbstractTransformer method makeAtModule.
List<JCAnnotation> makeAtModule(ModuleDescriptor moduleDescriptor) {
Module module = moduleDescriptor.getUnit().getPackage().getModule();
ListBuffer<JCExpression> imports = new ListBuffer<JCTree.JCExpression>();
for (ModuleImport dependency : module.getImports()) {
if (!isForBackend(dependency.getNativeBackends(), Backend.Java)) {
continue;
}
Module dependencyModule = dependency.getModule();
JCExpression dependencyName = make().Assign(naming.makeUnquotedIdent("name"), make().Literal(dependencyModule.getNameAsString()));
JCExpression dependencyVersion = null;
String versionInDescriptor = getImportVersionFromDescriptor(moduleDescriptor, dependency, dependencyModule);
if (versionInDescriptor != null)
dependencyVersion = make().Assign(naming.makeUnquotedIdent("version"), make().Literal(versionInDescriptor));
List<JCExpression> spec;
if (dependencyVersion != null)
spec = List.<JCExpression>of(dependencyName, dependencyVersion);
else
spec = List.<JCExpression>of(dependencyName);
if (Util.getAnnotation(dependency, "shared") != null) {
JCExpression exported = make().Assign(naming.makeUnquotedIdent("export"), make().Literal(true));
spec = spec.append(exported);
}
if (Util.getAnnotation(dependency, "optional") != null) {
JCExpression exported = make().Assign(naming.makeUnquotedIdent("optional"), make().Literal(true));
spec = spec.append(exported);
}
JCExpression nativeBackendsAnnotationValue = makeNativeBackendsAnnotationValue(dependency.getNativeBackends());
if (nativeBackendsAnnotationValue != null)
spec = spec.append(nativeBackendsAnnotationValue);
JCAnnotation atImport = make().Annotation(makeIdent(syms().ceylonAtImportType), spec);
imports.add(atImport);
}
ListBuffer<JCExpression> annotationArgs = getLicenseAuthorsDocAnnotationArguments(module.getNameAsString(), module.getAnnotations());
annotationArgs.add(make().Assign(naming.makeUnquotedIdent("version"), make().Literal(module.getVersion())));
annotationArgs.add(make().Assign(naming.makeUnquotedIdent("dependencies"), make().NewArray(null, null, imports.toList())));
JCExpression nativeBackendsAnnotationValue = makeNativeBackendsAnnotationValue(module.getNativeBackends());
if (nativeBackendsAnnotationValue != null)
annotationArgs.add(nativeBackendsAnnotationValue);
return makeModelAnnotation(syms().ceylonAtModuleType, annotationArgs.toList());
}
use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class CeyloncFileManager method list.
public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
Iterable<JavaFileObject> result = super.list(location, packageName, kinds, recurse);
ListBuffer<JavaFileObject> buf = new ListBuffer<JavaFileObject>();
for (JavaFileObject f : result) {
if (f.getName().endsWith(".ceylon")) {
buf.add(new CeylonFileObject(f));
} else {
buf.add(f);
}
}
return buf.toList();
}
use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class Start method parseAndExecute.
/**
* Main program - internal
*/
private boolean parseAndExecute(String... argv) throws IOException {
long tm = System.currentTimeMillis();
ListBuffer<String> javaNames = new ListBuffer<String>();
// Preprocess @file arguments
try {
argv = CommandLine.parse(argv);
} catch (FileNotFoundException e) {
messager.error(null, "main.cant.read", e.getMessage());
exit();
} catch (IOException e) {
e.printStackTrace();
exit();
}
setDocletInvoker(argv);
ListBuffer<String> subPackages = new ListBuffer<String>();
ListBuffer<String> excludedPackages = new ListBuffer<String>();
Context context = new Context();
// Setup a new Messager, using the same initial parameters as the
// existing Messager, except that this one will be able to use any
// options that may be set up below.
Messager.preRegister(context, messager.programName, messager.errWriter, messager.warnWriter, messager.noticeWriter);
Options compOpts = Options.instance(context);
boolean docClasses = false;
// Parse arguments
for (int i = 0; i < argv.length; i++) {
String arg = argv[i];
if (arg.equals("-subpackages")) {
oneArg(argv, i++);
addToList(subPackages, argv[i]);
} else if (arg.equals("-exclude")) {
oneArg(argv, i++);
addToList(excludedPackages, argv[i]);
} else if (arg.equals("-verbose")) {
setOption(arg);
compOpts.put("-verbose", "");
} else if (arg.equals("-encoding")) {
oneArg(argv, i++);
encoding = argv[i];
compOpts.put("-encoding", argv[i]);
} else if (arg.equals("-breakiterator")) {
breakiterator = true;
setOption("-breakiterator");
} else if (arg.equals("-quiet")) {
quiet = true;
setOption("-quiet");
} else if (arg.equals("-help")) {
usage();
exit();
} else if (arg.equals("-Xclasses")) {
setOption(arg);
docClasses = true;
} else if (arg.equals("-Xwerror")) {
setOption(arg);
rejectWarnings = true;
} else if (arg.equals("-private")) {
setOption(arg);
setFilter(ModifierFilter.ALL_ACCESS);
} else if (arg.equals("-package")) {
setOption(arg);
setFilter(PUBLIC | PROTECTED | ModifierFilter.PACKAGE);
} else if (arg.equals("-protected")) {
setOption(arg);
setFilter(PUBLIC | PROTECTED);
} else if (arg.equals("-public")) {
setOption(arg);
setFilter(PUBLIC);
} else if (arg.equals("-source")) {
oneArg(argv, i++);
if (compOpts.get("-source") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-source", argv[i]);
} else if (arg.equals("-prompt")) {
compOpts.put("-prompt", "-prompt");
messager.promptOnError = true;
} else if (arg.equals("-sourcepath")) {
oneArg(argv, i++);
if (compOpts.get("-sourcepath") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-sourcepath", argv[i]);
} else if (arg.equals("-classpath")) {
oneArg(argv, i++);
if (compOpts.get("-classpath") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-classpath", argv[i]);
} else if (arg.equals("-sysclasspath")) {
oneArg(argv, i++);
if (compOpts.get("-bootclasspath") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-bootclasspath", argv[i]);
} else if (arg.equals("-bootclasspath")) {
oneArg(argv, i++);
if (compOpts.get("-bootclasspath") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-bootclasspath", argv[i]);
} else if (arg.equals("-extdirs")) {
oneArg(argv, i++);
if (compOpts.get("-extdirs") != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put("-extdirs", argv[i]);
} else if (arg.equals("-overview")) {
oneArg(argv, i++);
} else if (arg.equals("-doclet")) {
// handled in setDocletInvoker
i++;
} else if (arg.equals("-docletpath")) {
// handled in setDocletInvoker
i++;
} else if (arg.equals("-locale")) {
if (i != 0)
usageError("main.locale_first");
oneArg(argv, i++);
docLocale = argv[i];
} else if (arg.equals("-Xmaxerrs") || arg.equals("-Xmaxwarns")) {
oneArg(argv, i++);
if (compOpts.get(arg) != null) {
usageError("main.option.already.seen", arg);
}
compOpts.put(arg, argv[i]);
} else if (arg.equals("-X")) {
Xusage();
exit();
} else if (arg.startsWith("-XD")) {
String s = arg.substring("-XD".length());
int eq = s.indexOf('=');
String key = (eq < 0) ? s : s.substring(0, eq);
String value = (eq < 0) ? s : s.substring(eq + 1);
compOpts.put(key, value);
} else // other arg starts with - is invalid
if (arg.startsWith("-")) {
int optionLength;
optionLength = docletInvoker.optionLength(arg);
if (optionLength < 0) {
// error already displayed
exit();
} else if (optionLength == 0) {
// option not found
usageError("main.invalid_flag", arg);
} else {
// doclet added option
if ((i + optionLength) > argv.length) {
usageError("main.requires_argument", arg);
}
ListBuffer<String> args = new ListBuffer<String>();
for (int j = 0; j < optionLength - 1; ++j) {
args.append(argv[++i]);
}
setOption(arg, args.toList());
}
} else {
javaNames.append(arg);
}
}
if (javaNames.isEmpty() && subPackages.isEmpty()) {
usageError("main.No_packages_or_classes_specified");
}
if (!docletInvoker.validOptions(options.toList())) {
// error message already displayed
exit();
}
JavadocTool comp = JavadocTool.make0(context);
if (comp == null)
return false;
if (showAccess == null) {
setFilter(defaultFilter);
}
LanguageVersion languageVersion = docletInvoker.languageVersion();
RootDocImpl root = comp.getRootDocImpl(docLocale, encoding, showAccess, javaNames.toList(), options.toList(), breakiterator, subPackages.toList(), excludedPackages.toList(), docClasses, // legacy?
languageVersion == null || languageVersion == LanguageVersion.JAVA_1_1, quiet);
// pass off control to the doclet
boolean ok = root != null;
if (ok)
ok = docletInvoker.start(root);
Messager docletMessager = Messager.instance0(context);
messager.nwarnings += docletMessager.nwarnings;
messager.nerrors += docletMessager.nerrors;
// We're done.
if (compOpts.get("-verbose") != null) {
tm = System.currentTimeMillis() - tm;
messager.notice("main.done_in", Long.toString(tm));
}
return ok;
}
use of com.sun.tools.javac.util.ListBuffer in project ceylon-compiler by ceylon.
the class ClassDocImpl method importedClasses.
/**
* Get the list of classes declared as imported.
* These are called "single-type-import declarations" in the JLS.
* This method is deprecated in the ClassDoc interface.
*
* @return an array of ClassDocImpl representing the imported classes.
*
* @deprecated Import declarations are implementation details that
* should not be exposed here. In addition, not all imported
* classes are imported through single-type-import declarations.
*/
@Deprecated
public ClassDoc[] importedClasses() {
// information is not available for binary classfiles
if (tsym.sourcefile == null)
return new ClassDoc[0];
ListBuffer<ClassDocImpl> importedClasses = new ListBuffer<ClassDocImpl>();
Env<AttrContext> compenv = env.enter.getEnv(tsym);
if (compenv == null)
return new ClassDocImpl[0];
Name asterisk = tsym.name.table.names.asterisk;
for (JCTree t : compenv.toplevel.defs) {
if (t.getTag() == JCTree.IMPORT) {
JCTree imp = ((JCImport) t).qualid;
if ((TreeInfo.name(imp) != asterisk) && (imp.type.tsym.kind & Kinds.TYP) != 0) {
importedClasses.append(env.getClassDoc((ClassSymbol) imp.type.tsym));
}
}
}
return importedClasses.toArray(new ClassDocImpl[importedClasses.length()]);
}
Aggregations