com.github.javaparser.ast.body.Parameter Java Examples

The following examples show how to use com.github.javaparser.ast.body.Parameter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParameterNameVisitor.java    From meghanada-server with GNU General Public License v3.0 6 votes vote down vote up
private void getParameterNames(MethodDeclaration methodDeclaration, boolean isInterface) {
  NodeList<Modifier> modifiers = methodDeclaration.getModifiers();
  if (isInterface || modifiers.contains(Modifier.publicModifier())) {
    String methodName = methodDeclaration.getName().getIdentifier();
    List<Parameter> parameters = methodDeclaration.getParameters();
    names.className = this.className;
    List<List<ParameterName>> parameterNames =
        names.names.computeIfAbsent(methodName, k -> new ArrayList<>(4));

    final List<ParameterName> temp = new ArrayList<>(8);
    for (final Parameter parameter : parameters) {
      ParameterName parameterName = new ParameterName();
      String type = parameter.getType().toString();
      String name = parameter.getName().getIdentifier();
      if (name.contains("[]")) {
        type = type + "[]";
        name = COMPILE.matcher(name).replaceAll(Matcher.quoteReplacement(""));
      }
      parameterName.type = type;
      parameterName.name = name;
      temp.add(parameterName);
    }
    parameterNames.add(temp);
  }
}
 
Example #2
Source File: GroovydocJavaVisitor.java    From groovy with Apache License 2.0 6 votes vote down vote up
private void setConstructorOrMethodCommon(CallableDeclaration<? extends CallableDeclaration<?>> n, SimpleGroovyExecutableMemberDoc methOrCons) {
    n.getJavadocComment().ifPresent(javadocComment ->
            methOrCons.setRawCommentText(javadocComment.getContent()));
    NodeList<Modifier> mods = n.getModifiers();
    if (currentClassDoc.isInterface()) {
        mods.add(Modifier.publicModifier());
    }
    setModifiers(mods, methOrCons);
    processAnnotations(methOrCons, n);
    for (Parameter param : n.getParameters()) {
        SimpleGroovyParameter p = new SimpleGroovyParameter(param.getNameAsString());
        processAnnotations(p, param);
        p.setType(makeType(param.getType()));
        methOrCons.add(p);
    }
}
 
Example #3
Source File: ParserTypeUtil.java    From JRemapper with MIT License 6 votes vote down vote up
/**
 * @param md
 *            JavaParser method declaration.
 * @return Internal descriptor from declaration, or {@code null} if any parsing
 *         failures occured.
 */
private static String getMethodDesc(MethodDeclaration md) {
	StringBuilder sbDesc = new StringBuilder("(");
	// Append the method parameters for the descriptor
	NodeList<Parameter> params = md.getParameters();
	for (Parameter param : params) {
		Type pType = param.getType();
		String pDesc = getDescriptor(pType);
		if (pDesc == null)
			return null;
		sbDesc.append(pDesc);
	}
	// Append the return type for the descriptor
	Type typeRet = md.getType();
	String retDesc = getDescriptor(typeRet);
	if (retDesc == null)
		return null;
	sbDesc.append(")");
	sbDesc.append(retDesc);
	return sbDesc.toString();
}
 
Example #4
Source File: RuleSetNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private MethodCallExpr handleRuleFlowGroup(RuleSetNode.RuleType ruleType) {
    // build supplier for rule runtime
    BlockStmt actionBody = new BlockStmt();
    LambdaExpr lambda = new LambdaExpr(new Parameter(new UnknownType(), "()"), actionBody);

    MethodCallExpr ruleRuntimeBuilder = new MethodCallExpr(
            new MethodCallExpr(new NameExpr("app"), "ruleUnits"), "ruleRuntimeBuilder");
    MethodCallExpr ruleRuntimeSupplier = new MethodCallExpr(
            ruleRuntimeBuilder, "newKieSession",
            NodeList.nodeList(new StringLiteralExpr("defaultStatelessKieSession"), new NameExpr("app.config().rule()")));
    actionBody.addStatement(new ReturnStmt(ruleRuntimeSupplier));

    return new MethodCallExpr("ruleFlowGroup")
            .addArgument(new StringLiteralExpr(ruleType.getName()))
            .addArgument(lambda);

}
 
