use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Printer method className.
/**
* Converts a class name into a (possibly localized) string. Anonymous
* inner classes get converted into a localized string.
*
* @param t the type of the class whose name is to be rendered
* @param longform if set, the class' fullname is displayed - if unset the
* short name is chosen (w/o package)
* @param locale the locale in which the string is to be rendered
* @return localized string representation
*/
protected String className(ClassType t, boolean longform, Locale locale) {
Symbol sym = t.tsym;
if (sym.name.length() == 0 && (sym.flags() & COMPOUND) != 0) {
StringBuilder s = new StringBuilder(visit(t.supertype_field, locale));
for (List<Type> is = t.interfaces_field; is.nonEmpty(); is = is.tail) {
s.append('&');
s.append(visit(is.head, locale));
}
return s.toString();
} else if (sym.name.length() == 0) {
String s;
ClassType norm = (ClassType) t.tsym.type;
if (norm == null) {
s = localize(locale, "compiler.misc.anonymous.class", (Object) null);
} else if (norm.interfaces_field != null && norm.interfaces_field.nonEmpty()) {
s = localize(locale, "compiler.misc.anonymous.class", visit(norm.interfaces_field.head, locale));
} else {
s = localize(locale, "compiler.misc.anonymous.class", visit(norm.supertype_field, locale));
}
return s;
} else if (longform) {
return sym.getQualifiedName().toString();
} else {
return sym.name.toString();
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class JavaCompiler method processAnnotations.
/**
* Process any annotations found in the specified compilation units.
* @param roots a list of compilation units
* @return an instance of the compiler in which to complete the compilation
*/
// Implementation note: when this method is called, log.deferredDiagnostics
// will have been set true by initProcessAnnotations, meaning that any diagnostics
// that are reported will go into the log.deferredDiagnostics queue.
// By the time this method exits, log.deferDiagnostics must be set back to false,
// and all deferredDiagnostics must have been handled: i.e. either reported
// or determined to be transient, and therefore suppressed.
public JavaCompiler processAnnotations(List<JCCompilationUnit> roots, List<String> classnames) {
if (shouldStop(CompileState.PROCESS)) {
// any annotation processors.
if (unrecoverableError()) {
deferredDiagnosticHandler.reportDeferredDiagnostics();
log.popDiagnosticHandler(deferredDiagnosticHandler);
return this;
}
}
if (!processAnnotations) {
// emit a warning.
if (options.isSet(PROC, "only")) {
log.warning("proc.proc-only.requested.no.procs");
todo.clear();
}
// If not processing annotations, classnames must be empty
if (!classnames.isEmpty()) {
log.error("proc.no.explicit.annotation.processing.requested", classnames);
}
Assert.checkNull(deferredDiagnosticHandler);
// continue regular compilation
return this;
}
Assert.checkNonNull(deferredDiagnosticHandler);
try {
List<ClassSymbol> classSymbols = List.nil();
List<PackageSymbol> pckSymbols = List.nil();
if (!classnames.isEmpty()) {
// processing
if (!explicitAnnotationProcessingRequested()) {
log.error("proc.no.explicit.annotation.processing.requested", classnames);
deferredDiagnosticHandler.reportDeferredDiagnostics();
log.popDiagnosticHandler(deferredDiagnosticHandler);
// TODO: Will this halt compilation?
return this;
} else {
boolean errors = false;
for (String nameStr : classnames) {
Symbol sym = resolveBinaryNameOrIdent(nameStr);
if (sym == null || (sym.kind == Kinds.PCK && !processPcks) || sym.kind == Kinds.ABSENT_TYP) {
log.error("proc.cant.find.class", nameStr);
errors = true;
continue;
}
try {
if (sym.kind == Kinds.PCK)
sym.complete();
if (sym.exists()) {
if (sym.kind == Kinds.PCK)
pckSymbols = pckSymbols.prepend((PackageSymbol) sym);
else
classSymbols = classSymbols.prepend((ClassSymbol) sym);
continue;
}
Assert.check(sym.kind == Kinds.PCK);
log.warning("proc.package.does.not.exist", nameStr);
pckSymbols = pckSymbols.prepend((PackageSymbol) sym);
} catch (CompletionFailure e) {
log.error("proc.cant.find.class", nameStr);
errors = true;
continue;
}
}
if (errors) {
deferredDiagnosticHandler.reportDeferredDiagnostics();
log.popDiagnosticHandler(deferredDiagnosticHandler);
return this;
}
}
}
try {
JavaCompiler c = procEnvImpl.doProcessing(context, roots, classSymbols, pckSymbols, deferredDiagnosticHandler);
if (c != this)
annotationProcessingOccurred = c.annotationProcessingOccurred = true;
// doProcessing will have handled deferred diagnostics
return c;
} finally {
procEnvImpl.close();
}
} catch (CompletionFailure ex) {
log.error("cant.access", ex.sym, ex.getDetailValue());
deferredDiagnosticHandler.reportDeferredDiagnostics();
log.popDiagnosticHandler(deferredDiagnosticHandler);
return this;
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class FilteredMemberList method iterator.
// A more efficient implementation than AbstractList's.
public Iterator<Symbol> iterator() {
return new Iterator<Symbol>() {
/**
* The next entry to examine, or null if none.
*/
private Scope.Entry nextEntry = scope.elems;
private boolean hasNextForSure = false;
public boolean hasNext() {
if (hasNextForSure) {
return true;
}
while (nextEntry != null && unwanted(nextEntry.sym)) {
nextEntry = nextEntry.sibling;
}
hasNextForSure = (nextEntry != null);
return hasNextForSure;
}
public Symbol next() {
if (hasNext()) {
Symbol result = nextEntry.sym;
nextEntry = nextEntry.sibling;
hasNextForSure = false;
return result;
} else {
throw new NoSuchElementException();
}
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Code method emitop2.
/**
* Emit an opcode with a two-byte operand field.
*/
public void emitop2(int op, int od) {
emitop(op);
if (!alive)
return;
emit2(od);
switch(op) {
case getstatic:
state.push(((Symbol) (pool.pool[od])).erasure(types));
break;
case putstatic:
state.pop(((Symbol) (pool.pool[od])).erasure(types));
break;
case new_:
Symbol sym;
if (pool.pool[od] instanceof UniqueType) {
// Required by change in Gen.makeRef to allow
// annotated types.
// TODO: is this needed anywhere else?
sym = ((UniqueType) (pool.pool[od])).type.tsym;
} else {
sym = (Symbol) (pool.pool[od]);
}
state.push(uninitializedObject(sym.erasure(types), cp - 3));
break;
case sipush:
state.push(syms.intType);
break;
case if_acmp_null:
case if_acmp_nonnull:
case ifeq:
case ifne:
case iflt:
case ifge:
case ifgt:
case ifle:
state.pop(1);
break;
case if_icmpeq:
case if_icmpne:
case if_icmplt:
case if_icmpge:
case if_icmpgt:
case if_icmple:
case if_acmpeq:
case if_acmpne:
state.pop(2);
break;
case goto_:
markDead();
break;
case putfield:
state.pop(((Symbol) (pool.pool[od])).erasure(types));
// object ref
state.pop(1);
break;
case getfield:
// object ref
state.pop(1);
state.push(((Symbol) (pool.pool[od])).erasure(types));
break;
case checkcast:
{
// object ref
state.pop(1);
Object o = pool.pool[od];
Type t = (o instanceof Symbol) ? ((Symbol) o).erasure(types) : types.erasure((((UniqueType) o).type));
state.push(t);
break;
}
case ldc2w:
state.push(typeForPool(pool.pool[od]));
break;
case instanceof_:
state.pop(1);
state.push(syms.intType);
break;
case ldc2:
state.push(typeForPool(pool.pool[od]));
break;
case jsr:
break;
default:
throw new AssertionError(mnem(op));
}
// postop();
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Code method emitInvokespecial.
/**
* Emit an invokespecial instruction.
*/
public void emitInvokespecial(int meth, Type mtype) {
int argsize = width(mtype.getParameterTypes());
emitop(invokespecial);
if (!alive)
return;
emit2(meth);
Symbol sym = (Symbol) pool.pool[meth];
state.pop(argsize);
if (sym.isConstructor())
state.markInitialized((UninitializedType) state.peek());
state.pop(1);
state.push(mtype.getReturnType());
}
Aggregations