Java ASTHelper.createParameter方法代码示例(com.github.javaparser.asthelper.createparameter方法的典型用法代码示例)

本文整理汇总了Java中com.github.javaparser.ASTHelper.createParameter方法的典型用法代码示例。如果您正苦于以下问题:Java ASTHelper.createParameter方法的具体用法?Java ASTHelper.createParameter怎么用?Java ASTHelper.createParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.javaparser.ASTHelper的用法示例。


Java ASTHelper.createParameter方法代码示例(com.github.javaparser.asthelper.createparameter方法的典型用法代码示例)

在下文中一共展示了ASTHelper.createParameter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createCU

import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
/**
 * creates the compilation unit
 */
private static CompilationUnit createCU() {
    CompilationUnit cu = new CompilationUnit();
    // set the package
    cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("java.parser.test")));

    // create the type declaration
    ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "GeneratedClass");
    ASTHelper.addTypeDeclaration(cu, type);

    // create a method
    MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "main");
    method.setModifiers(ModifierSet.addModifier(method.getModifiers(), ModifierSet.STATIC));
    ASTHelper.addMember(type, method);

    // add a parameter to the method
    Parameter param = ASTHelper.createParameter(ASTHelper.createReferenceType("String", 0), "args");
    param.setVarArgs(true);
    ASTHelper.addParameter(method, param);

    // add a body to the method
    BlockStmt block = new BlockStmt();
    method.setBody(block);

    // add a statement do the method body
    NameExpr clazz = new NameExpr("System");
    FieldAccessExpr field = new FieldAccessExpr(clazz, "out");
    MethodCallExpr call = new MethodCallExpr(field, "println");
    ASTHelper.addArgument(call, new StringLiteralExpr("Hello World!"));
    ASTHelper.addStmt(block, call);

    return cu;
} 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:36,代码来源:ClassCreator.java

示例2: visit

import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
@Override
public void visit(MethodDeclaration n, Object arg) {
    // change the name of the method to upper case
    n.setName(n.getName().toUpperCase());

    // create the new parameter
    Parameter newArg = ASTHelper.createParameter(ASTHelper.INT_TYPE, "value");

    // add the parameter to the method
    ASTHelper.addParameter(n, newArg);
} 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:12,代码来源:MethodChanger.java

示例3: changeMethod

import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
private static void changeMethod(MethodDeclaration n) {
    // change the name of the method to upper case
    n.setName(n.getName().toUpperCase());

    // create the new parameter
    Parameter newArg = ASTHelper.createParameter(ASTHelper.INT_TYPE, "value");

    // add the parameter to the method
    ASTHelper.addParameter(n, newArg);
} 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:11,代码来源:MethodChangerWithoutVisitor.java

示例4: setup

import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
@Before
public void setup(){
  CompilationUnit cu = new CompilationUnit();
  // set the package
  cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("java.parser.test")));

  // create the type declaration
  ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "GeneratedClass");
  ASTHelper.addTypeDeclaration(cu, type);

  // create a method
  MethodDeclaration method = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.VOID_TYPE, "main");
  method.setModifiers(ModifierSet.addModifier(method.getModifiers(), ModifierSet.STATIC));
  ASTHelper.addMember(type, method);

  // add a parameter to the method
  Parameter param = ASTHelper.createParameter(ASTHelper.createReferenceType("String", 0), "args");
  param.setVarArgs(true);
  ASTHelper.addParameter(method, param);

  // add a body to the method
  BlockStmt block = new BlockStmt();
  method.setBody(block);

  // add a statement do the method body
  NameExpr clazz = new NameExpr("System");
  FieldAccessExpr field = new FieldAccessExpr(clazz, "out");
  MethodCallExpr call = new MethodCallExpr(field, "println");
  ASTHelper.addArgument(call, new StringLiteralExpr("Hello World!"));
  ASTHelper.addStmt(block, call);

  unit = cu;
} 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:34,代码来源:JavaparserTest.java

示例5: whenVarargsCalledAreAddedToMethodInClass

import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
@When("$typeName varargs called \"$parameterName\" are added to method $methodPosition in class $classPosition")
public void whenVarargsCalledAreAddedToMethodInClass(String typeName, String parameterName, int methodPosition, int classPosition) {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
    Parameter param = ASTHelper.createParameter(ASTHelper.createReferenceType(typeName, 0), parameterName);
    param.setVarArgs(true);
    ASTHelper.addParameter(method, param);
} 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:9,代码来源:ManipulationSteps.java

示例6: visit

import com.github.javaparser.ASTHelper; //导入方法依赖的package包/类
@Override
public void visit(MethodDeclaration n, Object arg) {

    if (!methodFilter.test(n)) {
        return;
    }

    MethodDeclaration method = new MethodDeclaration(n.getModifiers(), methodReturnTypeFunction.apply(n), n.getName());

    if (methodCommentMutator != null) {
        method.setComment(methodCommentMutator.apply(n.getComment()));
    } else {
        method.setComment(n.getComment());
    }

    for (Parameter parameter : n.getParameters()) {
        Parameter param = ASTHelper.createParameter(parameter.getType(), parameter.getId().getName());
        param.setVarArgs(parameter.isVarArgs());

        ASTHelper.addParameter(method, param);
    }

    if (n.getTypeParameters() != null) {
        method.setTypeParameters(new ArrayList<>());
        method.getTypeParameters().addAll(n.getTypeParameters());
    }

    if (n.getAnnotations() != null) {
        method.setAnnotations(n.getAnnotations());
    }

    ASTHelper.addMember(resultType, method);
} 
开发者ID:lettuce-io,项目名称:lettuce-core,代码行数:34,代码来源:CompilationUnitFactory.java

本文标签属性:

示例:示例英文

代码:代码大全可复制

java:java自行车

ASTHelper:ASTHelper

createParameter:createParameter

上一篇:什么是核污染?(什么是核污染?)
下一篇:日本一天两次地震是哪一年(日本本州东海岸发生7.1级地震6级以上地震接连发生)(日本本州东岸近海发生多次强震)

为您推荐