Search in sources :

Example 6 with Name

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;
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) Name(org.eclipse.ceylon.langtools.tools.javac.util.Name)

Example 7 with Name

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;
}
Also used : MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) TypeSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) PackageSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) Name(org.eclipse.ceylon.langtools.tools.javac.util.Name)

Example 8 with Name

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;
    }
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) Name(org.eclipse.ceylon.langtools.tools.javac.util.Name)

Example 9 with Name

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();
}
Also used : Name(org.eclipse.ceylon.langtools.tools.javac.util.Name)

Example 10 with Name

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;
    }
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) IOException(java.io.IOException) Name(org.eclipse.ceylon.langtools.tools.javac.util.Name)

Aggregations

Name (org.eclipse.ceylon.langtools.tools.javac.util.Name)15 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)8 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)8 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)8 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)6 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)6 CName (org.eclipse.ceylon.compiler.java.codegen.Naming.CName)5 JCVariableDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)5 Type (org.eclipse.ceylon.model.typechecker.model.Type)5 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)3 JCAnnotation (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)3 JCBlock (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCBlock)3 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)3 Substitution (org.eclipse.ceylon.compiler.java.codegen.Naming.Substitution)2 Expression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Expression)2 SpecifierOrInitializerExpression (org.eclipse.ceylon.compiler.typechecker.tree.Tree.SpecifierOrInitializerExpression)2 Term (org.eclipse.ceylon.compiler.typechecker.tree.Tree.Term)2 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)2 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)2 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)2