Example #5
Source File: RuleSetNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private MethodCallExpr handleDecision(RuleSetNode.RuleType.Decision ruleType) {

        StringLiteralExpr namespace = new StringLiteralExpr(ruleType.getNamespace());
        StringLiteralExpr model = new StringLiteralExpr(ruleType.getModel());
        Expression decision = ruleType.getDecision() == null ?
                new NullLiteralExpr() : new StringLiteralExpr(ruleType.getDecision());

        MethodCallExpr decisionModels =
                new MethodCallExpr(new NameExpr("app"), "decisionModels");
        MethodCallExpr decisionModel =
                new MethodCallExpr(decisionModels, "getDecisionModel")
                        .addArgument(namespace)
                        .addArgument(model);

        BlockStmt actionBody = new BlockStmt();
        LambdaExpr lambda = new LambdaExpr(new Parameter(new UnknownType(), "()"), actionBody);
        actionBody.addStatement(new ReturnStmt(decisionModel));

        return new MethodCallExpr(METHOD_DECISION)
                .addArgument(namespace)
                .addArgument(model)
                .addArgument(decision)
                .addArgument(lambda);
    }
 
Example #6
Source File: TriggerMetaData.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public static LambdaExpr buildLambdaExpr(Node node, ProcessMetaData metadata) {
    Map<String, Object> nodeMetaData = node.getMetaData();
    TriggerMetaData triggerMetaData = new TriggerMetaData(
            (String) nodeMetaData.get(TRIGGER_REF),
            (String) nodeMetaData.get(TRIGGER_TYPE),
            (String) nodeMetaData.get(MESSAGE_TYPE),
            (String) nodeMetaData.get(MAPPING_VARIABLE),
            String.valueOf(node.getId()))
            .validate();
    metadata.getTriggers().add(triggerMetaData);

    // and add trigger action
    BlockStmt actionBody = new BlockStmt();
    CastExpr variable = new CastExpr(
            new ClassOrInterfaceType(null, triggerMetaData.getDataType()),
            new MethodCallExpr(new NameExpr(KCONTEXT_VAR), "getVariable")
                    .addArgument(new StringLiteralExpr(triggerMetaData.getModelRef())));
    MethodCallExpr producerMethodCall = new MethodCallExpr(new NameExpr("producer_" + node.getId()), "produce").addArgument(new MethodCallExpr(new NameExpr("kcontext"), "getProcessInstance")).addArgument(variable);
    actionBody.addStatement(producerMethodCall);
    return new LambdaExpr(
            new Parameter(new UnknownType(), KCONTEXT_VAR), // (kcontext) ->
            actionBody
    );
}
 
Example #7
Source File: DecisionConfigGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private MethodDeclaration generateMergeEventListenerConfigMethod() {
    BlockStmt body = new BlockStmt().addStatement(new ReturnStmt(newObject(CachedDecisionEventListenerConfig.class,
            callMerge(
                    VAR_DECISION_EVENT_LISTENER_CONFIG,
                    DecisionEventListenerConfig.class, "listeners",
                    VAR_DMN_RUNTIME_EVENT_LISTENERS
            )
    )));

    return method(Modifier.Keyword.PRIVATE, DecisionEventListenerConfig.class, METHOD_MERGE_DECISION_EVENT_LISTENER_CONFIG,
            nodeList(
                    new Parameter().setType(genericType(Collection.class, DecisionEventListenerConfig.class)).setName(VAR_DECISION_EVENT_LISTENER_CONFIG),
                    new Parameter().setType(genericType(Collection.class, DMNRuntimeEventListener.class)).setName(VAR_DMN_RUNTIME_EVENT_LISTENERS)
            ),
            body);
}
 
Example #8
Source File: RuleConfigGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private MethodDeclaration generateMergeEventListenerConfigMethod() {
    BlockStmt body = new BlockStmt().addStatement(new ReturnStmt(newObject(CachedRuleEventListenerConfig.class,
            callMerge(
                    VAR_RULE_EVENT_LISTENER_CONFIGS,
                    RuleEventListenerConfig.class, "agendaListeners",
                    VAR_AGENDA_EVENT_LISTENERS
            ),
            callMerge(
                    VAR_RULE_EVENT_LISTENER_CONFIGS,
                    RuleEventListenerConfig.class, "ruleRuntimeListeners",
                    VAR_RULE_RUNTIME_EVENT_LISTENERS
            )
    )));

    return method(Modifier.Keyword.PRIVATE, RuleEventListenerConfig.class, METHOD_MERGE_RULE_EVENT_LISTENER_CONFIG,
            NodeList.nodeList(
                    new Parameter().setType(genericType(Collection.class, RuleEventListenerConfig.class)).setName(VAR_RULE_EVENT_LISTENER_CONFIGS),
                    new Parameter().setType(genericType(Collection.class, AgendaEventListener.class)).setName(VAR_AGENDA_EVENT_LISTENERS),
                    new Parameter().setType(genericType(Collection.class, RuleRuntimeEventListener.class)).setName(VAR_RULE_RUNTIME_EVENT_LISTENERS)
            ),
            body);
}
 
