本文整理匯總了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;
}
示例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;
}
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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();
}
}
示例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
}
示例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(";");
}
示例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());
}
示例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;
}
示例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);
}
示例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);
}
}
}
}
}
示例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);
}
示例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;
}
}