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


Java ASTHelper类代码示例

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


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


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