当前位置: 首页>>代码示例>>Java>>正文


Java AssignExpr类代码示例

本文整理汇总了Java中com.github.javaparser.ast.expr.AssignExpr的典型用法代码示例。如果您正苦于以下问题:Java AssignExpr类的具体用法?Java AssignExpr怎么用?Java AssignExpr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AssignExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了AssignExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的com.github.javaparser.ast.expr.AssignExpr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。