Example #9
Source File: QueryEndpointGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private BlockStmt wrapBodyAddingExceptionLogging(BlockStmt body, String nameURL) {
    TryStmt ts = new TryStmt();
    ts.setTryBlock(body);
    CatchClause cc = new CatchClause();
    String exceptionName = "e";
    cc.setParameter(new Parameter().setName(exceptionName).setType(Exception.class));
    BlockStmt cb = new BlockStmt();
    cb.addStatement(parseStatement(
            String.format(
                    "SystemMetricsCollector.registerException(\"%s\", %s.getStackTrace()[0].toString());",
                    nameURL,
                    exceptionName)
    ));
    cb.addStatement(new ThrowStmt(new NameExpr(exceptionName)));
    cc.setBody(cb);
    ts.setCatchClauses(new NodeList<>(cc));
    return new BlockStmt(new NodeList<>(ts));
}
 
Example #10
Source File: ProcessConfigGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private MethodDeclaration generateMergeEventListenerConfigMethod() {
    BlockStmt body = new BlockStmt().addStatement(new ReturnStmt(newObject(CachedProcessEventListenerConfig.class,
            callMerge(
                    VAR_PROCESS_EVENT_LISTENER_CONFIGS,
                    ProcessEventListenerConfig.class, "listeners",
                    VAR_PROCESS_EVENT_LISTENERS
            )
    )));

    return method(Modifier.Keyword.PRIVATE, ProcessEventListenerConfig.class, METHOD_MERGE_PROCESS_EVENT_LISTENER_CONFIG,
            NodeList.nodeList(
                    new Parameter().setType(genericType(Collection.class, ProcessEventListenerConfig.class)).setName(VAR_PROCESS_EVENT_LISTENER_CONFIGS),
                    new Parameter().setType(genericType(Collection.class, ProcessEventListener.class)).setName(VAR_PROCESS_EVENT_LISTENERS)
            ),
            body);
}
 
Example #11
Source File: RemoveMethodParameterTest.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * Asserts that all method calls in the body of methodWithTargetMethodCalls have
 * the same argument size as the refactoredMethod has arguments
 * 
 * @param methodWithTargetMethodCalls
 * @param refactoredMethod
 */
private void assertAllMethodCallsArgumentSizeEqualToRefactoredMethodParameterCount(
		MethodDeclaration methodWithTargetMethodCalls, MethodDeclaration refactoredMethod) {
	for (MethodCallExpr methodCall : methodWithTargetMethodCalls.getBody().get().findAll(MethodCallExpr.class)) {
		if (methodCall.getNameAsString().equals(refactoredMethod.getNameAsString())) {
			NodeList<Expression> callerMethodArguments = methodCall.getArguments();
			NodeList<Parameter> refactoredMethodParameters = refactoredMethod.getParameters();

			assertThat(callerMethodArguments).hasSameSizeAs(refactoredMethodParameters);
		}
	}
}
 
Example #12
Source File: RemoveMethodParameter.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * @param methodDeclaration
 * @param parameterName
 * @return index of the parameter with the given name, or null if not found
 */
private Integer getMethodParameterIndex(MethodDeclaration methodDeclaration, String parameterName) {
	NodeList<Parameter> parameters = methodDeclaration.getParameters();
	for (int i = 0; i < parameters.size(); i++) {
		if (parameters.get(i).getName().asString().equals(parameterName)) {
			return i;
		}
	}
	return null;
}
 
Example #13
Source File: CodegenUtils.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public static MethodDeclaration method(Modifier.Keyword modifier, Class<?> type, String name, NodeList<Parameter> parameters, BlockStmt body) {
    return new MethodDeclaration()
            .setModifiers(modifier)
            .setType(type == null ? "void" : type.getCanonicalName())
            .setName(name)
            .setParameters(parameters)
            .setBody(body);
}
 
