use of org.eclipse.ceylon.langtools.tools.javac.util.Name in project ceylon by eclipse.
the class ClassDefinitionBuilder method field.
public ClassDefinitionBuilder field(long modifiers, String attrName, JCExpression type, JCExpression initialValue, boolean isLocal, List<JCTree.JCAnnotation> annotations) {
if (!isLocal) {
// A shared or captured attribute gets turned into a class member
Name attrNameNm = gen.names().fromString(Naming.quoteFieldName(attrName));
JCExpression fieldInit;
if ((modifiers & Flags.STATIC) != 0) {
fieldInit = initialValue;
} else {
fieldInit = null;
}
defs(gen.make().VarDef(gen.make().Modifiers(modifiers, annotations), attrNameNm, type, fieldInit));
if (initialValue != null && (modifiers & Flags.STATIC) == 0) {
// The attribute's initializer gets moved to the constructor
// because it might be using locals of the initializer
initBuilder.init(gen.make().Exec(gen.make().Assign(gen.makeSelect("this", Naming.quoteFieldName(attrName)), initialValue)));
}
} else {
// Otherwise it's local to the constructor
// Stef: pretty sure we don't want annotations on a variable defined in a constructor
Name attrNameNm = gen.names().fromString(Naming.quoteLocalValueName(attrName));
initBuilder.init(gen.make().VarDef(gen.make().Modifiers(modifiers), attrNameNm, type, initialValue));
}
return this;
}
use of org.eclipse.ceylon.langtools.tools.javac.util.Name in project ceylon by eclipse.
the class CeylonModelLoader method getEnclosing.
private ClassSymbol getEnclosing(ClassSymbol c) {
Symbol owner = c.owner;
org.eclipse.ceylon.langtools.tools.javac.util.List<Name> enclosing = Convert.enclosingCandidates(Convert.shortName(c.name));
if (enclosing.isEmpty())
return c;
Name name = enclosing.head;
Symbol encl = owner.members().lookup(name).sym;
if (encl == null || !(encl instanceof ClassSymbol))
encl = symtab.classes.get(TypeSymbol.formFlatName(name, owner));
if (encl != null)
return (ClassSymbol) encl;
return c;
}
use of org.eclipse.ceylon.langtools.tools.javac.util.Name in project ceylon by eclipse.
the class JavacElements method nameToSymbol.
/**
* Returns a symbol given the type's or packages's canonical name,
* or null if the name isn't found.
*/
private <S extends Symbol> S nameToSymbol(String nameStr, Class<S> clazz) {
Name name = names.fromString(nameStr);
// First check cache.
Symbol sym = (clazz == ClassSymbol.class) ? syms.classes.get(name) : syms.packages.get(name);
try {
if (sym == null)
sym = javaCompiler.resolveIdent(nameStr);
sym.complete();
return (sym.kind != Kinds.ERR && sym.exists() && clazz.isInstance(sym) && name.equals(sym.getQualifiedName())) ? clazz.cast(sym) : null;
} catch (CompletionFailure e) {
return null;
}
}
use of org.eclipse.ceylon.langtools.tools.javac.util.Name in project ceylon by eclipse.
the class Tokens method enterKeyword.
private void enterKeyword(String s, TokenKind token) {
Name n = names.fromString(s);
tokenName[token.ordinal()] = n;
if (n.getIndex() > maxKey)
maxKey = n.getIndex();
}
use of org.eclipse.ceylon.langtools.tools.javac.util.Name in project ceylon by eclipse.
the class CeylonModelLoader method loadClassInternal.
private boolean loadClassInternal(String quotedClassName) {
try {
Name name = names.fromString(quotedClassName);
if (syms().classes.containsKey(name))
return true;
JavaFileObject fileObject = fileManager.getJavaFileForInput(PLATFORM_CLASS_PATH, quotedClassName, JavaFileObject.Kind.CLASS);
if (fileObject == null) {
fileObject = fileManager.getJavaFileForInput(CLASS_PATH, quotedClassName, JavaFileObject.Kind.CLASS);
}
if (fileObject != null) {
reader.enterClass(name, fileObject);
return true;
}
return false;
} catch (IOException e) {
// this is not normal, but will result in an error elsewhere, so just log it
logVerbose("IOException loading class: " + e.getMessage());
return false;
}
}
Aggregations