本文整理汇总了Java中com.sun.tools.javac.tree.JCTree.JCAssign类的典型用法代码示例。如果您正苦于以下问题:Java JCAssign类的具体用法?Java JCAssign怎么用?Java JCAssign使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JCAssign类属于com.sun.tools.javac.tree.JCTree包,在下文中一共展示了JCAssign类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitAnnotation
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
@Override public void visitAnnotation(JCAnnotation tree) {
print("@");
print(tree.annotationType);
if (tree.args.isEmpty()) return;
print("(");
boolean done = false;
if (tree.args.length() == 1 && tree.args.get(0) instanceof JCAssign) {
JCAssign arg1 = (JCAssign) tree.args.get(0);
JCIdent arg1Name = arg1.lhs instanceof JCIdent ? ((JCIdent) arg1.lhs) : null;
if (arg1Name != null && arg1Name.name == name_value(arg1Name.name)) {
print(arg1.rhs);
done = true;
}
}
if (!done) print(tree.args, ", ");
print(")");
}
示例2: visitAnnotation
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
public void visitAnnotation(JCAnnotation tree) {
try {
print("@");
printExpr(tree.annotationType);
if (tree.args.nonEmpty()) {
print("(");
if (tree.args.length() == 1 && tree.args.get(0) instanceof JCAssign) {
JCExpression lhs = ((JCAssign)tree.args.get(0)).lhs;
if (lhs instanceof JCIdent && ((JCIdent)lhs).name.toString().equals("value")) tree.args = List.of(((JCAssign)tree.args.get(0)).rhs);
}
printExprs(tree.args);
print(")");
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例3: isAllVariableInitialized
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
/**
* Verify if all variables were initialized on the constructor.
* @param block The lines of the constructor.
* @return true if all variables were initialized on the constructor.
*/
private boolean isAllVariableInitialized(JCBlock block) {
for (com.sun.tools.javac.util.List<JCStatement> traversing = block.stats; !traversing.isEmpty(); traversing = traversing.tail){
if(traversing.head instanceof JCExpressionStatement){
if(((JCExpressionStatement) traversing.head).expr instanceof JCAssign
&& !((JCAssign) ((JCExpressionStatement) traversing.head).expr).rhs.toString().equals("null")){
String toTest = ((JCAssign) ((JCExpressionStatement) traversing.head).expr).lhs.toString();
int i = 0; boolean isNecessaryToRemove = false;
for(i = 0; i < this.variables.size(); i++){
if(toTest.equals(this.variables.get(i)) || toTest.equals("this." + this.variables.get(i))){
isNecessaryToRemove = true;
break;
}
}
if(isNecessaryToRemove)
this.variables.remove(i);
}
}
}
return this.variables.isEmpty();
}
示例4: visitAnnotation
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
public void visitAnnotation(JCAnnotation tree) {
try {
print("@");
printExpr(tree.annotationType);
if (tree.args.nonEmpty()) {
print("(");
if (tree.args.length() == 1 && tree.args.get(0) instanceof JCAssign) {
JCExpression lhs = ((JCAssign)tree.args.get(0)).lhs;
if (lhs instanceof JCIdent && ((JCIdent)lhs).name.toString().equals("value")) tree.args = List.of(((JCAssign)tree.args.get(0)).rhs);
}
printExprs(tree.args);
print(")");
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例5: diffAssign
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
protected int diffAssign(JCAssign oldT, JCAssign newT, JCTree parent, int[] bounds) {
int localPointer = bounds[0];
// lhs
int[] lhsBounds = getBounds(oldT.lhs);
if (lhsBounds[0] < 0) {
lhsBounds[0] = getOldPos(oldT.rhs);
lhsBounds[1] = -1;
}
copyTo(localPointer, lhsBounds[0]);
localPointer = diffTree(oldT.lhs, newT.lhs, lhsBounds);
int[] rhsBounds = getCommentCorrectedBounds(oldT.rhs);
//#174552: '=' may be missing if this is a synthetic annotation attribute assignment (of attribute name "value"):
if ( oldT.lhs.getKind() == Kind.IDENTIFIER
&& newT.lhs.getKind() == Kind.IDENTIFIER
&& !((JCIdent) oldT.lhs).name.equals(((JCIdent) newT.lhs).name)) {
tokenSequence.move(rhsBounds[0]);
moveToSrcRelevant(tokenSequence, Direction.BACKWARD);
if (tokenSequence.token().id() != JavaTokenId.EQ) {
boolean spaceAroundAssignOps = (parent.getKind() == Kind.ANNOTATION || parent.getKind() == Kind.TYPE_ANNOTATION) ? diffContext.style.spaceAroundAnnotationValueAssignOps() : diffContext.style.spaceAroundAssignOps();
if (spaceAroundAssignOps)
printer.print(" = ");
else
printer.print("=");
localPointer = lhsBounds[0];
}
}
//#174552 end
// rhs
copyTo(localPointer, rhsBounds[0]);
localPointer = diffTree(oldT.rhs, newT.rhs, rhsBounds);
copyTo(localPointer, bounds[1]);
return bounds[1];
}
示例6: visitAssign
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
@Override
public void visitAssign(JCAssign assignment) {
// super call comes first in order to ensure the correct sequence of valueChange triggers
super.visitAssign(assignment);
final JCTree.JCExpression assignmentVariable = assignment.getVariable();
if (doesContainMutation(assignmentVariable)) {
// for example in case of an array access we only need the array[index] combination instead of array[++index]
// so we can pass it to the GW.valueChange hook without producing side effects and altering the original behaviour
collect(extractAssignmentTarget(assignmentVariable));
}
else {
collect(assignmentVariable);
}
}
示例7: doAssignmentCheck0
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
public void doAssignmentCheck0(JavacNode node, JCTree statement, Name name) {
if (statement instanceof JCAssign) doAssignmentCheck0(node, ((JCAssign)statement).rhs, name);
if (statement instanceof JCExpressionStatement) doAssignmentCheck0(node,
((JCExpressionStatement)statement).expr, name);
if (statement instanceof JCVariableDecl) doAssignmentCheck0(node, ((JCVariableDecl)statement).init, name);
if (statement instanceof JCTypeCast) doAssignmentCheck0(node, ((JCTypeCast)statement).expr, name);
if (statement instanceof JCIdent) {
if (((JCIdent)statement).name.contentEquals(name)) {
JavacNode problemNode = node.getNodeFor(statement);
if (problemNode != null) problemNode.addWarning(
"You're assigning an auto-cleanup variable to something else. This is a bad idea.");
}
}
}
示例8: visitAssign
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
public void visitAssign(JCAssign that) {
try {
print("JCAssign:");
} catch (Exception e) {
}
super.visitAssign(that);
}
示例9: visitAssign
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
public void visitAssign(JCAssign tree) {
try {
open(prec, TreeInfo.assignPrec);
printExpr(tree.lhs, TreeInfo.assignPrec + 1);
print(" = ");
printExpr(tree.rhs, TreeInfo.assignPrec);
close(prec, TreeInfo.assignPrec);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例10: process
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
@Override
public void process() {
fieldsMap.clear();
JavacElements utils = getEnvironment().getUtils();
Symbol.ClassSymbol viewByIdType = utils.getTypeElement(ANNOTATION_CLASS_NAME);
ViewWrapper viewWrapper = new ViewWrapper(utils);
BindableWrapper bindableWrapper = new BindableWrapper(utils);
Set<GField> allFields = getEnvironment().getGElementsAnnotatedWith(ViewById.class, GField.class);
for (GField field : allFields) {
JCTree.JCAnnotation annotation = field.extractAnnotation(viewByIdType);
JCTree fieldType = field.getTree().getType();
JCExpression value = annotation.getArguments().get(0);
if (value instanceof JCAssign) {
value = ((JCAssign) value).rhs;
}
if (!getEnvironment().getTypes().isSubtype(((Symbol.VarSymbol) field.getElement()).asType(), viewWrapper.getClassSymbol().asType())) {
getEnvironment().getMessager().printMessage(Diagnostic.Kind.ERROR,
"Annotation " + viewByIdType.getSimpleName() + " can be applied only to field with type extended of View",
field.getElement());
}
field.getGClass().implementInBestParent(bindableWrapper.getClassSymbol(), allFields);
field.getGClass().overrideMethod(bindableWrapper.getBindMethod(), true)
.prependCode("this.%s = (%s) $p0.findViewById(%s);", field.getName(), fieldType, value);
field.getGClass().overrideMethod(bindableWrapper.getUnbindMethod(), true)
.prependCode("this.%s = null;", field.getName());
Map<String, GField> classFieldsMap = fieldsMap.get(field.getGClass());
if (classFieldsMap == null) {
classFieldsMap = new HashMap<>();
fieldsMap.put(field.getGClass(), classFieldsMap);
}
classFieldsMap.put(value.toString(), field);
}
}
示例11: visitAssign
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
@Override public void visitAssign(JCAssign node) {
BinaryExpression expr = new BinaryExpression();
expr.rawRight(toTree(node.getExpression()));
expr.rawLeft(toTree(node.getVariable()));
expr.astOperator(BinaryOperator.ASSIGN);
set(node, expr);
}
示例12: visitAnnotation
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
@Override public void visitAnnotation(JCAnnotation node) {
Annotation a = new Annotation();
a.rawAnnotationTypeReference(toTree(node.getAnnotationType(), FlagKey.TYPE_REFERENCE));
for (JCExpression elem : node.getArguments()) {
AnnotationElement e = new AnnotationElement();
if (elem instanceof JCAssign) {
JCExpression rawName = ((JCAssign) elem).getVariable();
if (rawName instanceof JCIdent) e.astName(setPos(rawName, new Identifier().astValue(((JCIdent)rawName).getName().toString())));
elem = ((JCAssign) elem).getExpression();
}
e.rawValue(toTree(elem));
a.astElements().addToEnd(e);
}
set(node, a);
}
示例13: visitAssignment
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
@Override
public Choice<State<JCAssign>> visitAssignment(final AssignmentTree node, State<?> state) {
return chooseSubtrees(
state,
s -> unifyExpression(node.getVariable(), s),
s -> unifyExpression(node.getExpression(), s),
maker()::Assign)
.condition(s -> !(s.result().getVariable() instanceof PlaceholderParamIdent));
}
示例14: deleteExpectedException
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
/**
* Searches the annotation list for {@code @Test(expected=...)}. If found, deletes the exception
* attribute from the annotation, and returns its value.
*/
private static JCExpression deleteExpectedException(
SuggestedFix.Builder fix, List<JCAnnotation> annotations, VisitorState state) {
Type testAnnotation = state.getTypeFromString(JUnitMatchers.JUNIT4_TEST_ANNOTATION);
for (JCAnnotation annotationTree : annotations) {
if (!ASTHelpers.isSameType(testAnnotation, annotationTree.type, state)) {
continue;
}
com.sun.tools.javac.util.List<JCExpression> arguments = annotationTree.getArguments();
for (JCExpression arg : arguments) {
if (!arg.hasTag(Tag.ASSIGN)) {
continue;
}
JCAssign assign = (JCAssign) arg;
if (assign.lhs.hasTag(Tag.IDENT)
&& ((JCIdent) assign.lhs).getName().contentEquals("expected")) {
if (arguments.size() == 1) {
fix.replace(annotationTree, "@Test");
} else {
removeFromList(fix, state, arguments, assign);
}
return assign.rhs;
}
}
}
return null;
}
示例15: visitAssign
import com.sun.tools.javac.tree.JCTree.JCAssign; //导入依赖的package包/类
public void visitAssign(JCAssign tree) {
try {
open(prec, TreeInfo.assignPrec);
printExpr(tree.lhs, TreeInfo.assignPrec + 1);
print(" = ");
printExpr(tree.rhs, TreeInfo.assignPrec);
close(prec, TreeInfo.assignPrec);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}