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


Java Operator类代码示例

本文整理汇总了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;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:34,代码来源:FieldDeclaration.java

示例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);
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:11,代码来源:ColumnWrapper.java

示例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;
}
 
开发者ID:JCTools,项目名称:JCTools,代码行数:14,代码来源:JavaParsingAtomicArrayQueueGenerator.java


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