Search in sources :

Example 26 with SimpleName

use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.

the class JavadocConverter method visitParam.

@Override
public Void visitParam(ParamTree node, TagElement tag) {
    DCTree.DCIdentifier identifier = (DCTree.DCIdentifier) node.getName();
    if (identifier == null || node.isTypeParameter()) {
        return null;
    }
    List<? extends VariableElement> params = element instanceof ExecutableElement ? ((ExecutableElement) element).getParameters() : Collections.emptyList();
    tag.setTagName(TagElement.TAG_PARAM);
    String name = identifier.toString();
    VariableElement param = null;
    for (VariableElement p : params) {
        if (name.equals(p.getSimpleName().toString())) {
            param = p;
            break;
        }
    }
    // param will be null if the @param tag refers to a nonexistent parameter.
    TreeNode nameNode = param != null ? new SimpleName(param) : new SimpleName(name);
    setPos(identifier, nameNode);
    tag.addFragment(nameNode);
    scan(node.getDescription(), tag);
    int lastEnd = nameNode.getStartPosition();
    for (TreeNode fragment : tag.getFragments()) {
        // TODO(tball): remove and fix JavadocGenerator after javac switch.
        if (fragment.getKind() == TreeNode.Kind.TEXT_ELEMENT) {
            TextElement text = (TextElement) fragment;
            text.setText(" " + text.getText());
            text.setSourceRange(text.getStartPosition(), text.getLength() + 1);
        }
        int thisEnd = lastEnd + fragment.getLength();
        setPos(fragment, lastEnd, thisEnd);
        lastEnd = thisEnd;
    }
    setPos(tag, pos(node), endPos(node));
    tag.setLineNumber(nameNode.getLineNumber());
    return null;
}
Also used : TextElement(com.google.devtools.j2objc.ast.TextElement) TreeNode(com.google.devtools.j2objc.ast.TreeNode) ExecutableElement(javax.lang.model.element.ExecutableElement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) VariableElement(javax.lang.model.element.VariableElement) DCTree(com.sun.tools.javac.tree.DCTree)

Example 27 with SimpleName

use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.

the class TreeConverter method convertFieldAccess.

private TreeNode convertFieldAccess(JCTree.JCFieldAccess node) {
    String fieldName = node.name.toString();
    SourcePosition pos = getPosition(node);
    JCTree.JCExpression selected = node.getExpression();
    if (fieldName.equals("this")) {
        return new ThisExpression().setQualifier((Name) convert(selected)).setTypeMirror(node.sym.asType());
    }
    if ("super".equals(getMemberName(selected))) {
        SuperFieldAccess newNode = new SuperFieldAccess().setVariableElement((VariableElement) node.sym).setName(convertSimpleName(node.sym, node.type, pos));
        if (selected.getKind() == Kind.MEMBER_SELECT) {
            newNode.setQualifier((Name) convert(((JCTree.JCFieldAccess) selected).getExpression()));
        }
        return newNode;
    }
    if (node.getIdentifier().toString().equals("class")) {
        return new TypeLiteral(node.type).setType((Type) convertType(selected.type, pos, false).setPosition(getPosition(node)));
    }
    if (selected.getKind() == Kind.IDENTIFIER && (!node.sym.getKind().isField() || ElementUtil.isConstant((VariableElement) node.sym))) {
        if (selected.toString().equals("this")) {
            // Just return the constant.
            return new SimpleName(node.sym);
        }
        JCIdent ident = (JCTree.JCIdent) selected;
        return new QualifiedName().setName(convertSimpleName(node.sym, node.type, pos)).setQualifier(convertSimpleName(ident.sym, ident.type, pos)).setElement(node.sym);
    }
    if (selected.getKind() == Kind.MEMBER_SELECT) {
        TreeNode newSelected = convertFieldAccess((JCTree.JCFieldAccess) selected).setPosition(pos);
        if (newSelected.getKind() == TreeNode.Kind.QUALIFIED_NAME) {
            return new QualifiedName().setName(convertSimpleName(node.sym, node.type, pos)).setQualifier((QualifiedName) newSelected).setElement(node.sym);
        }
    }
    if (ElementUtil.isConstant((VariableElement) node.sym) && ElementUtil.isStatic(node.sym) && !(selected.getKind() == Kind.METHOD_INVOCATION)) {
        return new QualifiedName().setName(convertSimpleName(node.sym, node.type, pos)).setQualifier((Name) convert(selected)).setElement(node.sym);
    }
    return new FieldAccess().setVariableElement((VariableElement) node.sym).setExpression((Expression) convert(selected)).setName(convertSimpleName(node.sym, node.type, pos).setTypeMirror(node.type));
}
Also used : JCIdent(com.sun.tools.javac.tree.JCTree.JCIdent) SimpleName(com.google.devtools.j2objc.ast.SimpleName) QualifiedName(com.google.devtools.j2objc.ast.QualifiedName) JCTree(com.sun.tools.javac.tree.JCTree) SuperFieldAccess(com.google.devtools.j2objc.ast.SuperFieldAccess) VariableElement(javax.lang.model.element.VariableElement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) Name(com.google.devtools.j2objc.ast.Name) QualifiedName(com.google.devtools.j2objc.ast.QualifiedName) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) TypeLiteral(com.google.devtools.j2objc.ast.TypeLiteral) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionalExpression(com.google.devtools.j2objc.ast.FunctionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) TreeNode(com.google.devtools.j2objc.ast.TreeNode) SourcePosition(com.google.devtools.j2objc.ast.SourcePosition) FieldAccess(com.google.devtools.j2objc.ast.FieldAccess) SuperFieldAccess(com.google.devtools.j2objc.ast.SuperFieldAccess)