Example #14
Source File: ConstructorIndexer.java    From jql with MIT License 5 votes vote down vote up
public void index(ConstructorDeclaration constructorDeclaration, int typeId) {
    List<Parameter> parameters = constructorDeclaration.getParameters();
    String name = constructorDeclaration.getNameAsString();
    int methodId = methodDao.save(new Method(name,
            constructorDeclaration.isPublic(), constructorDeclaration.isStatic(), constructorDeclaration.isFinal(), constructorDeclaration.isAbstract(), true, typeId));
    for (Parameter parameter : parameters) {
        parameterIndexer.index(parameter, methodId);
    }
}
 
Example #15
Source File: MethodIndexer.java    From jql with MIT License 5 votes vote down vote up
public void index(MethodDeclaration methodDeclaration, int typeId) {
    List<Parameter> parameters = methodDeclaration.getParameters();
    String name = methodDeclaration.getNameAsString();
    int methodId = methodDao.save(new Method(name,
            methodDeclaration.isPublic(), methodDeclaration.isStatic(), methodDeclaration.isFinal(), methodDeclaration.isAbstract(), false, typeId));
    for (Parameter parameter : parameters) {
        parameterIndexer.index(parameter, methodId);
    }
}
 
Example #16
Source File: RemoveMethodParameter.java    From Refactoring-Bot with MIT License 5 votes vote down vote up
/**
 * Removes the parameter with the given name from the given method declaration
 * 
 * @param methodDeclaration
 * @param parameterName
 */
private void removeMethodParameter(MethodDeclaration methodDeclaration, String parameterName) {
	Optional<Parameter> parameterToBeRemoved = methodDeclaration.getParameterByName(parameterName);
	if (parameterToBeRemoved.isPresent()) {
		parameterToBeRemoved.get().remove();
	}
}
 
Example #17
Source File: JavaDocParserVisitor.java    From jaxrs-analyzer with Apache License 2.0 5 votes vote down vote up
private MemberParameterTag createMethodParameterTag(JavadocBlockTag tag, MethodDeclaration method) {
    Stream<AnnotationExpr> annotations = method.getParameterByName(tag.getName().orElse(null))
            .map(Parameter::getAnnotations)
            .map(NodeList::stream)
            .orElseGet(Stream::empty);

    return createMemberParamTag(tag.getContent(), annotations);
}
 
Example #18
Source File: ParameterMerger.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@Override
public Parameter doMerge(Parameter first, Parameter second) {

    Parameter parameter = new Parameter();

    parameter.setType(first.getType());
    parameter.setId(first.getId());
    parameter.setVarArgs(first.isVarArgs());
    parameter.setModifiers(mergeModifiers(first.getModifiers(), second.getModifiers()));
    parameter.setAnnotations(mergeCollections(first.getAnnotations(), second.getAnnotations()));

    return parameter;
}
 
Example #19
Source File: JavaparserTest.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #20
Source File: JavaClassSyncHandler.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void syncConstructorSnippet(ConstructorDeclaration constructor, Map<String, ImportDeclaration> imports) {
    String signature
            = constructor.getParameters()
                    .stream()
                    .map(Parameter::getTypeAsString)
                    .collect(joining(", "));
    if (!javaClass.getConstructors()
            .stream()
            .filter(Constructor::isEnable)
            .filter(cot -> cot.getSignature().equals(signature))
            .findAny()
            .isPresent()) {
        syncClassSnippet(AFTER_FIELD, constructor.toString(), imports);
    }
}
 
Example #21
Source File: JavaRefactoring.java    From gauge-java with Apache License 2.0 5 votes vote down vote up
private Range getParamsRange() {
    List<Parameter> parameters = registry.get(oldStepValue.getStepText()).getParameters();
    if (parameters.isEmpty()) {
        int line = registry.get(oldStepValue.getStepText()).getSpan().begin.line + 1;
        int column = registry.get(oldStepValue.getStepText()).getName().length();
        return new Range(new Position(line, column), new Position(line, column));
    }
    Range firstParam = parameters.get(0).getRange().get();
    Range lastParam = parameters.get(parameters.size() - 1).getRange().get();
    return new Range(new Position(firstParam.begin.line, firstParam.begin.column - 1), new Position(lastParam.end.line, lastParam.end.column));
}
 
Example #22
Source File: JavaRefactoring.java    From gauge-java with Apache License 2.0 5 votes vote down vote up
private JavaRefactoringElement addJavaDiffElements(RefactoringMethodVisitor methodVisitor, JavaRefactoringElement javaElement) {
    List<Parameter> newParameters = methodVisitor.getNewParameters();
    Range stepLineSpan = methodVisitor.getStepLineSpan();
    javaElement.addDiffs(new Diff("\"" + parameterizedStepValue + "\"", getStepRange(stepLineSpan)));
    javaElement.addDiffs(new Diff(updatedParameters(newParameters), getParamsRange()));
    return javaElement;
}
 
Example #23
Source File: JavaParsingAtomicArrayQueueGenerator.java    From JCTools with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(ClassOrInterfaceDeclaration node, Void arg) {
    super.visit(node, arg);

    replaceParentClassesForAtomics(node);

    node.setName(translateQueueName(node.getNameAsString()));

    if (isCommentPresent(node, GEN_DIRECTIVE_CLASS_CONTAINS_ORDERED_FIELD_ACCESSORS)) {
        node.setComment(null);
        removeStaticFieldsAndInitialisers(node);
        patchAtomicFieldUpdaterAccessorMethods(node);
    }

    for (MethodDeclaration method : node.getMethods()) {
        if (isCommentPresent(method, GEN_DIRECTIVE_METHOD_IGNORE)) {
            method.remove();
        }
    }

    if (!node.getMethodsByName("failFastOffer").isEmpty()) {
        MethodDeclaration deprecatedMethodRedirect = node.addMethod("weakOffer", Keyword.PUBLIC);
        patchMethodAsDeprecatedRedirector(deprecatedMethodRedirect, "failFastOffer", PrimitiveType.intType(),
                new Parameter(classType("E"), "e"));
    }

    node.setJavadocComment(formatMultilineJavadoc(0,
            "NOTE: This class was automatically generated by "
                    + JavaParsingAtomicArrayQueueGenerator.class.getName(),
            "which can found in the jctools-build module. The original source file is " + sourceFileName + ".")
            + node.getJavadocComment().orElse(new JavadocComment("")).getContent());
}
 
Example #24
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/***************
 * Constructors
 *   - modify the 2 arg constructor - changing the args and the body
 * @param n - the constructor node
 * @param ignored -
 */
@Override
public void visit(ConstructorDeclaration n, Object ignored) {
  super.visit(n, ignored);  // processes the params 
  if (!isConvert2v3) {  // for enums, annotations
    return;
  }
  List<Parameter> ps = n.getParameters();
  
  if (ps.size() == 2 && 
      getParmTypeName(ps, 0).equals("int") &&
      getParmTypeName(ps, 1).equals("TOP_Type")) {
      
    /** public Foo(TypeImpl type, CASImpl casImpl) {
     *   super(type, casImpl);
     *   readObject();
     */
    setParameter(ps, 0, "TypeImpl", "type");
    setParameter(ps, 1, "CASImpl", "casImpl");
    
    // Body: change the 1st statement (must be super)
    NodeList<Statement> stmts = n.getBody().getStatements();
    if (!(stmts.get(0) instanceof ExplicitConstructorInvocationStmt)) {
      recordBadConstructor("missing super call");
      return;
    }
    NodeList<Expression> args = ((ExplicitConstructorInvocationStmt)(stmts.get(0))).getArguments();
    args.set(0, new NameExpr("type"));
    args.set(1,  new NameExpr("casImpl"));
   
    // leave the rest unchanged.
  }      
}
 
Example #25
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Heuristic:
 *   JCas classes have 0, 1, and 2 arg constructors with particular arg types
 *   0 -
 *   1 - JCas
 *   2 - int, TOP_Type  (v2) or TypeImpl, CASImpl (v3)
 *   
 * Additional 1 and 2 arg constructors are permitted.
 * 
 * Sets fields hasV2Constructors, hasV3Constructors
 * @param members
 */
