本文整理汇总了Java中com.sun.source.tree.AssignmentTree类的典型用法代码示例。如果您正苦于以下问题:Java AssignmentTree类的具体用法?Java AssignmentTree怎么用?Java AssignmentTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AssignmentTree类属于com.sun.source.tree包,在下文中一共展示了AssignmentTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWrapAssignment
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
public void testWrapAssignment() throws Exception {
String code = "package hierbas.del.litoral;\n\n" +
"import java.util.concurrent.atomic.AtomicBoolean;\n\n" +
"public class Test {\n" +
" public void t(AtomicBoolean ab) {\n" +
" new AtomicBoolean();\n" +
" }\n" +
"}\n";
runWrappingTest(code, new Task<WorkingCopy>() {
public void run(WorkingCopy workingCopy) throws IOException {
workingCopy.toPhase(Phase.RESOLVED);
CompilationUnitTree cut = workingCopy.getCompilationUnit();
TreeMaker make = workingCopy.getTreeMaker();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree method = (MethodTree) clazz.getMembers().get(1);
ExpressionStatementTree init = (ExpressionStatementTree) method.getBody().getStatements().get(0);
AssignmentTree bt = make.Assignment(make.Identifier("ab"), init.getExpression());
workingCopy.rewrite(init, make.ExpressionStatement(bt));
}
}, FmtOptions.wrapAssignOps, WrapStyle.WRAP_IF_LONG.name());
}
示例2: visitAssignment
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
@Override
public Void visitAssignment(AssignmentTree tree, EnumSet<UseTypes> d) {
handlePossibleIdentifier(new TreePath(getCurrentPath(), tree.getVariable()), EnumSet.of(UseTypes.WRITE));
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;
}
示例3: findValue
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
public static ExpressionTree findValue(AnnotationTree m, String name) {
for (ExpressionTree et : m.getArguments()) {
if (et.getKind() == Kind.ASSIGNMENT) {
AssignmentTree at = (AssignmentTree) et;
String varName = ((IdentifierTree) at.getVariable()).getName().toString();
if (varName.equals(name)) {
return at.getExpression();
}
}
if (et instanceof LiteralTree/*XXX*/ && "value".equals(name)) {
return et;
}
}
return null;
}
示例4: hasNonCleanUpUsages
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
private static boolean hasNonCleanUpUsages(
final Collection<? extends TreePath> usages,
final Collection<? super TreePath> cleanupStatements) {
for (TreePath usage : usages) {
final TreePath parentPath = usage.getParentPath();
final Tree parent = parentPath.getLeaf();
if (parent.getKind() != Tree.Kind.ASSIGNMENT) {
return true;
}
final AssignmentTree assign = (AssignmentTree) parent;
if (assign.getVariable() != usage.getLeaf()) {
return true;
}
if (assign.getExpression().getKind() != Tree.Kind.NULL_LITERAL) {
return true;
}
final TreePath parentParent = parentPath.getParentPath();
if (parentParent.getLeaf().getKind() != Tree.Kind.EXPRESSION_STATEMENT) {
return true;
}
cleanupStatements.add(parentParent);
}
return false;
}
示例5: isAssigned
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
private static boolean isAssigned(
final Element what,
final Iterable<? extends TreePath> where,
final Trees trees) {
ErrorAwareTreePathScanner<Boolean, Void> scanner = new ErrorAwareTreePathScanner<Boolean, Void>() {
@Override public Boolean visitAssignment(AssignmentTree node, Void p) {
if (trees.getElement(new TreePath(getCurrentPath(), node.getVariable())) == what) {
return true;
}
return super.visitAssignment(node, p);
}
@Override
public Boolean reduce(Boolean r1, Boolean r2) {
return r1 == Boolean.TRUE || r2 == Boolean.TRUE;
}
};
for (TreePath usage : where) {
if (scanner.scan(usage, null) == Boolean.TRUE) {
return true;
}
}
return false;
}
示例6: beautifyAssignement
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
private void beautifyAssignement(Tree currentTree, Set<Name> needed) {
AssignmentTree assigned = (AssignmentTree) ((ExpressionStatementTree) currentTree).getExpression();
ExpressionTree variable = assigned.getVariable();
if (variable.getKind() == Tree.Kind.IDENTIFIER) {
IdentifierTree id = (IdentifierTree) variable;
if (needed.contains(id.getName())) {
this.correspondingTree = treeMaker.ExpressionStatement(assigned.getExpression());
} else {
this.correspondingTree = this.addReturn(castToStatementTree(currentTree), getOneFromSet(needed));
}
} else {
this.correspondingTree = this.addReturn(castToStatementTree(currentTree), getOneFromSet(needed));
}
}
示例7: assignsTo
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
/**
* Determines whether the catch exception parameter is assigned to.
*
* @param ctx HintContext - for CompilationInfo
* @param variable the inspected variable
* @param statements statements that should be checked for assignment
* @return true if 'variable' is assigned to within 'statements'
*/
public static boolean assignsTo(final HintContext ctx, TreePath variable, Iterable<? extends TreePath> statements) {
final Element tEl = ctx.getInfo().getTrees().getElement(variable);
if (tEl == null || tEl.getKind() != ElementKind.EXCEPTION_PARAMETER) return true;
final boolean[] result = new boolean[1];
for (TreePath tp : statements) {
new ErrorAwareTreePathScanner<Void, Void>() {
@Override
public Void visitAssignment(AssignmentTree node, Void p) {
if (tEl.equals(ctx.getInfo().getTrees().getElement(new TreePath(getCurrentPath(), node.getVariable())))) {
result[0] = true;
}
return super.visitAssignment(node, p);
}
}.scan(tp, null);
}
return result[0];
}
示例8: handleAssignment
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
private List<ErrorDescription> handleAssignment(CompilationInfo info, TreePath treePath) {
AssignmentTree at = (AssignmentTree) treePath.getLeaf();
String declarationName = getName(at.getVariable());
String actualName = getName(at.getExpression());
if (isConflicting(info, declarationName, actualName)) {
long start = info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), at.getVariable());
long end = info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), at.getVariable());
if (start != (-1) && end != (-1)) {
return Collections.singletonList(ErrorDescriptionFactory.createErrorDescription(getSeverity().toEditorSeverity(), "Suspicious names combination", info.getFileObject(), (int) start, (int) end));
}
}
return null;
}
示例9: visitAssignment
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
@Override
public Boolean visitAssignment(AssignmentTree node, ConstructorData p) {
TypeElement oldQName = this.referenceTarget;
this.referenceTarget = null;
lValueDereference = true;
scan(node.getVariable(), null);
lValueDereference = false;
Boolean constVal = scan(node.getExpression(), p);
Element e = info.getTrees().getElement(new TreePath(getCurrentPath(), node.getVariable()));
if (e != null) {
if (SUPPORTED_VARIABLES.contains(e.getKind())) {
recordVariableState(e, new TreePath(getCurrentPath(), node.getExpression()));
} else if (shouldProcessUndefined(e)) {
Element cv = canonicalUndefined(e);
recordVariableState(e, new TreePath(getCurrentPath(), node.getExpression()));
}
}
this.referenceTarget = oldQName;
return constVal;
}
示例10: resolveResourceVariable
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
private void resolveResourceVariable(final WorkingCopy wc, TreePath tp, TreeMaker make, TypeMirror proposedType) {
final String name = ((IdentifierTree) tp.getLeaf()).getName().toString();
final Element el = wc.getTrees().getElement(tp);
if (el == null) {
return;
}
if (tp.getParentPath().getLeaf().getKind() != Kind.ASSIGNMENT) {
//?
return ;
}
AssignmentTree at = (AssignmentTree) tp.getParentPath().getLeaf();
VariableTree vt = make.Variable(make.Modifiers(EnumSet.noneOf(Modifier.class)), name, make.Type(proposedType), at.getExpression());
wc.rewrite(at, vt);
}
示例11: visitAssignment
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
/**
* If we're assigning to an identifier then we see if this identifier has the same name as one of the
* non-final params in scope. We only care about assignments to an identifier.
*
* Thus, a = 5; would be flagged by array[0] = "foo" would not be flagged. The left hand side of the assignment
* operation must be an identifier in order for us to flag it.
*
* @param assignmentTree assignment AST node
* @param nonFinalParamsInScope params to check against the LHS of the assignment
*/
@Override
public Void visitAssignment(AssignmentTree assignmentTree, Set<Name> nonFinalParamsInScope) {
if (nonFinalParamsInScope != null && !nonFinalParamsInScope.isEmpty()) {
ExpressionTree variable = assignmentTree.getVariable();
variable.accept(new SimpleTreeVisitor<Void, Void>() {
@Override
public Void visitIdentifier(IdentifierTree node, Void aVoid) {
if (nonFinalParamsInScope.contains(node.getName())) {
// printing a message of type error counts as a compilation error
trees.printMessage(Diagnostic.Kind.ERROR,
String.format("EFFECTIVELY_FINAL: Assignment to param in `%s`", assignmentTree),
node, compilationUnitTree);
}
return null;
}
}, null);
}
return null;
}
示例12: visitAnnotation
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
@Override
public String visitAnnotation(AnnotationTree node, Void p) {
for (ExpressionTree expressionTree : node.getArguments()) {
if (expressionTree instanceof AssignmentTree) {
AssignmentTree assignmentTree = (AssignmentTree) expressionTree;
ExpressionTree variable = assignmentTree.getVariable();
if (variable instanceof IdentifierTree && ((IdentifierTree) variable).getName().contentEquals(annotationFieldName)) {
return scan(expressionTree, p);
}
}
}
return null;
}
示例13: visitAnnotation
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
@Override
public Void visitAnnotation(AnnotationTree node, Map<ErrorDescription, Integer> p) {
Element e = ci.getTrees().getElement(getCurrentPath());
if (e != null) {
String annType = ((TypeElement)e).getQualifiedName().toString();
if (annType.startsWith("com.sun.btrace.annotations.")) { // NOI18N
isHandler = true;
if (annType.equals("com.sun.btrace.annotations.BTrace")) { // NOI18N
isBTraceClass = true;
for(ExpressionTree et : node.getArguments()) {
if (et.getKind() == Tree.Kind.ASSIGNMENT) {
String varName = ((AssignmentTree)et).getVariable().toString();
String varValue = ((AssignmentTree)et).getExpression().toString();
if (varName.equals("unsafe") && varValue.toLowerCase().equals("true")) { // NOI18N
isUnsafe = true;
}
}
}
}
}
}
return super.visitAnnotation(node, p);
}
示例14: visitAssignment
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
@Override
public Void visitAssignment(AssignmentTree node, Map<ErrorDescription, Integer> p) {
if (isUnsafe) return super.visitAssignment(node, p);
Tree varTree = node.getVariable();
TreePath tp = ci.getTrees().getPath(ci.getCompilationUnit(), varTree);
Element e = tp != null ? ci.getTrees().getElement(tp) : null;
if (e != null && e.getKind().isField()) {
Element parent = e.getEnclosingElement();
if (parent != null && (parent.getKind().isClass() || parent.getKind().isInterface())) {
String typeName = ((TypeElement)parent).getQualifiedName().toString();
if (!(typeName.equals(btraceClassName) ||
typeName.equals("com.cun.btrace.BTraceUtils") || // NOI18N
typeName.startsWith("com.sun.btrace.BTraceUtils$"))) { // NOI18N
addError(node, ERR_NO_ASSIGNMENT, p);
}
}
}
return super.visitAssignment(node, p);
}
示例15: assertCompilerMatchesOnAssignment
import com.sun.source.tree.AssignmentTree; //导入依赖的package包/类
private void assertCompilerMatchesOnAssignment(
final Map<String, Boolean> expectedMatches, String... lines) {
final Matcher<ExpressionTree> matcher = new CompileTimeConstantExpressionMatcher();
final Scanner scanner =
new Scanner() {
@Override
public Void visitAssignment(AssignmentTree t, VisitorState state) {
ExpressionTree lhs = t.getVariable();
if (expectedMatches.containsKey(lhs.toString())) {
boolean matches = matcher.matches(t.getExpression(), state);
if (expectedMatches.get(lhs.toString())) {
assertTrue("Matcher should match expression" + t.getExpression(), matches);
} else {
assertFalse("Matcher should not match expression" + t.getExpression(), matches);
}
}
return super.visitAssignment(t, state);
}
};
CompilationTestHelper.newInstance(ScannerSupplier.fromScanner(scanner), getClass())
.expectResult(Result.OK)
.addSourceLines("test/CompileTimeConstantExpressionMatcherTestCase.java", lines)
.doTest();
}