Example 28 with SimpleName

use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.

the class TreeConverter method convertBreakStatement.

private TreeNode convertBreakStatement(JCTree.JCBreak node) {
    BreakStatement newNode = new BreakStatement();
    Object label = node.getLabel();
    if (label != null) {
        newNode.setLabel((SimpleName) new SimpleName(label.toString()).setPosition(getPosition(node)));
    }
    return newNode;
}
Also used : BreakStatement(com.google.devtools.j2objc.ast.BreakStatement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) JavaFileObject(javax.tools.JavaFileObject)

Example 29 with SimpleName

use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.

the class TreeConverter method convertContinueStatement.

private TreeNode convertContinueStatement(JCTree.JCContinue node) {
    ContinueStatement newNode = new ContinueStatement();
    Object label = node.getLabel();
    if (label != null) {
        newNode.setLabel((SimpleName) new SimpleName(label.toString()).setPosition(getPosition(node)));
    }
    return newNode;
}
Also used : SimpleName(com.google.devtools.j2objc.ast.SimpleName) JavaFileObject(javax.tools.JavaFileObject) ContinueStatement(com.google.devtools.j2objc.ast.ContinueStatement)

Example 30 with SimpleName

use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.

the class JavadocGenerator method printTagFragments.

private String printTagFragments(List<TreeNode> fragments) {
    if (fragments.isEmpty()) {
        return "";
    }
    StringBuilder sb = new StringBuilder();
    int lineNo = fragments.get(0).getLineNumber();
    for (TreeNode fragment : fragments) {
        if (fragment.getLineNumber() > lineNo) {
            sb.append("\n ");
            lineNo = fragment.getLineNumber();
        }
        if (fragment instanceof TextElement) {
            if (spanningPreTag) {
                sb.append(getSourceIndent(fragment));
            }
            String text = escapeDocText(((TextElement) fragment).getText());
            sb.append(text);
        } else if (fragment instanceof TagElement) {
            sb.append(printTag((TagElement) fragment));
        } else if (fragment instanceof SimpleName) {
            Element element = ((Name) fragment).getElement();
            if (element != null && ElementUtil.isVariable(element)) {
                sb.append(NameTable.getDocCommentVariableName(((VariableElement) element)));
            } else {
                sb.append(fragment.toString());
            }
        } else {
            sb.append(fragment.toString().trim());
        }
    }
    return sb.toString();
}
Also used : TextElement(com.google.devtools.j2objc.ast.TextElement) TreeNode(com.google.devtools.j2objc.ast.TreeNode) SimpleName(com.google.devtools.j2objc.ast.SimpleName) TagElement(com.google.devtools.j2objc.ast.TagElement) VariableElement(javax.lang.model.element.VariableElement) Element(javax.lang.model.element.Element) TextElement(com.google.devtools.j2objc.ast.TextElement) TagElement(com.google.devtools.j2objc.ast.TagElement) Name(com.google.devtools.j2objc.ast.Name) SimpleName(com.google.devtools.j2objc.ast.SimpleName)

Aggregations

SimpleName (com.google.devtools.j2objc.ast.SimpleName)48 VariableElement (javax.lang.model.element.VariableElement)26 Expression (com.google.devtools.j2objc.ast.Expression)25 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)16 GeneratedVariableElement (com.google.devtools.j2objc.types.GeneratedVariableElement)16 TypeMirror (javax.lang.model.type.TypeMirror)15 ExpressionStatement (com.google.devtools.j2objc.ast.ExpressionStatement)14 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)14 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)13 VariableDeclarationStatement (com.google.devtools.j2objc.ast.VariableDeclarationStatement)13 ExecutablePair (com.google.devtools.j2objc.types.ExecutablePair)12 Block (com.google.devtools.j2objc.ast.Block)11 Statement (com.google.devtools.j2objc.ast.Statement)11 ExecutableElement (javax.lang.model.element.ExecutableElement)11 TypeElement (javax.lang.model.element.TypeElement)10 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)9 MethodInvocation (com.google.devtools.j2objc.ast.MethodInvocation)9 GeneratedExecutableElement (com.google.devtools.j2objc.types.GeneratedExecutableElement)9 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)8 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)8