• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ASTHelper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setterDeclaration

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
private MethodDeclaration setterDeclaration(EntityField field) {
    MethodDeclaration decl = new MethodDeclaration(ModifierSet.PUBLIC,
            new VoidType(),
            "set" + CaseConverter.pascalCase(field.getName()),
            Collections.singletonList(new Parameter(
                    ASTHelper.createReferenceType(field.getType().getSimpleName(), 0),
                    new VariableDeclaratorId(field.getName()))));

    BlockStmt body = new BlockStmt();
    body.setStmts(
            Collections.singletonList(
                    new ExpressionStmt(
                            new AssignExpr(
                                    new FieldAccessExpr(new ThisExpr(), field.getName()),
                                    ASTHelper.createNameExpr(field.getName()),
                                    AssignExpr.Operator.assign
                            ))));
    decl.setBody(body);
    return decl;
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:21,代码来源:FormTask.java


示例2: getClassDeclaration

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
/**
 * Generates the class definition for the Operation
 */
private ClassOrInterfaceDeclaration getClassDeclaration() {
  ClassOrInterfaceDeclaration operation = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC,
      false, getOperationClassName());
  operation.setImplements(Collections.singletonList(iOperation));
  operation.setJavaDoc(javadocComment);
  operation.setComment(new BlockComment(
      " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n"
          + " * ===== THIS CODE HAS BEEN DYNAMICALLY GENERATED! DO NOT MODIFY! ==== *\n"
          + " * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "));
  operation.setMembers(socketHintDeclarationCollection
      .getAllSocketHints()
      .stream()
      .map(SocketHintDeclaration::getDeclaration)
      .filter(declaration -> declaration != null)
      .collect(Collectors.toList()));
  ASTHelper.addMember(operation, getNameMethod());
  ASTHelper.addMember(operation, getDescriptionMethod());
  ASTHelper.addMember(operation, getCategoryMethod());
  ASTHelper.addMember(operation, getCreateInputSocketsMethod());
  ASTHelper.addMember(operation, getCreateOutputSocketsMethod());
  ASTHelper.addMember(operation, getPerformMethod());
  return operation;
}
 
开发者ID:WPIRoboticsProjects,项目名称:GRIP,代码行数:27,代码来源:Operation.java


示例3: SocketHintDeclaration

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
public SocketHintDeclaration(DefaultValueCollector collector, Type genericType,
                             List<DefinedParamType> paramTypes, DefinedParamType
                                 .DefinedParamDirection state) {
      /* Convert this to the 'boxed' type if this is a PrimitiveType */
  if (genericType instanceof PrimitiveType) {
    if (((PrimitiveType) genericType).getType().equals(PrimitiveType.Primitive.Boolean)) {
      this.genericType = ((PrimitiveType) genericType).getType().toBoxedType();
    } else {
      this.genericType = ASTHelper.createReferenceType("Number", 0);
    }
  } else {
    this.genericType = genericType;
  }
  this.paramTypes = paramTypes;
  this.isOutput = state.isOutput();
  this.collector = collector;
}
 
开发者ID:WPIRoboticsProjects,项目名称:GRIP,代码行数:18,代码来源:SocketHintDeclaration.java


示例4: visit

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void visit(@Nullable MethodDeclaration methodDec,
		@Nullable List<String> groupNames) {
	if (null == methodDec || null == groupNames)
		throw GlobalUtils
				.createNotInitializedException("classorinterfacedeclaration");
	else {
		if (methodDec.getName().equals("runTest")) {
			List<Expression> groups = new ArrayList<Expression>();
			for (int i = 1; i < groupNames.size(); i++) {
				groups.add(new StringLiteralExpr(groupNames.get(i)));
			}
			List<MemberValuePair> testAnnoParams = new ArrayList<MemberValuePair>();
			testAnnoParams.add(new MemberValuePair("groups",
					new ArrayInitializerExpr(groups)));
			NormalAnnotationExpr testAnno = new NormalAnnotationExpr(
					ASTHelper.createNameExpr("Test"), testAnnoParams);

			methodDec.getAnnotations().add(testAnno);
		}
	}
}
 
开发者ID:bigtester,项目名称:automation-test-engine,代码行数:26,代码来源:CaseRunnerGenerator.java


