Search in sources :

Example 96 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class CeylonTransformer method transformAttribute.

public List<JCTree> transformAttribute(TypedDeclaration declarationModel, String attrName, String attrClassName, final Tree.Declaration annotated, final Tree.Block block, final Tree.SpecifierOrInitializerExpression expression, final Tree.TypedDeclaration decl, final Tree.AttributeSetterDefinition setterDecl) {
    // For everything else generate a getter/setter method
    ClassDefinitionBuilder classBuilder = ClassDefinitionBuilder.klass(this, attrClassName, null, false);
    final HasErrorException expressionError;
    if (expression != null) {
        expressionError = errors().getFirstExpressionErrorAndMarkBrokenness(expression.getExpression());
    } else {
        expressionError = null;
    }
    BoxingStrategy boxingStrategy = null;
    final JCExpression initialValue;
    if (expressionError != null) {
        initialValue = make().Erroneous();
    } else {
        if (Decl.isNonTransientValue(declarationModel) && !(expression instanceof Tree.LazySpecifierExpression)) {
            if (expression != null) {
                boxingStrategy = useJavaBox(declarationModel, declarationModel.getType()) && javaBoxExpression(expression.getExpression().getTypeModel(), declarationModel.getType()) ? BoxingStrategy.JAVA : CodegenUtil.getBoxingStrategy(declarationModel);
                initialValue = expressionGen().transform(expression, boxingStrategy, declarationModel.getType());
            } else {
                Parameter p = CodegenUtil.findParamForDecl(attrName, declarationModel);
                if (p != null) {
                    boxingStrategy = CodegenUtil.getBoxingStrategy(p.getModel());
                    initialValue = naming.makeName(p.getModel(), Naming.NA_MEMBER | Naming.NA_ALIASED);
                } else {
                    initialValue = null;
                }
            }
        } else {
            initialValue = null;
        }
    }
    boolean memoized = declarationModel.isLate() && expression != null;
    AttributeDefinitionBuilder builder = AttributeDefinitionBuilder.wrapped(this, attrName, declarationModel, declarationModel.isToplevel(), memoized ? initialValue : null);
    builder.is(Flags.PUBLIC, declarationModel.isShared());
    if (isJavaStrictfp(declarationModel)) {
        builder.is(Flags.STRICTFP, true);
    }
    if (isJavaSynchronized(declarationModel)) {
        builder.is(Flags.SYNCHRONIZED, true);
    }
    if (isJavaNative(declarationModel)) {
        builder.is(Flags.NATIVE, true);
        builder.isJavaNative(true);
    }
    // For captured local variable Values, use a VariableBox
    if (Decl.isBoxedVariable(declarationModel)) {
        classBuilder.restoreClassBuilder();
        if (expressionError != null) {
            return List.<JCTree>of(this.makeThrowUnresolvedCompilationError(expressionError));
        } else {
            return List.<JCTree>of(makeVariableBoxDecl(initialValue, declarationModel));
        }
    }
    // For late-bound getters we only generate a declaration
    if (block == null && expression == null && !declarationModel.isToplevel()) {
        JCExpression typeExpr = makeJavaType(getGetterInterfaceType(declarationModel));
        JCTree.JCVariableDecl var = makeVar(attrClassName, typeExpr, null);
        classBuilder.restoreClassBuilder();
        return List.<JCTree>of(var);
    }
    // Set the local declarations annotation
    List<JCAnnotation> scopeAnnotations = null;
    if (decl != null) {
        scopeAnnotations = declarationModel.isToplevel() && setterDecl != null ? makeAtLocalDeclarations(decl, setterDecl) : makeAtLocalDeclarations(decl);
    } else if (block != null) {
        scopeAnnotations = makeAtLocalDeclarations(block);
    }
    if (scopeAnnotations != null)
        builder.classAnnotations(scopeAnnotations);
    // Remember the setter class if we generate a getter
    if (Decl.isGetter(declarationModel) && declarationModel.isVariable() && Decl.isLocal(declarationModel)) {
        // we must have a setter class
        Setter setter = ((Value) declarationModel).getSetter();
        if (setter != null) {
            String setterClassName = Naming.getAttrClassName(setter, 0);
            JCExpression setterClassNameExpr = naming.makeUnquotedIdent(setterClassName);
            builder.setterClass(makeSelect(setterClassNameExpr, "class"));
        }
    }
    if (declarationModel instanceof Setter || (declarationModel instanceof FunctionOrValue && ((FunctionOrValue) declarationModel).isParameter())) {
        // For local setters
        JCBlock setterBlock = makeSetterBlock(declarationModel, block, expression);
        builder.setterBlock(setterBlock);
        builder.skipGetter();
        if (Decl.isLocal(decl.getDeclarationModel())) {
            // we need to find back the Setter model for local setters, because
            // in transformAttribute(Tree.TypedDeclaration decl, Tree.AttributeSetterDefinition setterDecl)
            // we turn the declaration model from the Setter to its single parameter
            Setter setter = (Setter) declarationModel.getContainer();
            String getterClassName = Naming.getAttrClassName(setter.getGetter(), 0);
            JCExpression getterClassNameExpr = naming.makeUnquotedIdent(getterClassName);
            builder.isSetter(makeSelect(getterClassNameExpr, "class"));
        }
    } else {
        if (Decl.isValue(declarationModel)) {
            // For local and toplevel value attributes
            if (!declarationModel.isVariable() && !declarationModel.isLate()) {
                builder.immutable();
            }
        } else {
            // For local and toplevel getters
            boolean prevSyntheticClassBody = Decl.isLocal(declarationModel) ? expressionGen().withinSyntheticClassBody(true) : expressionGen().isWithinSyntheticClassBody();
            JCBlock getterBlock = makeGetterBlock(declarationModel, block, expression);
            prevSyntheticClassBody = expressionGen().withinSyntheticClassBody(prevSyntheticClassBody);
            builder.getterBlock(getterBlock);
            if (Decl.isLocal(declarationModel)) {
                // For local getters
                builder.immutable();
            } else {
                // For toplevel getters
                if (setterDecl != null) {
                    JCBlock setterBlock = makeSetterBlock(setterDecl.getDeclarationModel(), setterDecl.getBlock(), setterDecl.getSpecifierExpression());
                    builder.setterBlock(setterBlock);
                    // builder.userAnnotationsSetter(expressionGen().transformAnnotations(true, OutputElement.METHOD, setterDecl));
                    builder.userAnnotationsSetter(expressionGen().transformAnnotations(OutputElement.SETTER, setterDecl));
                } else {
                    builder.immutable();
                }
            }
        }
    }
    if (annotated != null) {
        builder.userAnnotations(expressionGen().transformAnnotations(OutputElement.GETTER, annotated));
        builder.fieldAnnotations(expressionGen().transformAnnotations(OutputElement.FIELD, annotated));
    }
    if (Decl.isLocal(declarationModel)) {
        if (expressionError != null) {
            classBuilder.restoreClassBuilder();
            return List.<JCTree>of(this.makeThrowUnresolvedCompilationError(expressionError));
        }
        builder.classAnnotations(makeAtLocalDeclaration(declarationModel.getQualifier(), false));
        if (initialValue != null)
            builder.valueConstructor();
        JCExpression typeExpr;
        if (declarationModel instanceof Setter || (declarationModel instanceof FunctionOrValue && ((FunctionOrValue) declarationModel).isParameter())) {
            typeExpr = makeQuotedIdent(attrClassName);
        } else {
            typeExpr = makeJavaType(getGetterInterfaceType(declarationModel));
        }
        return builder.buildWithWrapperClass(classBuilder).append(makeLocalIdentityInstance(typeExpr, attrClassName, attrClassName, declarationModel.isShared(), initialValue));
    } else {
        if (expressionError != null) {
            builder.initialValueError(expressionError);
        } else if (!memoized && initialValue != null) {
            builder.initialValue(initialValue, boxingStrategy);
        }
        builder.is(Flags.STATIC, true);
        return builder.buildWithWrapperClass(classBuilder);
    }
}
Also used : JCBlock(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCBlock) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) HasErrorException(org.eclipse.ceylon.compiler.java.codegen.recovery.HasErrorException) JCVariableDecl(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 97 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class CeylonTransformer method transformAttribute.

public List<JCTree> transformAttribute(Tree.TypedDeclaration decl, Tree.AttributeSetterDefinition setterDecl) {
    at(decl);
    TypedDeclaration declarationModel = decl.getDeclarationModel();
    final String attrName = declarationModel.getName();
    final String attrClassName = Naming.getAttrClassName(declarationModel, 0);
    final Tree.SpecifierOrInitializerExpression expression;
    final Tree.Block block;
    if (decl instanceof Tree.AttributeDeclaration) {
        Tree.AttributeDeclaration adecl = (Tree.AttributeDeclaration) decl;
        expression = adecl.getSpecifierOrInitializerExpression();
        block = null;
    } else if (decl instanceof Tree.AttributeGetterDefinition) {
        expression = null;
        Tree.AttributeGetterDefinition gdef = (Tree.AttributeGetterDefinition) decl;
        block = gdef.getBlock();
    } else if (decl instanceof Tree.AttributeSetterDefinition) {
        Tree.AttributeSetterDefinition sdef = (Tree.AttributeSetterDefinition) decl;
        block = sdef.getBlock();
        expression = sdef.getSpecifierExpression();
        if (Decl.isLocal(decl.getDeclarationModel())) {
            declarationModel = ((Tree.AttributeSetterDefinition) decl).getDeclarationModel().getParameter().getModel();
        }
    } else {
        throw new RuntimeException();
    }
    return transformAttribute(declarationModel, attrName, attrClassName, decl, block, expression, decl, setterDecl);
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Example 98 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class CeylonTransformer method makeDefs.

private List<JCTree> makeDefs(CompilationUnit t) {
    final ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
    t.visit(new SourceDeclarationVisitor() {

        @Override
        public void loadFromSource(Declaration decl) {
            if (!checkNative(decl))
                return;
            Stack<Tree.Declaration> ancestors = new Stack<>();
            long flags = decl instanceof Tree.AnyInterface ? Flags.INTERFACE : 0;
            String name = Naming.toplevelClassName("", decl);
            defs.add(makeClassDef(decl, flags, name, WantedDeclaration.Normal, defs, ancestors));
            if (decl instanceof Tree.AnyInterface) {
                String implName = Naming.getImplClassName(name);
                defs.add(makeClassDef(decl, 0, implName, WantedDeclaration.InterfaceImpl, defs, ancestors));
            }
            if (Decl.isAnnotationClassNoModel(decl)) {
                String annotationName = Naming.suffixName(Suffix.$annotation$, name);
                defs.add(makeClassDef(decl, Flags.ANNOTATION | Flags.INTERFACE, annotationName, WantedDeclaration.Annotation, defs, ancestors));
                if (Decl.isSequencedAnnotationClassNoModel((Tree.AnyClass) decl)) {
                    String annotationsName = Naming.suffixName(Suffix.$annotations$, name);
                    defs.add(makeClassDef(decl, Flags.ANNOTATION | Flags.INTERFACE, annotationsName, WantedDeclaration.AnnotationSequence, defs, ancestors));
                }
            }
        }

        private JCTree makeClassDef(Tree.Declaration decl, long flags, String name, WantedDeclaration wantedDeclaration, ListBuffer<JCTree> toplevelDeclarations, Stack<Tree.Declaration> ancestors) {
            if (decl instanceof Tree.AnyInterface == false && TreeUtil.hasAnnotation(decl.getAnnotationList(), "static", null)) {
                flags |= Flags.STATIC;
            }
            ListBuffer<JCTree.JCTypeParameter> typarams = new ListBuffer<JCTree.JCTypeParameter>();
            if (decl instanceof Tree.ClassOrInterface) {
                Tree.ClassOrInterface classDecl = (ClassOrInterface) decl;
                if (decl instanceof Tree.AnyInterface) {
                    // interfaces are pulled up and catch container type params
                    for (Tree.Declaration ancestor : ancestors) {
                        if (ancestor instanceof Tree.ClassOrInterface) {
                            addTypeParameters(typarams, (Tree.ClassOrInterface) ancestor);
                        }
                    }
                }
                addTypeParameters(typarams, classDecl);
            }
            ancestors.push(decl);
            JCTree ret = make().ClassDef(make().Modifiers(flags | Flags.PUBLIC), names().fromString(name), typarams.toList(), null, List.<JCExpression>nil(), makeClassBody(decl, wantedDeclaration, toplevelDeclarations, ancestors));
            ancestors.pop();
            return ret;
        }

        private void addTypeParameters(ListBuffer<JCTypeParameter> typarams, Tree.ClassOrInterface classDecl) {
            if (classDecl.getTypeParameterList() != null) {
                for (Tree.TypeParameterDeclaration typeParamDecl : classDecl.getTypeParameterList().getTypeParameterDeclarations()) {
                    // we don't need a valid name, just a name, and making it BOGUS helps us find it later if it turns out
                    // we failed to reset everything properly
                    typarams.add(make().TypeParameter(names().fromString("BOGUS-" + typeParamDecl.getIdentifier().getText()), List.<JCExpression>nil()));
                }
            }
        }

        private List<JCTree> makeClassBody(Declaration decl, WantedDeclaration wantedDeclaration, ListBuffer<JCTree> toplevelDeclarations, Stack<Tree.Declaration> ancestors) {
            // only do it for Bootstrap where we control the annotations, because it's so dodgy ATM
            if (wantedDeclaration == WantedDeclaration.Annotation) {
                ListBuffer<JCTree> body = new ListBuffer<JCTree>();
                for (Tree.Parameter param : ((Tree.ClassDefinition) decl).getParameterList().getParameters()) {
                    String name;
                    JCExpression type = make().TypeArray(make().Type(syms().stringType));
                    if (param instanceof Tree.InitializerParameter)
                        name = ((Tree.InitializerParameter) param).getIdentifier().getText();
                    else if (param instanceof Tree.ParameterDeclaration) {
                        Tree.TypedDeclaration typedDeclaration = ((Tree.ParameterDeclaration) param).getTypedDeclaration();
                        name = typedDeclaration.getIdentifier().getText();
                        type = getAnnotationTypeFor(typedDeclaration.getType());
                    } else
                        name = "ERROR";
                    JCMethodDecl method = make().MethodDef(make().Modifiers(Flags.PUBLIC), names().fromString(name), type, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null);
                    body.append(method);
                }
                return body.toList();
            }
            if (wantedDeclaration == WantedDeclaration.AnnotationSequence) {
                String name = Naming.toplevelClassName("", decl);
                String annotationName = Naming.suffixName(Suffix.$annotation$, name);
                JCExpression type = make().TypeArray(make().Ident(names().fromString(annotationName)));
                JCMethodDecl method = make().MethodDef(make().Modifiers(Flags.PUBLIC), names().fromString("value"), type, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null);
                return List.<JCTree>of(method);
            }
            ListBuffer<JCTree> defs = new ListBuffer<>();
            java.util.List<Statement> statements = null;
            if (decl instanceof Tree.ClassDefinition)
                statements = ((Tree.ClassDefinition) decl).getClassBody().getStatements();
            else if (decl instanceof Tree.InterfaceDefinition) {
                // only walk interface members if we're generating the impl class
                if (wantedDeclaration == WantedDeclaration.InterfaceImpl)
                    statements = ((Tree.InterfaceDefinition) decl).getInterfaceBody().getStatements();
            }
            if (statements != null) {
                for (Tree.Statement member : statements) {
                    if (member instanceof Tree.ClassOrInterface && checkNative((Tree.Declaration) member)) {
                        long flags = member instanceof Tree.AnyInterface ? Flags.INTERFACE : 0;
                        String initialName = Naming.toplevelClassName("", (Tree.Declaration) member);
                        String name;
                        if (member instanceof Tree.AnyInterface) {
                            // interfaces are pulled to the toplevel
                            StringBuffer strbuf = new StringBuffer();
                            for (Tree.Declaration part : ancestors) strbuf.append(part.getIdentifier().getText()).append("$");
                            name = strbuf.append(initialName).toString();
                        } else {
                            name = initialName;
                        }
                        JCTree def = makeClassDef((Tree.Declaration) member, flags, name, WantedDeclaration.Normal, toplevelDeclarations, ancestors);
                        if (member instanceof Tree.AnyInterface) {
                            toplevelDeclarations.add(def);
                            String implName = Naming.getImplClassName(initialName);
                            defs.add(makeClassDef((Tree.Declaration) member, 0, implName, WantedDeclaration.InterfaceImpl, defs, ancestors));
                        } else
                            defs.add(def);
                    // FIXME: interfaces impl?
                    }
                }
            }
            return defs.toList();
        }

        private JCExpression getAnnotationTypeFor(Tree.Type type) {
            if (type instanceof Tree.BaseType) {
                String name = ((Tree.BaseType) type).getIdentifier().getText();
                if (name.equals("String") || name.equals("Declaration"))
                    return make().Type(syms().stringType);
                if (name.equals("Boolean"))
                    return make().Type(syms().booleanType);
                if (name.equals("Integer"))
                    return make().Type(syms().longType);
                if (name.equals("Float"))
                    return make().Type(syms().doubleType);
                if (name.equals("Byte"))
                    return make().Type(syms().byteType);
                if (name.equals("Character"))
                    return make().Type(syms().charType);
                if (name.equals("Declaration") || name.equals("ClassDeclaration") || name.equals("InterfaceDeclaration") || name.equals("ClassOrInterfaceDeclaration"))
                    return make().Type(syms().stringType);
                // probably an enum value then
                return make().TypeArray(make().Type(syms().stringType));
            }
            if (type instanceof Tree.SequencedType) {
                return make().TypeArray(getAnnotationTypeFor(((Tree.SequencedType) type).getType()));
            }
            if (type instanceof Tree.SequenceType) {
                return make().TypeArray(getAnnotationTypeFor(((Tree.SequenceType) type).getElementType()));
            }
            if (type instanceof Tree.IterableType) {
                return make().TypeArray(getAnnotationTypeFor(((Tree.IterableType) type).getElementType()));
            }
            if (type instanceof Tree.TupleType) {
                // can only be one, must be a SequencedType
                Tree.Type sequencedType = ((Tree.TupleType) type).getElementTypes().get(0);
                return getAnnotationTypeFor(sequencedType);
            }
            System.err.println("Unknown Annotation type: " + type);
            return make().TypeArray(make().Type(syms().stringType));
        }

        @Override
        public void loadFromSource(ModuleDescriptor that) {
        // don't think we care about these
        }

        @Override
        public void loadFromSource(PackageDescriptor that) {
        // don't think we care about these
        }
    });
    return defs.toList();
}
Also used : ClassOrInterface(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ClassOrInterface) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) SourceDeclarationVisitor(org.eclipse.ceylon.compiler.java.loader.SourceDeclarationVisitor) List(org.eclipse.ceylon.langtools.tools.javac.util.List) Declaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Declaration) JCMethodDecl(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCMethodDecl) Stack(java.util.Stack) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) PackageDescriptor(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PackageDescriptor) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Declaration(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Declaration) ClassOrInterface(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ClassOrInterface) Statement(org.eclipse.ceylon.compiler.typechecker.tree.Tree.Statement) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) JCVariableDecl(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl) ModuleDescriptor(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ModuleDescriptor) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter)

Example 99 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class CeylonTransformer method transformAttributeGetter.

public JCExpression transformAttributeGetter(TypedDeclaration declarationModel, final JCExpression expression) {
    final String attrName = declarationModel.getName();
    final String attrClassName = Naming.getAttrClassName(declarationModel, 0);
    JCBlock getterBlock = makeGetterBlock(expression);
    // For everything else generate a getter/setter method
    AttributeDefinitionBuilder builder = AttributeDefinitionBuilder.indirect(this, attrName, declarationModel, declarationModel.isToplevel()).getterBlock(getterBlock).immutable();
    ClassDefinitionBuilder classBuilder = ClassDefinitionBuilder.klass(this, attrClassName, null, false);
    List<JCTree> attr = builder.buildWithWrapperClass(classBuilder);
    JCNewClass newExpr = makeNewClass(attrClassName, false, null);
    JCExpression result = makeLetExpr(naming.temp(), List.<JCStatement>of((JCStatement) attr.get(0)), newExpr);
    return result;
}
Also used : JCBlock(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCBlock) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) JCNewClass(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass) JCStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)

Example 100 with JCTree

use of org.eclipse.ceylon.langtools.tools.javac.tree.JCTree in project ceylon by eclipse.

the class JavaPositionsRetriever method getJavaSourceCodeWithCeylonPositions.

