當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。