当前位置: 首页>>代码示例>>Java>>正文


Java ExpressionTree类代码示例

本文整理汇总了Java中com.sun.source.tree.ExpressionTree的典型用法代码示例。如果您正苦于以下问题:Java ExpressionTree类的具体用法?Java ExpressionTree怎么用?Java ExpressionTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ExpressionTree类属于com.sun.source.tree包,在下文中一共展示了ExpressionTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitMethodInvocation

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
@Override
public MethodArgument[] visitMethodInvocation(MethodInvocationTree node, Object p) {
    if (!methodInvocation || offset != positions.getEndPosition(tree, node.getMethodSelect())) {
        return super.visitMethodInvocation(node, p);
        /*MethodArgument[] r = scan(node.getTypeArguments(), p);
        r = scanAndReduce(node.getMethodSelect(), p, r);
        r = scanAndReduce(node.getArguments(), p, r);
        return r;*/
    }
    List<? extends ExpressionTree> args = node.getArguments();
    List<? extends Tree> argTypes = node.getTypeArguments();
    /*int n = args.size();
    arguments = new MethodArgument[n];
    for (int i = 0; i < n; i++) {
        arguments[i] = new MethodArgument(args.get(i).toString(), argTypes.get(i).toString());
    }
    return arguments;*/
    arguments = composeArguments(args, argTypes);
    return arguments;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:MethodArgumentsScanner.java

示例2: dotExpressionUpToArgs

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
private void dotExpressionUpToArgs(ExpressionTree expression, Optional<BreakTag> tyargTag) {
    expression = getArrayBase(expression);
    switch (expression.getKind()) {
        case MEMBER_SELECT:
            MemberSelectTree fieldAccess = (MemberSelectTree) expression;
            visit(fieldAccess.getIdentifier());
            break;
        case METHOD_INVOCATION:
            MethodInvocationTree methodInvocation = (MethodInvocationTree) expression;
            if (!methodInvocation.getTypeArguments().isEmpty()) {
                builder.open(plusFour);
                addTypeArguments(methodInvocation.getTypeArguments(), ZERO);
                // TODO(jdd): Should indent the name -4.
                builder.breakOp(Doc.FillMode.UNIFIED, "", ZERO, tyargTag);
                builder.close();
            }
            visit(getMethodName(methodInvocation));
            break;
        case IDENTIFIER:
            visit(((IdentifierTree) expression).getName());
            break;
        default:
            scan(expression, null);
            break;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:27,代码来源:JavaInputAstVisitor.java

示例3: createMethod

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
private static MethodTree createMethod(WorkingCopy wc, MethodInfo mInfo) {
    TreeMaker make = wc.getTreeMaker();
    TypeInfo[] pTypes = mInfo.getParameterTypes();
    String[] pNames = mInfo.getParameterNames();
    List<VariableTree> params = new ArrayList<VariableTree>();
    for (int i = 0 ; pTypes != null && i < pTypes.length; i++) {
        VariableTree vtree = createVariable(wc, pNames[i], pTypes[i]);
        params.add(vtree);
    }
    
    TypeInfo[] excepTypes = mInfo.getExceptionTypes();
    List<ExpressionTree> throwsList = new ArrayList<ExpressionTree>();
    for (int i = 0 ; excepTypes != null && i < excepTypes.length; i++) {
        throwsList.add((ExpressionTree)createType(wc, excepTypes[i]));
    }
    
    String body = mInfo.getMethodBodyText();
    if(body == null) {
        body = "";
    }
    
    MethodTree mtree = make.Method(createModifiers(wc, mInfo.getModifiers(), mInfo.getAnnotations()),
            mInfo.getName(),
            createType(wc, mInfo.getReturnType()),
            Collections.<TypeParameterTree>emptyList(),
            params,
            throwsList,
            "{" + body + "}",
            null
            );
    
    //         if(mInfo.getCommentText() != null) {
    //             Comment comment = Comment.create(Comment.Style.JAVADOC, -2,
    //                     -2, -2, mInfo.getCommentText());
    //             make.addComment(mtree, comment, true);
    //         }
    
    return mtree;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:JpaControllerUtil.java

示例4: defineNewHandler

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
/**
 * Defines a new method as event handler, and marks it with @FXML annotation.
 * 
 * @param h handler definition
 */
private void defineNewHandler(CharSequence handlerName, TypeElement eventType) {
    TreeMaker mk = wcopy.getTreeMaker();
    
    // @FXML private void {handlerName}({eventType} event);
    MethodTree handler = mk.Method(
            mk.Modifiers(Collections.singleton(Modifier.PRIVATE), 
                Collections.singletonList(fxmlAnnotationTree)
            ),
            handlerName, 
            mk.PrimitiveType(TypeKind.VOID),
            Collections.<TypeParameterTree>emptyList(),
            Collections.singletonList(
                mk.Variable(
                    mk.Modifiers(Collections.<Modifier>emptySet()), 
                    "event", mk.Type(eventType.asType()), null)
            ), 
            Collections.<ExpressionTree>emptyList(),
            mk.Block(Collections.<StatementTree>emptyList(), false), 
            null);
    
    // add to class
    controllerClass = genUtils().insertClassMember(controllerClass, handler);
    addMethod(handlerName.toString(), eventType.asType());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:ControllerGenerator.java

示例5: generateStubTestMethod

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
protected ClassTree generateStubTestMethod(ClassTree tstClass,
                                           String testMethodName,
                                           WorkingCopy workingCopy) {
    List<? extends Tree> tstMembersOrig = tstClass.getMembers();
    List<Tree> tstMembers = new ArrayList<Tree>(tstMembersOrig.size() + 4);
    tstMembers.addAll(tstMembersOrig);

    List<ExpressionTree> throwsList = Collections.emptyList();
    MethodTree method = composeNewTestMethod(
            STUB_TEST_NAME,
            generateStubTestMethodBody(workingCopy),
            throwsList,
            workingCopy);

    tstMembers.add(method);

    ClassTree newClass = workingCopy.getTreeMaker().Class(
            tstClass.getModifiers(),
            tstClass.getSimpleName(),
            tstClass.getTypeParameters(),
            tstClass.getExtendsClause(),
            (List<? extends ExpressionTree>) tstClass.getImplementsClause(),
            tstMembers);
    return newClass;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:AbstractTestGenerator.java

示例6: generateDefMethodBody

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
/**
 * Returns default body for the test method. The generated body will
 * contains the following lines:
 * <pre><code>
 * // TODO review the generated test code and remove the default call to fail.
 * fail("The test case is a prototype.");
 * </code></pre>
 * @param maker the tree maker
 * @return an {@literal ExpressionStatementTree} for the generated body.
 * @throws MissingResourceException
 * @throws IllegalStateException
 */
private ExpressionStatementTree generateDefMethodBody(TreeMaker maker)
                    throws MissingResourceException, IllegalStateException {
    String failMsg = NbBundle.getMessage(TestCreator.class,
                               "TestCreator.variantMethods.defaultFailMsg");
    MethodInvocationTree failMethodCall =
        maker.MethodInvocation(
            Collections.<ExpressionTree>emptyList(),
            maker.Identifier("fail"),
            Collections.<ExpressionTree>singletonList(
                                                   maker.Literal(failMsg)));
    ExpressionStatementTree exprStatement =
        maker.ExpressionStatement(failMethodCall);
    if (setup.isGenerateMethodBodyComment()) {
        Comment comment =
            Comment.create(Comment.Style.LINE, -2, -2, -2,
                           NbBundle.getMessage(AbstractTestGenerator.class,
                              "TestCreator.variantMethods.defaultComment"));
        maker.addComment(exprStatement, comment, true);
    }
    return exprStatement;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:AbstractTestGenerator.java

示例7: visitRegularDot

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
/**
 * Output a "regular" chain of dereferences, possibly in builder-style. Break before every dot.
 *
 * @param items   in the chain
 * @param needDot whether a leading dot is needed
 */
private void visitRegularDot(List<ExpressionTree> items, boolean needDot) {
    boolean trailingDereferences = items.size() > 1;
    boolean needDot0 = needDot;
    if (!needDot0) {
        builder.open(plusFour);
    }
    // don't break after the first element if it is every small, unless the
    // chain starts with another expression
    int minLength = indentMultiplier * 4;
    int length = needDot0 ? minLength : 0;
    for (ExpressionTree e : items) {
        if (needDot) {
            if (length > minLength) {
                builder.breakOp(FillMode.UNIFIED, "", ZERO);
            }
            token(".");
            length++;
        }
        if (!fillFirstArgument(e, items, trailingDereferences ? ZERO : minusFour)) {
            BreakTag tyargTag = genSym();
            dotExpressionUpToArgs(e, Optional.of(tyargTag));
            Indent tyargIndent = Indent.If.make(tyargTag, plusFour, ZERO);
            dotExpressionArgsAndParen(
                    e, tyargIndent, (trailingDereferences || needDot) ? plusFour : ZERO);
        }
        length += getLength(e, getCurrentPath());
        needDot = true;
    }
    if (!needDot0) {
        builder.close();
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:39,代码来源:JavaInputAstVisitor.java

示例8: composeNewTestClass

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
/**
 */
@Override
protected ClassTree composeNewTestClass(WorkingCopy workingCopy,
                                        String name,
                                        List<? extends Tree> members) {
    final TreeMaker maker = workingCopy.getTreeMaker();
    ModifiersTree modifiers = maker.Modifiers(
                                  Collections.<Modifier>singleton(PUBLIC));
    return maker.Class(
                modifiers,                                 //modifiers
                name,                                      //name
                Collections.<TypeParameterTree>emptyList(),//type params
                null,                                      //extends
                Collections.<ExpressionTree>emptyList(),   //implements
                members);                                  //members
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:TestGenerator.java

示例9: visitPackage

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
private void visitPackage(
        ExpressionTree packageName, List<? extends AnnotationTree> packageAnnotations) {
    if (!packageAnnotations.isEmpty()) {
        for (AnnotationTree annotation : packageAnnotations) {
            builder.forcedBreak();
            scan(annotation, null);
        }
        builder.forcedBreak();
    }
    builder.open(plusFour);
    token("package");
    builder.space();
    visitName(packageName);
    builder.close();
    token(";");
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:17,代码来源:JavaInputAstVisitor.java

示例10: createAssignmentConstructor

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
/**
 * Creates a constructor which assigns its parameters to fields with the
 * same names. For example it can be used to generate:
 *
 * <pre>
 * public void Constructor(String field1, Object field2) {
 *     this.field1 = field1;
 *     this.field2 = field2;
 * }
 * </pre>
 *
 * @param  modifiersTree the constructor modifiers.
 * @param  constructorName the constructor name; cannot be null, it's not used inside except for assertion since 2007 (or before, TODO: remove?)
 * @param  parameters the constructor parameters; cannot be null.
 * @return the new constructor; never null.
 */
public MethodTree createAssignmentConstructor(ModifiersTree modifiersTree, String constructorName, List<VariableTree> parameters) {
    Parameters.notNull("modifiersTree", modifiersTree);
    Parameters.javaIdentifier("constructorName", constructorName); // NOI18N
    Parameters.notNull("parameters", parameters); // NOI18N

    StringBuilder body = new StringBuilder(parameters.size() * 30);
    body.append("{"); // NOI18N
    for (VariableTree parameter : parameters) {
        String parameterName = parameter.getName().toString();
        body.append("this." + parameterName + " = " + parameterName + ";"); // NOI18N
    }
    body.append("}"); // NOI18N

    TreeMaker make = getTreeMaker();
    return make.Constructor(
            modifiersTree,
            Collections.<TypeParameterTree>emptyList(),
            parameters,
            Collections.<ExpressionTree>emptyList(),
            body.toString());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:GenerationUtils.java

示例11: visitSingleMemberAnnotation

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
boolean visitSingleMemberAnnotation(AnnotationTree node) {
    if (node.getArguments().size() != 1) {
        return false;
    }
    ExpressionTree value = Iterables.getOnlyElement(node.getArguments());
    if (value.getKind() == ASSIGNMENT) {
        return false;
    }
    boolean isArrayInitializer = value.getKind() == NEW_ARRAY;
    builder.open(isArrayInitializer ? ZERO : plusFour);
    token("@");
    scan(node.getAnnotationType(), null);
    token("(");
    if (!isArrayInitializer) {
        builder.breakOp();
    }
    scan(value, null);
    builder.close();
    token(")");
    return true;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:22,代码来源:JavaInputAstVisitor.java

示例12: performRewrite

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath tp = ctx.getPath();
    TypeMirror targetType = this.type.resolve(wc);
    
    if (targetType == null) {
        //XXX: log
        return ;
    }
    
    TreeMaker make = wc.getTreeMaker();
    ExpressionTree nue = make.TypeCast(make.Type(targetType), (ExpressionTree) tp.getLeaf());
    
    if (JavaFixUtilities.requiresParenthesis(tp.getLeaf(), tp.getLeaf(), nue)) {
        nue = make.TypeCast(make.Type(targetType), make.Parenthesized((ExpressionTree) tp.getLeaf()));
    }
    
    wc.rewrite(tp.getLeaf(), nue);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:VarArgsCast.java

示例13: addSyntheticTrees

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
private void addSyntheticTrees(DiffContext diffContext, Tree node) {
    if (node == null) return ;
    
    if (((JCTree) node).pos == (-1)) {
        diffContext.syntheticTrees.add(node);
        return ;
    }
    
    if (node.getKind() == Kind.EXPRESSION_STATEMENT) {
        ExpressionTree est = ((ExpressionStatementTree) node).getExpression();

        if (est.getKind() == Kind.METHOD_INVOCATION) {
            ExpressionTree select = ((MethodInvocationTree) est).getMethodSelect();

            if (select.getKind() == Kind.IDENTIFIER && ((IdentifierTree) select).getName().contentEquals("super")) {
                if (getTreeUtilities().isSynthetic(diffContext.origUnit, node)) {
                    diffContext.syntheticTrees.add(node);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:WorkingCopy.java

示例14: performRewrite

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
    TreePath p = ctx.getPath();
    if (p.getLeaf().getKind() != Tree.Kind.NEW_CLASS) {
        return;
    }
    NewClassTree origNct = (NewClassTree)p.getLeaf();
    if (origNct.getArguments().size() != 1) {
        return;
    }
    NewClassTree nct = GeneratorUtilities.get(ctx.getWorkingCopy()).importComments(origNct, ctx.getWorkingCopy().getCompilationUnit());
    ExpressionTree charArg = nct.getArguments().get(0);
    TreeMaker mk = ctx.getWorkingCopy().getTreeMaker();
    
    ExpressionTree newExpr = mk.NewClass(nct.getEnclosingExpression(), (List<ExpressionTree>)nct.getTypeArguments(), nct.getIdentifier(), 
            Collections.<ExpressionTree>emptyList(), nct.getClassBody());

    Tree replace = mk.MethodInvocation(
            Collections.<ExpressionTree>emptyList(), 
            mk.MemberSelect(newExpr, "append"), // NOI18N
            Collections.singletonList(charArg));
    ctx.getWorkingCopy().rewrite(nct, replace);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:StringBufferCharConstructor.java

示例15: isCorrectType

import com.sun.source.tree.ExpressionTree; //导入依赖的package包/类
/**
 * In the numeric case, accept both primitives and boxed types. Each boxed type is
 * convertible to the appropriate primitive, and all primitive types are assignable to double.
 */
private boolean isCorrectType(ExpressionTree t) {
    if (currentMatches) {
        return true;
    }
    TypeMirror tm = info.getTrees().getTypeMirror(getCurrentPath());
    switch (tm.getKind()) {
        case BOOLEAN:
            return logical;
        case BYTE:
        case DOUBLE:
        case FLOAT:
        case INT:
        case LONG:
        case SHORT:
            return !logical;
        case DECLARED:
            // can be converted to primitive
            return info.getTypes().isAssignable(tm, info.getTypes().getPrimitiveType(TypeKind.DOUBLE));
        default:
            return false;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ExpressionVisitor.java


注:本文中的com.sun.source.tree.ExpressionTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。