private void setHasJCasConstructors(NodeList<BodyDeclaration<?>> members) {
  boolean has0ArgConstructor = false;
  boolean has1ArgJCasConstructor = false;
  boolean has2ArgJCasConstructorV2 = false;
  boolean has2ArgJCasConstructorV3 = false;
  
  for (BodyDeclaration<?> bd : members) {
    if (bd instanceof ConstructorDeclaration) {
      List<Parameter> ps = ((ConstructorDeclaration)bd).getParameters();
      if (ps.size() == 0) has0ArgConstructor = true;
      if (ps.size() == 1 && getParmTypeName(ps, 0).equals("JCas")) {
        has1ArgJCasConstructor = true;
      }
      if (ps.size() == 2) {
        if (getParmTypeName(ps, 0).equals("int") &&
            getParmTypeName(ps, 1).equals("TOP_Type")) {
          has2ArgJCasConstructorV2 = true;
        } else if (getParmTypeName(ps, 0).equals("TypeImpl") &&
                   getParmTypeName(ps, 1).equals("CASImpl")) {
          has2ArgJCasConstructorV3 = true;
        }
      } // end of 2 arg constructor
    } // end of is-constructor
  } // end of for loop
  
  hasV2Constructors = has0ArgConstructor && has1ArgJCasConstructor && has2ArgJCasConstructorV2;
  hasV3Constructors = has0ArgConstructor && has1ArgJCasConstructor && has2ArgJCasConstructorV3;
}
 
Example #26
Source File: AbstractResourceGenerator.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private void enableValidation(ClassOrInterfaceDeclaration template) {
    Optional.ofNullable(context)
            .map(GeneratorContext::getBuildContext)
            .filter(KogitoBuildContext::isValidationSupported)
            .ifPresent(c -> template.findAll(Parameter.class)
                    .stream()
                    .filter(param -> param.getTypeAsString().equals(dataClazzName + "Input"))
                    .forEach(this::insertValidationAnnotations));
}
 
Example #27
Source File: ParameterHelper.java    From apigcc with MIT License 5 votes vote down vote up
public static boolean isRequestParam(Parameter parameter) {
    if (!parameter.isAnnotationPresent(ANNOTATION_PATH_VARIABLE) &&
            !parameter.isAnnotationPresent(ANNOTATION_REQUEST_BODY) &&
            !parameter.isAnnotationPresent(ANNOTATION_REQUEST_HEADER) &&
            !parameter.isAnnotationPresent(ANNOTATION_COOKIE_VALUE) &&
            !parameter.isAnnotationPresent(ANNOTATION_REQUEST_PART) &&
            !parameter.isAnnotationPresent(ANNOTATION_MULTIPART_FILE) &&
            !parameter.isAnnotationPresent(ANNOTATION_REQUEST_ATTRIBUTE)) {
        return true;
    }
    return false;
}
 
Example #28
Source File: ParameterHelper.java    From apigcc with MIT License 5 votes vote down vote up
public static Parameter getRequestBody(NodeList<Parameter> parameters){
    for (Parameter parameter : parameters) {
        if (isRequestBody(parameter)) {
            return parameter;
        }
    }
    return null;
}
 
Example #29
Source File: ParameterHelper.java    From apigcc with MIT License 5 votes vote down vote up
public static boolean hasRequestBody(NodeList<Parameter> parameters) {
    for (Parameter parameter : parameters) {
        if (isRequestBody(parameter)) {
            return true;
        }
    }
    return false;
}
 
Example #30
Source File: AutoDoc.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
/**
 * Write the method parameters and it's doc to target api doc
 *
 * @param doc     target doc
 * @param comment parameters and method doc
 **/
private void fillParamDoc(APIDoc doc, JavadocComment comment, StringBuilder methodDesBuilder) {
    Javadoc javadoc = comment.parse();
    toString(javadoc.getDescription(), methodDesBuilder);
    doc.setDesc(methodDesBuilder.toString());
    methodDesBuilder.setLength(0);
    List<JavadocBlockTag> tags = javadoc.getBlockTags();
    if (comment.getCommentedNode().isPresent()) {
        Node node = comment.getCommentedNode().get();
        if (node instanceof MethodDeclaration) {
            MethodDeclaration method = (MethodDeclaration) node;
            for (Parameter p : method.getParameters()) {
                String type = p.getType().asString();
                String name = p.getName().asString();
                List<Param> params = doc.getParams();
                Param param = new Param();
                param.setName(name);
                param.setType(type);
                for (JavadocBlockTag t : tags) {
                    if (t.getName().isPresent()) {
                        if (name.endsWith(t.getName().get())) {
                            toString(t.getContent(), methodDesBuilder);
                            param.setComment(methodDesBuilder.toString());
                            methodDesBuilder.setLength(0);
                        }
                    }
                }
                if (params == null) {
                    params = new ArrayList<>();
                    doc.setParams(params);
                }
                params.add(param);
            }
        }
    }
}