本文整理汇总了Java中com.github.javaparser.ast.expr.AssignExpr类的典型用法代码示例。如果您正苦于以下问题:Java AssignExpr类的具体用法?Java AssignExpr怎么用?Java AssignExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssignExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了AssignExpr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: parseWhileStatement
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
/**
*
* @param ws
* a github javaparser whileStatement
* @param attributes
* the list of attributes of the class,
* to potentially get a type from the name
* @param bd
* a body declaration
* @return
* a LoopStatement structure
*/
private LoopStatement parseWhileStatement(WhileStmt ws, List<Attribute> attributes, BodyDeclaration bd) {
LoopStatement ls = new LoopStatement();
List<Stmt> initialisation = null;
if (ws.getCondition() != null) {
if (ws.getCondition() instanceof AssignExpr) {
initialisation = new ArrayList<>();
initialisation.addAll(parseAssignExpression((AssignExpr) ws.getCondition(), attributes, bd.getBeginLine()));
} else {
ls.setCondition(parseExpression(ws.getCondition(), attributes, bd.getBeginLine()));
}
}
ls.setInitialization(initialisation);
ls.setBody(parseStatement(ws.getBody(), attributes, bd));
ls.setLine(ws.getBeginLine() - bd.getBeginLine());
return ls;
}
开发者ID:DevMine,项目名称:parsers,代码行数:30,代码来源:Parser.java
示例2: createSetter
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的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;
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:34,代码来源:FieldDeclaration.java
示例3: visit
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override public Boolean visit(final AssignExpr n1, final Node arg) {
final AssignExpr n2 = (AssignExpr) arg;
if (n1.getOperator() != n2.getOperator()) {
return false;
}
if (!nodeEquals(n1.getTarget(), n2.getTarget())) {
return false;
}
if (!nodeEquals(n1.getValue(), n2.getValue())) {
return false;
}
return true;
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:18,代码来源:EqualsVisitor.java
示例4: visit
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override public Node visit(final AssignExpr n, final A arg) {
visitComment(n, arg);
final Expression target = (Expression) n.getTarget().accept(this, arg);
if (target == null) {
return null;
}
n.setTarget(target);
final Expression value = (Expression) n.getValue().accept(this, arg);
if (value == null) {
return null;
}
n.setValue(value);
return n;
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:ModifierVisitorAdapter.java
示例5: solveSymbol
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override
public SymbolReference<? extends ValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
for (Expression expression : wrappedNode.getInitialization()) {
if (expression instanceof VariableDeclarationExpr) {
VariableDeclarationExpr variableDeclarationExpr = (VariableDeclarationExpr) expression;
for (VariableDeclarator variableDeclarator : variableDeclarationExpr.getVariables()) {
if (variableDeclarator.getName().getId().equals(name)) {
return SymbolReference.solved(JavaParserSymbolDeclaration.localVar(variableDeclarator, typeSolver));
}
}
} else if (!(expression instanceof AssignExpr || expression instanceof MethodCallExpr)) {
throw new UnsupportedOperationException(expression.getClass().getCanonicalName());
}
}
if (getParentNode(wrappedNode) instanceof NodeWithStatements) {
return StatementContext.solveInBlock(name, typeSolver, wrappedNode);
} else {
return getParent().solveSymbol(name, typeSolver);
}
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:22,代码来源:ForStatementContext.java
示例6: solveSymbol
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override
public SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) {
for (Expression expression : wrappedNode.getInitialization()) {
if (expression instanceof VariableDeclarationExpr) {
VariableDeclarationExpr variableDeclarationExpr = (VariableDeclarationExpr) expression;
for (VariableDeclarator variableDeclarator : variableDeclarationExpr.getVariables()) {
if (variableDeclarator.getName().getId().equals(name)) {
return SymbolReference.solved(JavaParserSymbolDeclaration.localVar(variableDeclarator, typeSolver));
}
}
} else if (!(expression instanceof AssignExpr || expression instanceof MethodCallExpr)) {
throw new UnsupportedOperationException(expression.getClass().getCanonicalName());
}
}
if (getParentNode(wrappedNode) instanceof NodeWithStatements) {
return StatementContext.solveInBlock(name, typeSolver, wrappedNode);
} else {
return getParent().solveSymbol(name, typeSolver);
}
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:22,代码来源:ForStatementContext.java
示例7: visit
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的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);
}
开发者ID:fjalvingh,项目名称:domui,代码行数:11,代码来源:ColumnWrapper.java
示例8: doMerge
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override public AssignExpr doMerge(AssignExpr first, AssignExpr second) {
AssignExpr ae = new AssignExpr();
ae.setOperator(first.getOperator());
ae.setTarget(mergeSingle(first.getTarget(),second.getTarget()));
ae.setValue(mergeSingle(first.getValue(),second.getValue()));
return ae;
}
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:10,代码来源:AssignExprMerger.java
示例9: doIsEquals
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override public boolean doIsEquals(AssignExpr first, AssignExpr second) {
if(!isEqualsUseMerger(first.getTarget(),second.getTarget())) return false;
if(!isEqualsUseMerger(first.getValue(),second.getValue())) return false;
if(!first.getOperator().equals(second.getOperator())) return false;
return true;
}
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:9,代码来源:AssignExprMerger.java
示例10: getDefaultConstructorBlockStatement
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
/**
* Generates the contents of the constructor.
*
* @param valueString The string representing the field that this will be assigned to
* @return The constructor block
*/
private BlockStmt getDefaultConstructorBlockStatement(String valueString) {
BlockStmt block = new BlockStmt();
AssignExpr assignment = new AssignExpr(new FieldAccessExpr(new ThisExpr(), valueString), new
NameExpr(valueString), AssignExpr.Operator.assign);
ASTHelper.addStmt(block, assignment);
return block;
}
开发者ID:WPIRoboticsProjects,项目名称:GRIP,代码行数:14,代码来源:Enumeration.java
示例11: resolveDeclaredFieldReference
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Test
public void resolveDeclaredFieldReference() throws ParseException {
CompilationUnit cu = parseSample("ReferencesToField");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "ReferencesToField");
MethodDeclaration method1 = Navigator.demandMethod(referencesToField, "method1");
ExpressionStmt stmt = (ExpressionStmt) method1.getBody().get().getStatements().get(0);
AssignExpr assignExpr = (AssignExpr) stmt.getExpression();
SymbolSolver symbolSolver = new SymbolSolver(typeSolver);
SymbolReference symbolReference = symbolSolver.solveSymbol("i", assignExpr.getTarget());
assertEquals(true, symbolReference.isSolved());
assertEquals("i", symbolReference.getCorrespondingDeclaration().getName());
assertEquals(true, symbolReference.getCorrespondingDeclaration().isField());
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:16,代码来源:ContextTest.java
示例12: resolveInheritedFieldReference
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Test
public void resolveInheritedFieldReference() throws ParseException {
CompilationUnit cu = parseSample("ReferencesToField");
com.github.javaparser.ast.body.ClassOrInterfaceDeclaration referencesToField = Navigator.demandClass(cu, "ReferencesToFieldExtendingClass");
MethodDeclaration method1 = Navigator.demandMethod(referencesToField, "method2");
ExpressionStmt stmt = (ExpressionStmt) method1.getBody().get().getStatements().get(0);
AssignExpr assignExpr = (AssignExpr) stmt.getExpression();
SymbolSolver symbolSolver = new SymbolSolver(typeSolver);
SymbolReference symbolReference = symbolSolver.solveSymbol("i", assignExpr.getTarget());
assertEquals(true, symbolReference.isSolved());
assertEquals("i", symbolReference.getCorrespondingDeclaration().getName());
assertEquals(true, symbolReference.getCorrespondingDeclaration().isField());
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:16,代码来源:ContextTest.java
示例13: visit
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override
public Node visit(AssignExpr _n, Object _arg) {
Expression target = cloneNodes(_n.getTarget(), _arg);
Expression value = cloneNodes(_n.getValue(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
AssignExpr r = new AssignExpr(
_n.getRange(),
target, value, _n.getOperator());
r.setComment(comment);
return r;
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:13,代码来源:CloneVisitor.java
示例14: generateCompilationUnitFromCloudFormationSpec
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
static CompilationUnit generateCompilationUnitFromCloudFormationSpec(CloudFormationSpecification spec,
ArrayInitializerExpr jsonSubTypesArrayExpr) {
if (spec.getResourceType().size() != 1) {
throw new RuntimeException("Expected exactly 1 resource per file");
}
Map.Entry<String, ResourceTypeSpecification> resourceTypeNameAndSpec =
spec.getResourceType().entrySet().iterator().next();
// resourceCanonicalName is a name like "AWS::EC2::Instance", used in the JsonSubTypes.Type annotation and
// Javadoc
String resourceCanonicalName = resourceTypeNameAndSpec.getKey();
// resourceClassName is a shortened form, like "EC2Instance", to serve as the name of the generated Java
// class
String resourceClassName = resourceCanonicalName.substring("AWS::".length()).replace("::", "");
CompilationUnit compilationUnit = new CompilationUnit();
compilationUnit.setPackageDeclaration("com.salesforce.cf2pojo.model")
.addImport(JsonProperty.class);
final ClassOrInterfaceDeclaration resourceClass = compilationUnit.addClass(resourceClassName);
// The class declaration is something like "public class EC2Instance extends
// ResourceBase<EC2Instance.Properties>"
resourceClass.setName(resourceClassName).addModifier(Modifier.PUBLIC)
.addExtendedType(String.format("ResourceBase<%s.Properties>", resourceClassName));
// Add an @Generated annotation to the class
final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
resourceClass.addAndGetAnnotation(Generated.class)
.addPair("value", surroundWithQuotes(GenerateTask.class.getCanonicalName()))
.addPair("date", surroundWithQuotes(dateFormat.format(new Date())));
// Add constructor that initializes the properties field to a new Properties object
resourceClass.addConstructor(Modifier.PUBLIC).setBody(new BlockStmt(NodeList.nodeList(
new ExpressionStmt(
new AssignExpr(new NameExpr("properties"),
new ObjectCreationExpr(null, JavaParser.parseClassOrInterfaceType("Properties"),
new NodeList<>()), AssignExpr.Operator.ASSIGN)))));
// Generate the Properties nested class
ResourceTypeSpecification resourceSpec = resourceTypeNameAndSpec.getValue();
ClassOrInterfaceDeclaration resourcePropertiesClass = generatePropertiesClassFromTypeSpec("Properties",
compilationUnit, resourceCanonicalName, resourceSpec);
resourceClass.addMember(resourcePropertiesClass);
// Add a @JsonSubTypes.Type annotation for this resource type to ResourceBase class
jsonSubTypesArrayExpr.getValues().add(new NormalAnnotationExpr()
.addPair("value", resourceClassName + ".class")
.addPair("name", surroundWithQuotes(resourceCanonicalName))
.setName("JsonSubTypes.Type"));
// Generate nested classes for any subproperties of this resource type (e.g.,
// "EC2Instance.BlockDeviceMapping"). These are found in the "PropertyTypes" section of the spec file.
if (spec.getPropertyTypes() != null) {
for (Map.Entry<String, PropertyTypeSpecification> propertyTypeSpecEntry :
spec.getPropertyTypes().entrySet()) {
String subpropertyClassName = substringAfterFinalPeriod(propertyTypeSpecEntry.getKey());
ClassOrInterfaceDeclaration subpropertyClass = generatePropertiesClassFromTypeSpec(
subpropertyClassName, compilationUnit, propertyTypeSpecEntry.getKey(),
propertyTypeSpecEntry.getValue());
// Add the generated subproperty class as a static nested class of the resource class
resourceClass.addMember(subpropertyClass);
}
}
return compilationUnit;
}
开发者ID:salesforce,项目名称:cf2pojo,代码行数:71,代码来源:GenerateTask.java
示例15: visit
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override
public void visit(AssignExpr n, Script arg) {
}
开发者ID:Nosorog,项目名称:nosorog-core,代码行数:4,代码来源:NoOpVisitor.java
示例16: visit
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override
public void visit(final AssignExpr n, final Object arg) {
printer.printLn("AssignExpr");
printJavaComment(n.getComment(), arg);
n.getTarget().accept(this, arg);
printer.print(" ");
switch (n.getOperator()) {
case assign:
printer.print("=");
break;
case and:
printer.print("&=");
break;
case or:
printer.print("|=");
break;
case xor:
printer.print("^=");
break;
case plus:
printer.print("+=");
break;
case minus:
printer.print("-=");
break;
case rem:
printer.print("%=");
break;
case slash:
printer.print("/=");
break;
case star:
printer.print("*=");
break;
case lShift:
printer.print("<<=");
break;
case rSignedShift:
printer.print(">>=");
break;
case rUnsignedShift:
printer.print(">>>=");
break;
}
printer.print(" ");
n.getValue().accept(this, arg);
}
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:48,代码来源:ASTDumpVisitor.java
示例17: visit
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override
public JCTree visit(final AssignExpr n, final Object arg) {
// ARG0: int opcode
Tag arg0;
// ARG1: JCExpression lhs
JCExpression arg1 = (JCExpression) n.getTarget().accept(this, arg);
// ARG2: JCExpression rhs
JCExpression arg2 = (JCExpression) n.getValue().accept(this, arg);
// JCTree has two distinct nodes for Assigment
// The following case if for pure assignment "="
if (n.getOperator() == AssignExpr.Operator.assign) {
return new AJCAssign(make.Assign(arg1, arg2), ((n.getComment() != null) ? n.getComment().getContent() : null));
}
// Cases for operation followed by assignment
switch (n.getOperator()) {
case plus:
arg0 = JCTree.Tag.PLUS_ASG;
break;
case minus:
arg0 = JCTree.Tag.MINUS_ASG;
break;
case star:
arg0 = JCTree.Tag.MUL_ASG;
break;
case slash:
arg0 = JCTree.Tag.DIV_ASG;
break;
case and:
arg0 = JCTree.Tag.BITAND_ASG;
break;
case or:
arg0 = JCTree.Tag.BITOR_ASG;
break;
case xor:
arg0 = JCTree.Tag.BITXOR_ASG;
break;
case rem:
arg0 = JCTree.Tag.MOD_ASG;
break;
case lShift:
arg0 = JCTree.Tag.SL_ASG;
break;
case rSignedShift:
arg0 = JCTree.Tag.SR_ASG;
break;
case rUnsignedShift:
arg0 = JCTree.Tag.USR_ASG;
break;
default:
arg0 = JCTree.Tag.ERRONEOUS;
}
return new AJCAssignOp(make.Assignop(arg0, arg1, arg2), ((n.getComment() != null) ? n.getComment().getContent() : null));
}
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:59,代码来源:JavaParser2JCTree.java
示例18: parseExpression
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
/**
*
* @param expression
* a github javaparser Expression
* @param attributes
* the list of attributes of the class,
* to potentially get a type from the name
* @param lineNumber
* the starting line number of the parse method or constructor
* @return
* an Expression structure
*/
public Expr parseExpression(Expression expression, List<Attribute> attributes, int lineNumber) {
if (expression instanceof AssignExpr) { // this.bar = "bar";
AssignExpr assExpr = (AssignExpr) expression;
return parseExpression(assExpr.getTarget(), attributes, lineNumber);
} else if (expression instanceof MethodCallExpr) {
MethodCallExpr mcEx = (MethodCallExpr) expression;
return parseMethodCallExpression(mcEx, attributes, lineNumber);
} else if (expression instanceof NameExpr) { // ident
NameExpr nEx = (NameExpr) expression;
Ident nameExpr = new Ident(nEx.getName());
return nameExpr;
} else if (expression instanceof LiteralExpr) { // basic lit
return parseLiteralExpr((LiteralExpr) expression);
} else if (expression instanceof FieldAccessExpr) {
FieldAccessExpr fieldExpr = (FieldAccessExpr) expression;
Ident ident = new Ident(ParserUtils.parseTarget(expression.toString()).get("name"));
AttributeRef attrRef = new AttributeRef(ident);
return attrRef;
} else if (expression instanceof ObjectCreationExpr) {
ObjectCreationExpr objConExpr = (ObjectCreationExpr) expression;
return parseObjectCreationExpression(objConExpr, attributes, lineNumber);
} else if (expression instanceof ArrayAccessExpr) {
ArrayAccessExpr arryExpr = (ArrayAccessExpr) expression;
return parseArrayAccessExpression(arryExpr);
} else if (expression instanceof UnaryExpr) {
UnaryExpr unExpr = (UnaryExpr) expression;
return parseUnaryExpression(unExpr, attributes, lineNumber);
} else if (expression instanceof ConditionalExpr) {
ConditionalExpr condExpr = (ConditionalExpr) expression;
return parseConditionalExpression(condExpr, attributes, lineNumber);
} else if (expression instanceof CastExpr) {
CastExpr castExpr = (CastExpr) expression;
return parseExpression(castExpr.getExpr(), attributes, lineNumber);
} else if (expression instanceof BinaryExpr) {
BinaryExpr binEx = (BinaryExpr) expression;
return parseBinaryExpression(binEx, attributes, lineNumber);
} else if (expression instanceof EnclosedExpr) {
EnclosedExpr enclosedExpr = (EnclosedExpr) expression;
return parseExpression(enclosedExpr.getInner(), attributes, lineNumber);
} else if (expression instanceof InstanceOfExpr) {
InstanceOfExpr intExpr = (InstanceOfExpr) expression;
return parseInstanceOfExpression(intExpr, attributes, lineNumber);
} else if (expression instanceof ArrayCreationExpr) {
ArrayCreationExpr arryCreaExpr = (ArrayCreationExpr) expression;
return parseArrayCreationExpression(arryCreaExpr, attributes, lineNumber);
} else if (expression instanceof ArrayInitializerExpr) {
ArrayInitializerExpr arryInEx = (ArrayInitializerExpr) expression;
return parseArrayInitializerExpression(arryInEx, attributes, lineNumber);
} else if (expression instanceof ThisExpr) {
return new Ident("this");
} else if (expression instanceof SuperExpr) {
return new Ident("super");
} else if (expression instanceof ClassExpr) {
return new Ident(expression.toString());
} else if (expression instanceof VariableDeclarationExpr) { // int foo = 42;
// should be parsed by parseVariableDeclarationExpression()
Log.e(TAG, "Unreachable case :: expression : ".concat(expression.toString()));
return null;
} else {
Log.e(TAG, "The type of expression '".concat(expression.getClass().toString()).concat("' is not managed by the parser"));
return null;
}
}
开发者ID:DevMine,项目名称:parsers,代码行数:76,代码来源:Parser.java
示例19: visit
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override public Node visit(final AssignExpr n, final A arg) {
n.setTarget((Expression) n.getTarget().accept(this, arg));
n.setValue((Expression) n.getValue().accept(this, arg));
return n;
}
开发者ID:plum-umd,项目名称:java-sketch,代码行数:6,代码来源:ModifierVisitorAdapter.java
示例20: visit
import com.github.javaparser.ast.expr.AssignExpr; //导入依赖的package包/类
@Override public void visit(final AssignExpr n, final A arg) {
visitComment(n.getComment(), arg);
n.getTarget().accept(this, arg);
n.getValue().accept(this, arg);
}
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:6,代码来源:VoidVisitorAdapter.java
注:本文中的com.github.javaparser.ast.expr.AssignExpr类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论