public String getJavaSourceCodeWithCeylonPositions() {
    final CharArrayWriter writer = new CharArrayWriter();
    Pretty printer = new Pretty(writer, true) {

        int previousCeylonPosition = -1;

        int previousPositionInString = 0;

        private void outputCeylonPosition(JCTree tree) {
            try {
                int currentCeylonPosition = tree.getPreferredPosition();
                int currentPositionInString = writer.size();
                if (previousCeylonPosition != currentCeylonPosition || previousPositionInString != currentPositionInString) {
                    if (currentCeylonPosition != -1 && currentCeylonPosition != 0) {
                        writer.write("/* " + formatCeylonPosition(currentCeylonPosition) + " */");
                    }
                    previousCeylonPosition = currentCeylonPosition;
                    previousPositionInString = writer.size();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void visitTopLevel(JCCompilationUnit tree) {
            outputCeylonPosition(tree);
            super.visitTopLevel(tree);
        }

        @Override
        public void visitImport(JCImport tree) {
            outputCeylonPosition(tree);
            super.visitImport(tree);
        }

        @Override
        public void visitClassDef(JCClassDecl tree) {
            outputCeylonPosition(tree);
            super.visitClassDef(tree);
        }

        @Override
        public void visitMethodDef(JCMethodDecl tree) {
            outputCeylonPosition(tree);
            super.visitMethodDef(tree);
        }

        @Override
        public void visitVarDef(JCVariableDecl tree) {
            outputCeylonPosition(tree);
            super.visitVarDef(tree);
        }

        @Override
        public void visitSkip(JCSkip tree) {
            outputCeylonPosition(tree);
            super.visitSkip(tree);
        }

        @Override
        public void visitBlock(JCBlock tree) {
            outputCeylonPosition(tree);
            super.visitBlock(tree);
            tree.endpos = currentPosition - 1;
        }

        @Override
        public void visitDoLoop(JCDoWhileLoop tree) {
            outputCeylonPosition(tree);
            super.visitDoLoop(tree);
        }

        @Override
        public void visitWhileLoop(JCWhileLoop tree) {
            outputCeylonPosition(tree);
            super.visitWhileLoop(tree);
        }

        @Override
        public void visitForLoop(JCForLoop tree) {
            outputCeylonPosition(tree);
            super.visitForLoop(tree);
        }

        @Override
        public void visitForeachLoop(JCEnhancedForLoop tree) {
            outputCeylonPosition(tree);
            super.visitForeachLoop(tree);
        }

        @Override
        public void visitLabelled(JCLabeledStatement tree) {
            outputCeylonPosition(tree);
            super.visitLabelled(tree);
        }

        @Override
        public void visitSwitch(JCSwitch tree) {
            outputCeylonPosition(tree);
            super.visitSwitch(tree);
        }

        @Override
        public void visitCase(JCCase tree) {
            outputCeylonPosition(tree);
            super.visitCase(tree);
        }

        @Override
        public void visitSynchronized(JCSynchronized tree) {
            outputCeylonPosition(tree);
            super.visitSynchronized(tree);
        }

        @Override
        public void visitTry(JCTry tree) {
            outputCeylonPosition(tree);
            super.visitTry(tree);
        }

        @Override
        public void visitCatch(JCCatch tree) {
            outputCeylonPosition(tree);
            super.visitCatch(tree);
        }

        @Override
        public void visitConditional(JCConditional tree) {
            outputCeylonPosition(tree);
            super.visitConditional(tree);
        }

        @Override
        public void visitIf(JCIf tree) {
            outputCeylonPosition(tree);
            super.visitIf(tree);
        }

        @Override
        public void visitExec(JCExpressionStatement tree) {
            outputCeylonPosition(tree);
            super.visitExec(tree);
        }

        @Override
        public void visitBreak(JCBreak tree) {
            outputCeylonPosition(tree);
            super.visitBreak(tree);
        }

        @Override
        public void visitContinue(JCContinue tree) {
            outputCeylonPosition(tree);
            super.visitContinue(tree);
        }

        @Override
        public void visitReturn(JCReturn tree) {
            outputCeylonPosition(tree);
            super.visitReturn(tree);
        }

        @Override
        public void visitThrow(JCThrow tree) {
            outputCeylonPosition(tree);
            super.visitThrow(tree);
        }

        @Override
        public void visitAssert(JCAssert tree) {
            outputCeylonPosition(tree);
            super.visitAssert(tree);
        }

        @Override
        public void visitApply(JCMethodInvocation tree) {
            outputCeylonPosition(tree);
            super.visitApply(tree);
        }

        @Override
        public void visitNewClass(JCNewClass tree) {
            outputCeylonPosition(tree);
            super.visitNewClass(tree);
        }

        @Override
        public void visitNewArray(JCNewArray tree) {
            outputCeylonPosition(tree);
            super.visitNewArray(tree);
        }

        @Override
        public void visitParens(JCParens tree) {
            outputCeylonPosition(tree);
            super.visitParens(tree);
        }

        @Override
        public void visitAssign(JCAssign tree) {
            outputCeylonPosition(tree);
            super.visitAssign(tree);
        }

        @Override
        public void visitAssignop(JCAssignOp tree) {
            outputCeylonPosition(tree);
            super.visitAssignop(tree);
        }

        @Override
        public void visitUnary(JCUnary tree) {
            outputCeylonPosition(tree);
            super.visitUnary(tree);
        }

        @Override
        public void visitBinary(JCBinary tree) {
            outputCeylonPosition(tree);
            super.visitBinary(tree);
        }

        @Override
        public void visitTypeCast(JCTypeCast tree) {
            outputCeylonPosition(tree);
            super.visitTypeCast(tree);
        }

        @Override
        public void visitTypeTest(JCInstanceOf tree) {
            outputCeylonPosition(tree);
            super.visitTypeTest(tree);
        }

        @Override
        public void visitIndexed(JCArrayAccess tree) {
            outputCeylonPosition(tree);
            super.visitIndexed(tree);
        }

        @Override
        public void visitSelect(JCFieldAccess tree) {
            outputCeylonPosition(tree);
            super.visitSelect(tree);
        }

        @Override
        public void visitIdent(JCIdent tree) {
            outputCeylonPosition(tree);
            super.visitIdent(tree);
        }

        @Override
        public void visitLiteral(JCLiteral tree) {
            outputCeylonPosition(tree);
            super.visitLiteral(tree);
        }

        @Override
        public void visitTypeIdent(JCPrimitiveTypeTree tree) {
            outputCeylonPosition(tree);
            super.visitTypeIdent(tree);
        }

        @Override
        public void visitTypeArray(JCArrayTypeTree tree) {
            outputCeylonPosition(tree);
            super.visitTypeArray(tree);
        }

        @Override
        public void visitTypeApply(JCTypeApply tree) {
            outputCeylonPosition(tree);
            super.visitTypeApply(tree);
        }

        @Override
        public void visitTypeParameter(JCTypeParameter tree) {
            outputCeylonPosition(tree);
            super.visitTypeParameter(tree);
        }

        @Override
        public void visitWildcard(JCWildcard tree) {
            outputCeylonPosition(tree);
            super.visitWildcard(tree);
        }

        @Override
        public void visitTypeBoundKind(TypeBoundKind tree) {
            outputCeylonPosition(tree);
            super.visitTypeBoundKind(tree);
        }

        @Override
        public void visitErroneous(JCErroneous tree) {
            outputCeylonPosition(tree);
            super.visitErroneous(tree);
        }

        @Override
        public void visitLetExpr(LetExpr tree) {
            outputCeylonPosition(tree);
            super.visitLetExpr(tree);
        }

        @Override
        public void visitModifiers(JCModifiers mods) {
            outputCeylonPosition(mods);
            super.visitModifiers(mods);
        }

        @Override
        public void visitAnnotation(JCAnnotation tree) {
            outputCeylonPosition(tree);
            super.visitAnnotation(tree);
        }

        @Override
        public void visitTree(JCTree tree) {
            outputCeylonPosition(tree);
            super.visitTree(tree);
        }
    };
    printer.visitTopLevel(unit);
    return writer.toString();
}
Also used : JCFieldAccess(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCFieldAccess) JCTypeApply(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeApply) JCAssert(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAssert) JCPrimitiveTypeTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCIf(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCIf) JCEnhancedForLoop(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCEnhancedForLoop) JCNewClass(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass) JCNewArray(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewArray) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation) JCCase(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCase) JCThrow(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCThrow) JCImport(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCImport) JCWildcard(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCWildcard) JCClassDecl(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCClassDecl) JCIdent(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCIdent) JCMethodDecl(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCMethodDecl) LetExpr(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.LetExpr) JCErroneous(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCErroneous) JCSynchronized(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCSynchronized) JCParens(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCParens) JCDoWhileLoop(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCDoWhileLoop) JCContinue(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCContinue) JCInstanceOf(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCInstanceOf) TypeBoundKind(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.TypeBoundKind) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) JCMethodInvocation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCMethodInvocation) JCUnary(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCUnary) JCModifiers(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCModifiers) JCCatch(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCatch) JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) JCWhileLoop(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCWhileLoop) JCReturn(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCReturn) JCLabeledStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCLabeledStatement) JCAssign(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAssign) JCSkip(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCSkip) JCConditional(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCConditional) JCExpressionStatement(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpressionStatement) CharArrayWriter(java.io.CharArrayWriter) JCTypeCast(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeCast) JCArrayTypeTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCArrayTypeTree) JCBlock(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCBlock) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree) JCBinary(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCBinary) JCArrayAccess(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCArrayAccess) IOException(java.io.IOException) JCForLoop(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCForLoop) JCVariableDecl(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl) Pretty(org.eclipse.ceylon.langtools.tools.javac.tree.Pretty) JCTry(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTry) JCSwitch(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCSwitch) JCLiteral(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCLiteral) JCAssignOp(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAssignOp) JCBreak(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCBreak)

Aggregations

JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)101 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)19 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)18 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)12 JCVariableDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCVariableDecl)10 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)9 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)8 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)8 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)8 ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)8 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)7 Type (org.eclipse.ceylon.model.typechecker.model.Type)6 JCAnnotation (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)5 JCBlock (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCBlock)4 JCClassDecl (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCClassDecl)4 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)4 JCPrimitiveTypeTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCPrimitiveTypeTree)4 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)4 IOException (java.io.IOException)3 TaskEvent (org.eclipse.ceylon.langtools.source.util.TaskEvent)3