示例5: startVisit

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
@Override
public UiVisitScope startVisit(
    UiGeneratorTools service,
    UiComponentGenerator generator,
    ComponentBuffer source,
    ContainerMetadata parent,
    UiAttrExpr n
) {
  boolean isMethod = n.getExpression() instanceof MethodCallExpr;
  String text = isMethod ? service.resolveString(source.getRoot().getContext(), n.getExpression()) : ASTHelper.extractAttrValue(n);
  String panel = parent.peekPanelName();
  final MethodBuffer mb = parent.getMethod(panel);
  mb.print(panel +".setText(")
    .print(isMethod ? text : "\"" + X_Source.escape(text) + "\"")
    .println(");");
  return new UiVisitScope(ScopeType.FEATURE).setVisitChildren(false);
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:18,代码来源:JavaFxTextFeatureGenerator.java


示例6: startVisit

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
@Override
public UiVisitScope startVisit(
    UiGeneratorTools service, ComponentBuffer source, ContainerMetadata me, UiContainerExpr n,
    UiGenerateMode mode
) {

  String parentName = me.peekPanelName();
  final MethodBuffer mb = me.getMethod(parentName);
  String container = n.getAttribute("type")
        .mapNullSafe(ASTHelper::extractAttrValue)
        .mapNullSafe(v->v.contains(".") ? v : "javafx.scene.layout." + v)
        .ifAbsentSupply(VBox.class::getCanonicalName);
  container = mb.addImport(container);

  String ref = me.getRefName("box");
  mb.println(container + " " + ref + " = new " + container + "();");
  mb.println(parentName + ".getChildren().add(" + ref + ");");
  me.pushPanelName(ref);
  me.saveMethod(ref, mb);
  return super.startVisit(service, source, me, n, mode);
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:22,代码来源:JavaFxBoxComponentGenerator.java


示例7: getTagName

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
private String getTagName(ClassOrInterfaceDeclaration cls) {
  for (AnnotationExpr anno : cls.getAnnotations()) {
    if (anno.getName().getSimpleName().equals("WebComponent")) {
      if (anno instanceof NormalAnnotationExpr) {
        for (MemberValuePair pair : ((NormalAnnotationExpr) anno).getPairs()) {
          if (pair.getName().equals("tagName")) {
            String val = ASTHelper.extractAnnoValue(pair);
            if (val != null) {
              return val;
            } else {
              X_Log.error(
                  getClass(),
                  "Type of annotation value not supported: " + pair.getValue().getClass() + " : " + pair.toSource()
              );
              throw new AssertionError("Must use string literals for tagName values of @WebComponent attributes");
            }
          }
        }

      }
    }
  }
  throw new AssertionError("Unable to find the generated tag name from component " + cls.toSource());
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:25,代码来源:GwtcSteps.java


示例8: renderSlide

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
public void renderSlide(DomBuffer into, UiContainerExpr slide) {
    // We'll render the slide element ourselves, if it hasn't been rendered for us.
    final DomBuffer out;
    if ("xapi-slide".equals(into.getTagName())) {
        out = into;
    } else {
        out = into.makeTag("xapi-slide");
    }
    slide.getAttribute("id")
        .mapNullSafe(UiAttrExpr::getExpression)
        .mapNullSafe(ASTHelper::extractStringValue)
        .readIfPresent(out::setId);

    final ComposableXapiVisitor<DomBuffer> visitor = new ComposableXapiVisitor<>();
    visitor
        .withUiContainerExpr((tag, buffer)->{
            renderSlideChild(out, tag, visitor, slide);
            return false;
        })
        .visit(slide.getBody(), out);
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:22,代码来源:SlideRenderer.java


示例9: rewriteTemplateReferences

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
protected void rewriteTemplateReferences(ComponentBuffer component) {
    final InterestingNodeResults interestingNodes = component.getInterestingNodes();
    Set<UiContainerExpr> templateParents = interestingNodes.getTemplateNameParents();
    state.componentFactory = containerFilter(templateParents);
    state.featureFactory = (feature, gen) -> {
        if (templateParents.contains(ASTHelper.getContainerParent(feature))) {
            rewriteDataReferences(component, feature, gen, interestingNodes);
            return new UiFeatureGenerator();
        } else {
            return null;
        }
    };
    final ContainerMetadata metadata = component.getRoot();
    UiGeneratorVisitor visitor = createVisitor(metadata, component);
    visitor.visit(metadata.getUi(), this);
    resetFactories();
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:18,代码来源:AbstractUiGeneratorService.java


示例10: generateDataAccessors

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
protected void generateDataAccessors(ComponentBuffer component) {
    final InterestingNodeResults interestingNodes = component.getInterestingNodes();
    Set<UiContainerExpr> dataParents = interestingNodes.getDataParents();
    Set<UiContainerExpr> modelParents = interestingNodes.getModelParents();
    final Set<UiContainerExpr> allParents = new LinkedHashSet<>();
    allParents.addAll(dataParents);
    allParents.addAll(modelParents);

    state.componentFactory = containerFilter(allParents);
    state.featureFactory = (feature, gen) -> {
        if (feature.getNameString().equalsIgnoreCase("data")) {
            return createDataFeatureGenerator();
        } else if (feature.getNameString().equalsIgnoreCase("model")) {
            return createModelFeatureGenerator();
        } else if (allParents.contains(ASTHelper.getContainerParent(feature))) {
            // TODO map features which contain nested UiContainerExpr via InterestingNodeFinder
            return new UiFeatureGenerator();
        } else {
            return null;
        }
    };
    final ContainerMetadata metadata = component.getRoot();
    UiGeneratorVisitor visitor = createVisitor(metadata, component);
    visitor.visit(metadata.getUi(), this);
    resetFactories();
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:27,代码来源:AbstractUiGeneratorService.java


示例11: execute

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
@Override
public void execute(PathResolver pathResolver) throws Exception {
    CompilationUnit cu = new CompilationUnit();
    String basePackage = BasePackageDetector.detect();
    cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr(basePackage + "form")));

    ClassOrInterfaceDeclaration formClass = new ClassOrInterfaceDeclaration(
            ModifierSet.PUBLIC, false, CaseConverter.pascalCase(tableName) + "Form");
    ASTHelper.addTypeDeclaration(cu, formClass);
    formClass.setExtends(Collections.singletonList(
            new ClassOrInterfaceType("FormBase")
    ));

    fields.stream()
            .filter(f -> !f.isId())
            .forEach(f -> ASTHelper.addMember(formClass, fieldDeclaration(f)));
    fields.stream()
            .filter(f -> !f.isId())
            .forEach(f -> ASTHelper.addMember(formClass, getterDeclaration(f)));
    fields.stream()
            .filter(f -> !f.isId())
            .forEach(f -> ASTHelper.addMember(formClass, setterDeclaration(f)));

    try (Writer writer = new OutputStreamWriter(pathResolver.destinationAsStream(destination))) {
        writer.write(cu.toString());
    }
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:28,代码来源:FormTask.java


示例12: fieldDeclaration

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
private FieldDeclaration fieldDeclaration(EntityField field) {
    VariableDeclarator variableDec = new VariableDeclarator(new VariableDeclaratorId(field.getName()));
    List<AnnotationExpr> annoList = new ArrayList<>();
    return new FieldDeclaration(ModifierSet.PRIVATE,
            annoList,
            ASTHelper.createReferenceType(field.getType().getSimpleName(), 0),
            Collections.singletonList(variableDec));
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:9,代码来源:FormTask.java


示例13: getterDeclaration

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
private MethodDeclaration getterDeclaration(EntityField field) {
    MethodDeclaration decl = new MethodDeclaration(ModifierSet.PUBLIC,
            ASTHelper.createReferenceType(field.getType().getSimpleName(), 0),
            "get" + CaseConverter.pascalCase(field.getName()));
    BlockStmt body = new BlockStmt();
    body.setStmts(
            Collections.singletonList(
                    new ReturnStmt(
                            new FieldAccessExpr(new ThisExpr(), field.getName()))));
    decl.setBody(body);
    return decl;
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:13,代码来源:FormTask.java


示例14: execute

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
public void execute(PathResolver pathResolver) throws Exception {
    CompilationUnit cu = new CompilationUnit();
    cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr(pkgName)));
    cu.setImports(Arrays.asList(
            new ImportDeclaration(ASTHelper.createNameExpr("org.seasar.doma.jdbc.Config"), false, false),
            new ImportDeclaration(ASTHelper.createNameExpr("org.seasar.doma.jdbc.dialect.Dialect"), false, false),
            new ImportDeclaration(ASTHelper.createNameExpr("org.seasar.doma.jdbc.dialect.H2Dialect"), false, false),
            new ImportDeclaration(ASTHelper.createNameExpr("javax.sql.DataSource"), false, false)
    ));

    ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "DomaConfig");
    type.setImplements(Collections.singletonList(new ClassOrInterfaceType("Config")));
    ASTHelper.addTypeDeclaration(cu, type);


    MethodDeclaration getDataSourceMethod = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.createReferenceType("DataSource", 0), "getDataSource");
    getDataSourceMethod.setAnnotations(Collections.singletonList(OVERRIDE_ANNOTATION));
    BlockStmt getDataSourceBody = new BlockStmt();
    ASTHelper.addStmt(getDataSourceBody, new ReturnStmt(new NullLiteralExpr()));
    getDataSourceMethod.setBody(getDataSourceBody);
    ASTHelper.addMember(type, getDataSourceMethod);

    MethodDeclaration getDialectMethod = new MethodDeclaration(ModifierSet.PUBLIC, ASTHelper.createReferenceType("Dialect", 0), "getDialect");
    getDialectMethod.setAnnotations(Collections.singletonList(OVERRIDE_ANNOTATION));
    BlockStmt getDialectBody = new BlockStmt();

    ObjectCreationExpr newDialect = new ObjectCreationExpr(null, new ClassOrInterfaceType("H2Dialect"), null);
    ASTHelper.addStmt(getDialectBody, new ReturnStmt(newDialect));
    getDialectMethod.setBody(getDialectBody);
    ASTHelper.addMember(type, getDialectMethod);

    try (OutputStreamWriter writer = new OutputStreamWriter(
            pathResolver.destinationAsStream(destination))) {
        writer.write(cu.toString());
    }
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:37,代码来源:DomaConfigTask.java


示例15: createAssignStatement

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
private VariableDeclarationExpr createAssignStatement() {
    VariableDeclarationExpr expr = ASTHelper.createVariableDeclarationExpr(ASTHelper.createReferenceType("Statement", 0), "stmt");
    expr.setVars(Collections.singletonList(new VariableDeclarator(
            new VariableDeclaratorId("stmt"),
            new MethodCallExpr(ASTHelper.createNameExpr("connection"), "createStatement")
    )));
    return expr;
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:9,代码来源:FlywayTask.java


示例16: createStatementExecuteBlock

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
private BlockStmt createStatementExecuteBlock() {
    BlockStmt block = new BlockStmt();
    MethodCallExpr stmtExecute = new MethodCallExpr(ASTHelper.createNameExpr("stmt"), "execute");
    ASTHelper.addArgument(stmtExecute, new StringLiteralExpr(createTableStatement));
    ASTHelper.addStmt(block, stmtExecute);
    return block;
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:8,代码来源:FlywayTask.java


示例17: configureApplicationFactory

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
private Generator configureApplicationFactory(Generator gen, String tableName, EnkanSystem system) {
    String path = findApplicationFactoryPath(system);
    return gen.writing("app", g -> g.task(new RewriteJavaSourceTask("src/main/java/" + path, cu -> {
        String controllerClassName = CaseConverter.pascalCase(tableName) + "Controller";
        String pkgName = BasePackageDetector.detect();

        cu.getImports().add(
                new ImportDeclaration(
                        ASTHelper.createNameExpr(pkgName + "controller." + controllerClassName),
                        false, false));
        cu.accept(new AppendRoutingVisitor(controllerClassName),
                new RoutingDefineContext());
    })));
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:15,代码来源:ScaffoldCommandRegister.java


示例18: visit

import com.github.javaparser.ASTHelper; //导入依赖的package包/类
public void visit(final MethodCallExpr n, final RoutingDefineContext arg) {
    if (n.getName().equals("define") && n.getScope().equals(ASTHelper.createNameExpr("Routes"))) {
        arg.setInRoutingDefine(true);
        super.visit(n, arg);
        arg.setInRoutingDefine(false);
    } else {
        super.visit(n, arg);
    }
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:10,代码来源:AppendRoutingVisitor.java


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NewBlockType类代码示例发布时间:2022-05-22
下一篇:
Java AID类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap