本文整理汇总了Java中com.sun.source.tree.CompoundAssignmentTree类的典型用法代码示例。如果您正苦于以下问题:Java CompoundAssignmentTree类的具体用法?Java CompoundAssignmentTree怎么用?Java CompoundAssignmentTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompoundAssignmentTree类属于com.sun.source.tree包,在下文中一共展示了CompoundAssignmentTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree tree, EnumSet<UseTypes> d) {
Set<UseTypes> useTypes = EnumSet.of(UseTypes.WRITE);
if (d != null) {
useTypes.addAll(d);
}
handlePossibleIdentifier(new TreePath(getCurrentPath(), tree.getVariable()), useTypes);
Tree expr = tree.getExpression();
if (expr instanceof IdentifierTree) {
TreePath tp = new TreePath(getCurrentPath(), expr);
handlePossibleIdentifier(tp, EnumSet.of(UseTypes.READ));
}
scan(tree.getVariable(), EnumSet.of(UseTypes.WRITE));
scan(tree.getExpression(), EnumSet.of(UseTypes.READ));
return null;
}
示例2: operatorName
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
/**
* Returns the string name of an operator, including assignment and compound assignment.
*/
static String operatorName(ExpressionTree expression) {
// JCTree.Tag tag = ((JCTree) expression).getTag();
// if (tag == JCTree.Tag.ASSIGN) {
// return "=";
// }
// boolean assignOp = expression instanceof CompoundAssignmentTree;
// if (assignOp) {
// tag = tag.noAssignOp();
// }
int tag = ((JCTree) expression).getTag();
if (tag == JCTree.ASSIGN) {
return "=";
}
boolean assignOp = expression instanceof CompoundAssignmentTree;
if (assignOp) {
// tag = tag.noAssignOp();
// TODO: 22-Jul-17 ?????
}
String name = new Pretty(/*writer*/ null, /*sourceOutput*/ true).operatorName(tag);
return assignOp ? name + "=" : name;
}
示例3: matchCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
/**
* Matchers when a string concatenates-and-assigns an array.
*/
@Override
public Description matchCompoundAssignment(CompoundAssignmentTree t, VisitorState state) {
if (!assignmentMatcher.matches(t, state)) {
return Description.NO_MATCH;
}
/*
* Replace instances of implicit array toString() calls due to string
* concatenation-and-assignment with Arrays.toString(array). Also adds
* the necessary import statement for java.util.Arrays.
*/
String receiver = t.getVariable().toString();
String expression = t.getExpression().toString();
Fix fix = new SuggestedFix()
.replace(t, receiver + " += Arrays.toString(" + expression + ")")
.addImport("java.util.Arrays");
return describeMatch(t, fix);
}
示例4: visitCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p) {
ExpressionTree var = node.getVariable();
ExpressionTree expr = node.getExpression();
AnnotatedTypeMirror varType = atypeFactory.getAnnotatedType(var);
AnnotatedTypeMirror exprType = atypeFactory.getAnnotatedType(expr);
Kind kind = node.getKind();
if ( (kind == Kind.PLUS_ASSIGNMENT || kind == Kind.MINUS_ASSIGNMENT)) {
if (!atypeFactory.getTypeHierarchy().isSubtype(exprType, varType)) {
checker.report(Result.failure("compound.assignment.type.incompatible",
varType, exprType), node);
}
} else if (exprType.getAnnotation(UnknownUnits.class) == null) {
// Only allow mul/div with unqualified units
checker.report(Result.failure("compound.assignment.type.incompatible",
varType, exprType), node);
}
return null; // super.visitCompoundAssignment(node, p);
}
示例5: visitCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
@Override
public Tree visitCompoundAssignment(CompoundAssignmentTree tree, Void p) {
CompoundAssignmentTree n = make.CompoundAssignment(tree.getKind(), tree.getVariable(), tree.getExpression());
model.setType(n, model.getType(tree));
comments.copyComments(tree, n);
model.setPos(n, model.getPos(tree));
return n;
}
示例6: visitCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
public Boolean visitCompoundAssignment(CompoundAssignmentTree node, TreePath p) {
if (p == null) {
super.visitCompoundAssignment(node, p);
return false;
}
CompoundAssignmentTree bt = (CompoundAssignmentTree) p.getLeaf();
boolean result = scan(node.getExpression(), bt.getExpression(), p);
return result && scan(node.getVariable(), bt.getVariable(), p);
}
示例7: visitCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree tree, List<Node> d) {
List<Node> below = new ArrayList<Node>();
addCorrespondingType(below);
addCorrespondingComments(below);
super.visitCompoundAssignment(tree, below);
d.add(new TreeNode(info, getCurrentPath(), below));
return null;
}
示例8: forIndexedArray
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
@TriggerPattern(value="for (int $index = 0; $index < $arr.length; $index++) $statement;", [email protected](variable="$arr", type="Object[]"))
public static ErrorDescription forIndexedArray(final HintContext ctx) {
AccessAndVarVisitor v = new AccessAndVarVisitor(ctx) {
@Override public Void visitArrayAccess(ArrayAccessTree node, Void p) {
TreePath path = getCurrentPath();
if (MatcherUtilities.matches(ctx, path, "$arr[$index]")) { // NOI18N
if (path.getParentPath() != null) {
if ( path.getParentPath().getLeaf().getKind() == Kind.ASSIGNMENT
&& ((AssignmentTree) path.getParentPath().getLeaf()).getVariable() == node) {
unsuitable();
}
if (CompoundAssignmentTree.class.isAssignableFrom(path.getParentPath().getLeaf().getKind().asInterface())
&& ((CompoundAssignmentTree) path.getParentPath().getLeaf()).getVariable() == node) {
unsuitable();
}
}
toReplace.add(path);
return null;
}
return super.visitArrayAccess(node, p);
}
};
v.scan(ctx.getVariables().get("$statement"), null); // NOI18N
if (v.unsuitable) return null;
return ErrorDescriptionFactory.forName(ctx, ctx.getPath(), Bundle.ERR_IteratorToForArray(),
new ReplaceIndexedForEachLoop(ctx.getInfo(), ctx.getPath(), ctx.getVariables().get("$arr"),
v.toReplace, v.definedVariables).toEditorFix());
}
示例9: handleCompoundAssignementReducer
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
private static ProspectiveOperation handleCompoundAssignementReducer(TreeMaker tm, ExpressionTree expr, OperationType operationType, PreconditionsChecker precond, WorkingCopy workingCopy, List<ProspectiveOperation> ls, ProspectiveOperation redOp) {
//this variable will be removed at a later stage.
VariableTree var = tm.Variable(tm.Modifiers(new HashSet<Modifier>()), "dummyVar18912", tm.Type("Object"), ((CompoundAssignmentTree) expr).getExpression());
ProspectiveOperation map = new ProspectiveOperation(var, operationType.MAP, precond.getInnerVariables(), workingCopy, precond.getVarToName());
map.getAvailableVariables().add(var.getName());
ls.add(map);
redOp = new ProspectiveOperation(expr, operationType, precond.getInnerVariables(), workingCopy, precond.getVarToName());
redOp.neededVariables = new HashSet<Name>();
redOp.neededVariables.add(var.getName());
redOp.reducingVariable = ((CompoundAssignmentTree) expr).getVariable();
return redOp;
}
示例10: makeParenthesis
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
private ExpressionTree makeParenthesis(ExpressionTree arg) {
Class c = arg.getKind().asInterface();
// if the original append argument was an expression, surround it in parenthesis, to get the same toString effect
if (c == BinaryTree.class || c == UnaryTree.class || c == CompoundAssignmentTree.class || c == AssignmentTree.class ||
c == ConditionalExpressionTree.class) {
return mk.Parenthesized(arg);
} else {
return arg;
}
}
示例11: assignmentToMethodParam
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
@Hint(displayName = "#DN_org.netbeans.modules.java.hints.AssignmentIssues.assignmentToMethodParam", description = "#DESC_org.netbeans.modules.java.hints.AssignmentIssues.assignmentToMethodParam", category = "assignment_issues", enabled = false, suppressWarnings = "AssignmentToMethodParameter", options=Options.QUERY) //NOI18N
@TriggerTreeKind({Kind.ASSIGNMENT, Kind.AND_ASSIGNMENT, Kind.DIVIDE_ASSIGNMENT,
Kind.LEFT_SHIFT_ASSIGNMENT, Kind.MINUS_ASSIGNMENT, Kind.MULTIPLY_ASSIGNMENT,
Kind.OR_ASSIGNMENT, Kind.PLUS_ASSIGNMENT, Kind.REMAINDER_ASSIGNMENT, Kind.RIGHT_SHIFT_ASSIGNMENT,
Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT, Kind.XOR_ASSIGNMENT, Kind.PREFIX_INCREMENT,
Kind.PREFIX_DECREMENT, Kind.POSTFIX_INCREMENT, Kind.POSTFIX_DECREMENT})
public static ErrorDescription assignmentToMethodParam(HintContext context) {
final TreePath path = context.getPath();
Element element = null;
switch (path.getLeaf().getKind()) {
case ASSIGNMENT:
element = context.getInfo().getTrees().getElement(TreePath.getPath(path, ((AssignmentTree) path.getLeaf()).getVariable()));
break;
case PREFIX_INCREMENT:
case PREFIX_DECREMENT:
case POSTFIX_INCREMENT:
case POSTFIX_DECREMENT:
element = context.getInfo().getTrees().getElement(TreePath.getPath(path, ((UnaryTree) path.getLeaf()).getExpression()));
break;
default:
element = context.getInfo().getTrees().getElement(TreePath.getPath(path, ((CompoundAssignmentTree) path.getLeaf()).getVariable()));
}
if (element != null && element.getKind() == ElementKind.PARAMETER) {
return ErrorDescriptionFactory.forTree(context, path, NbBundle.getMessage(AssignmentIssues.class, "MSG_AssignmentToMethodParam", element.getSimpleName())); //NOI18N
}
return null;
}
示例12: visitCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree node, List<TreePath> p) {
if (param == trees.getElement(TreePath.getPath(getCurrentPath(), node.getVariable()))) {
p.add(getCurrentPath());
return null;
}
return super.visitCompoundAssignment(node, p);
}
示例13: visitCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
/**
* Compound assignment expects the assigned-to variable's type.
*/
@Override
public List<? extends TypeMirror> visitCompoundAssignment(CompoundAssignmentTree node, Object p) {
if (theExpression == null) {
initExpression(new TreePath(getCurrentPath(), node.getExpression()));
}
return Collections.singletonList(info.getTrees().getTypeMirror(new TreePath(getCurrentPath(), node.getVariable())));
}
示例14: visitCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void unused) {
sync(node);
builder.open(plusFour);
scan(node.getVariable(), null);
builder.space();
splitToken(operatorName(node));
builder.breakOp(" ");
scan(node.getExpression(), null);
builder.close();
return null;
}
示例15: visitCompoundAssignment
import com.sun.source.tree.CompoundAssignmentTree; //导入依赖的package包/类
@Override
@Nullable
public Unifier visitCompoundAssignment(
CompoundAssignmentTree assignOp, @Nullable Unifier unifier) {
unifier = (getKind() == assignOp.getKind()) ? unifier : null;
unifier = getVariable().unify(assignOp.getVariable(), unifier);
return getExpression().unify(assignOp.getExpression(), unifier);
}