use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
the class Printer method className.
/**
* Converts a class name into a (possibly localized) string. Anonymous
* inner classes gets 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) {
StringBuffer s = new StringBuffer(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.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 com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
the class ClassReader method includeClassFile.
/** Include class corresponding to given class file in package,
* unless (1) we already have one the same kind (.class or .java), or
* (2) we have one of the other kind, and the given class file
* is older.
*/
protected void includeClassFile(PackageSymbol p, JavaFileObject file) {
if ((p.flags_field & EXISTS) == 0)
for (Symbol q = p; q != null && q.kind == PCK; q = q.owner) q.flags_field |= EXISTS;
JavaFileObject.Kind kind = file.getKind();
int seen;
if (kind == JavaFileObject.Kind.CLASS)
seen = CLASS_SEEN;
else
seen = SOURCE_SEEN;
String binaryName = fileManager.inferBinaryName(currentLoc, file);
int lastDot = binaryName.lastIndexOf(".");
Name classname = names.fromString(binaryName.substring(lastDot + 1));
boolean isPkgInfo = classname == names.package_info;
ClassSymbol c = isPkgInfo ? p.package_info : (ClassSymbol) p.members_field.lookup(classname).sym;
if (c == null) {
c = enterClass(classname, p);
if (// only update the file if's it's newly created
c.classfile == null)
c.classfile = file;
if (isPkgInfo) {
p.package_info = c;
} else {
if (// it might be an inner class
c.owner == p)
p.members_field.enter(c);
}
} else if (c.classfile != null && (c.flags_field & seen) == 0) {
// a file of the same kind; again no further action is necessary.
if ((c.flags_field & (CLASS_SEEN | SOURCE_SEEN)) != 0)
c.classfile = preferredFileObject(file, c.classfile);
}
c.flags_field |= seen;
}
use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
the class Gen method getStringBufferAppend.
Symbol getStringBufferAppend(JCTree tree, Type t) {
Assert.checkNull(t.constValue());
Symbol method = stringBufferAppend.get(t);
if (method == null) {
method = rs.resolveInternalMethod(tree.pos(), attrEnv, stringBufferType, names.append, List.of(t), null);
stringBufferAppend.put(t, method);
}
return method;
}
use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
the class DeclarationsImpl method hides.
/**
* {@inheritDoc}
* See sections 8.3 and 8.4.6 of
* <cite>The Java™ Language Specification</cite>
*/
public boolean hides(MemberDeclaration sub, MemberDeclaration sup) {
Symbol hider = ((DeclarationImpl) sub).sym;
Symbol hidee = ((DeclarationImpl) sup).sym;
// Names must match. Nothing hides itself (just try it).
if (hider == hidee || hider.kind != hidee.kind || hider.name != hidee.name) {
return false;
}
// Methods only hide methods with matching signatures.
if (hider.kind == MTH) {
if ((hider.flags() & Flags.STATIC) == 0 || !env.jctypes.isSubSignature(hider.type, hidee.type)) {
return false;
}
}
// Hider must be in a subclass of hidee's class.
// Note that if M1 hides M2, and M2 hides M3, and M3 is accessible
// in M1's class, then M1 and M2 both hide M3.
ClassSymbol hiderClass = hider.owner.enclClass();
ClassSymbol hideeClass = hidee.owner.enclClass();
if (hiderClass == null || hideeClass == null || !hiderClass.isSubClass(hideeClass, env.jctypes)) {
return false;
}
// The method isInheritedIn is poorly named: it checks only access.
return hidee.isInheritedIn(hiderClass, env.jctypes);
}
use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
the class Resolve method resolveDiamond.
/** Resolve constructor using diamond inference.
* @param pos The position to use for error reporting.
* @param env The environment current at the constructor invocation.
* @param site The type of class for which a constructor is searched.
* The scope of this class has been touched in attribution.
* @param argtypes The types of the constructor invocation's value
* arguments.
* @param typeargtypes The types of the constructor invocation's type
* arguments.
*/
Symbol resolveDiamond(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes) {
Symbol sym = startResolution();
List<MethodResolutionPhase> steps = methodResolutionSteps;
while (steps.nonEmpty() && steps.head.isApplicable(boxingEnabled, varargsEnabled) && sym.kind >= ERRONEOUS) {
currentStep = steps.head;
sym = resolveConstructor(pos, env, site, argtypes, typeargtypes, steps.head.isBoxingRequired(), env.info.varArgs = steps.head.isVarargsRequired());
methodResolutionCache.put(steps.head, sym);
steps = steps.tail;
}
if (sym.kind >= AMBIGUOUS) {
final JCDiagnostic details = sym.kind == WRONG_MTH ? ((InapplicableSymbolError) sym).explanation : null;
Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") {
@Override
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
String key = details == null ? "cant.apply.diamond" : "cant.apply.diamond.1";
return diags.create(dkind, log.currentSource(), pos, key, diags.fragment("diamond", site.tsym), details);
}
};
MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes);
env.info.varArgs = errPhase.isVarargsRequired();
}
return sym;
}
Aggregations