本文整理汇总了Java中com.github.javaparser.ast.expr.AssignExpr.Operator类的典型用法代码示例。如果您正苦于以下问题:Java Operator类的具体用法?Java Operator怎么用?Java Operator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Operator类属于com.github.javaparser.ast.expr.AssignExpr包,在下文中一共展示了Operator类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSetter
import com.github.javaparser.ast.expr.AssignExpr.Operator; //导入依赖的package包/类
/**
* Create a setter for this field, <b>will only work if this field declares only 1 identifier and if this field is
* already added to a ClassOrInterfaceDeclaration</b>
*
* @return the {@link MethodDeclaration} created
* @throws IllegalStateException if there is more than 1 variable identifier or if this field isn't attached to a
* class or enum
*/
public MethodDeclaration createSetter() {
if (getVariables().size() != 1)
throw new IllegalStateException("You can use this only when the field declares only 1 variable name");
ClassOrInterfaceDeclaration parentClass = getParentNodeOfType(ClassOrInterfaceDeclaration.class);
EnumDeclaration parentEnum = getParentNodeOfType(EnumDeclaration.class);
if ((parentClass == null && parentEnum == null) || (parentClass != null && parentClass.isInterface()))
throw new IllegalStateException(
"You can use this only when the field is attached to a class or an enum");
VariableDeclarator variable = getVariables().get(0);
String fieldName = variable.getId().getName();
String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length());
final MethodDeclaration setter;
if (parentClass != null)
setter = parentClass.addMethod("set" + fieldNameUpper, PUBLIC);
else
setter = parentEnum.addMethod("set" + fieldNameUpper, PUBLIC);
setter.setType(VOID_TYPE);
setter.getParameters().add(new Parameter(variable.getType(), new VariableDeclaratorId(fieldName)));
BlockStmt blockStmt2 = new BlockStmt();
setter.setBody(blockStmt2);
blockStmt2.addStatement(new AssignExpr(new NameExpr("this." + fieldName), new NameExpr(fieldName), Operator.assign));
return setter;
}
示例2: visit
import com.github.javaparser.ast.expr.AssignExpr.Operator; //导入依赖的package包/类
@Override public void visit(AssignExpr n, Void arg) {
if(n.getOperator().equals(Operator.ASSIGN)) {
Expression target = n.getTarget();
if(isOldFieldName(target.toString())) {
n.setTarget(new NameExpr(m_fieldName));
}
}
super.visit(n, arg);
}
示例3: fieldAssignment
import com.github.javaparser.ast.expr.AssignExpr.Operator; //导入依赖的package包/类
/**
* Generates something like <code>field = newValue</code>
*
* @param fieldName
* @param valueName
* @return
*/
private static BlockStmt fieldAssignment(String fieldName, String valueName) {
BlockStmt body = new BlockStmt();
body.addStatement(
new ExpressionStmt(new AssignExpr(new NameExpr(fieldName), new NameExpr(valueName), Operator.ASSIGN)));
return body;
}