com.github.javaparser.ast.expr.AnnotationExpr Java Examples

The following examples show how to use com.github.javaparser.ast.expr.AnnotationExpr. 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: AnnotatedMember.java    From jeddict with Apache License 2.0 6 votes vote down vote up
static List<String> getStringAttributes(AnnotationExpr annotationExpr, String attributeName) {
    List<String> values = new ArrayList<>();
    Optional<Expression> expOptional = getAttribute(annotationExpr, attributeName);
    if (expOptional.isPresent()) {
        Expression expression = expOptional.get();
        if (expression.isStringLiteralExpr()) {
            values.add(expression.asStringLiteralExpr().getValue());
        } else if (expression.isArrayInitializerExpr()) {
            List<Node> nodes = expression.asArrayInitializerExpr().getChildNodes();
            for (Node node : nodes) {
                if (node instanceof StringLiteralExpr) {
                    values.add(((StringLiteralExpr) node).getValue());
                } else {
                    values.add(node.toString());
                }
            }
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return values;
}
 
Example #2
Source File: AnnotatedWithCalculator.java    From jql with MIT License 6 votes vote down vote up
public void calculate(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, CompilationUnit compilationUnit) {
    List<AnnotationExpr> annotations = classOrInterfaceDeclaration.getAnnotations();
    for (AnnotationExpr annotation : annotations) {
        String annotationName = annotation.getNameAsString();
        String annotationPackageName = annotation
                .findCompilationUnit()
                .flatMap(CompilationUnit::getPackageDeclaration)
                .flatMap(pkg -> Optional.of(pkg.getNameAsString())).orElse("???");

        if (typeDao.exist(annotationName, annotationPackageName)) { // JDK annotations are not indexed
            int annotationId = typeDao.getId(annotationName, annotationPackageName);
            int typeId = typeDao.getId(classOrInterfaceDeclaration.getNameAsString(), compilationUnit.getPackageDeclaration().get().getNameAsString());
            annotatedWithDao.save(new AnnotatedWith(typeId, annotationId));
        }
    }
}
 
Example #3
Source File: MysteryGuest.java    From TestSmellDetector with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visit(VariableDeclarationExpr n, Void arg) {
    super.visit(n, arg);
    //Note: the null check limits the identification of variable types declared within the method body.
    // Removing it will check for variables declared at the class level.
    //TODO: to null check or not to null check???
    if (currentMethod != null) {
        for (String variableType : mysteryTypes) {
            //check if the type variable encountered is part of the mystery type collection
            if ((n.getVariable(0).getType().asString().equals(variableType))) {
                //check if the variable has been mocked
                for (AnnotationExpr annotation : n.getAnnotations()) {
                    if (annotation.getNameAsString().equals("Mock") || annotation.getNameAsString().equals("Spy"))
                        break;
                }
                // variable is not mocked, hence it's a smell
                mysteryCount++;
            }
        }
    }
}
 
Example #4
Source File: OpenApiObjectGenerator.java    From flow with Apache License 2.0 6 votes vote down vote up
private void parseClass(ClassOrInterfaceDeclaration classDeclaration,
        CompilationUnit compilationUnit) {
    Optional<AnnotationExpr> endpointAnnotation = classDeclaration
            .getAnnotationByClass(Endpoint.class);
    compilationUnit.getStorage().ifPresent(storage -> {
        String className = classDeclaration.getFullyQualifiedName()
                .orElse(classDeclaration.getNameAsString());
        qualifiedNameToPath.put(className, storage.getPath().toString());
    });
    if (!endpointAnnotation.isPresent()) {
        nonEndpointMap.put(classDeclaration.resolve().getQualifiedName(),
                classDeclaration);
    } else {
        Optional<Javadoc> javadoc = classDeclaration.getJavadoc();
        if (javadoc.isPresent()) {
            endpointsJavadoc.put(classDeclaration,
                    javadoc.get().getDescription().toText());
        } else {
            endpointsJavadoc.put(classDeclaration, "");
        }
        pathItems.putAll(createPathItems(
                getEndpointName(classDeclaration, endpointAnnotation.get()),
                classDeclaration));
    }
}
 
Example #5
Source File: AnnotationHelper.java    From apigcc with MIT License 6 votes vote down vote up
/**
 * 获取注解的属性
 * @param expr
 * @param keys 从前往后找,返回第一个存在的属性
 * @return
 */
public static Optional<Expression> attr(AnnotationExpr expr, String ... keys) {
    for (String key : keys) {
        if (Objects.equals("value", key) && expr.isSingleMemberAnnotationExpr()) {
            return Optional.of(expr.asSingleMemberAnnotationExpr().getMemberValue());
        }
        if (expr.isNormalAnnotationExpr()) {
            for (MemberValuePair pair : expr.asNormalAnnotationExpr().getPairs()) {
                if (Objects.equals(key, pair.getNameAsString())) {
                    return Optional.of(pair.getValue());
                }
            }
        }
    }
    return Optional.empty();
}
 
Example #6
Source File: AnnotatedMember.java    From jeddict with Apache License 2.0 6 votes vote down vote up
static Optional<String> getStringAttribute(AnnotationExpr annotationExpr, String attributeName) {
    Optional<Expression> expressionOpt = getAttribute(annotationExpr, attributeName);
    if (expressionOpt.isPresent()) {
        Expression expression = expressionOpt.get();
        if (expression.isStringLiteralExpr()) {
            return expression.toStringLiteralExpr()
                    .map(StringLiteralExpr::getValue);
        } else if (expression.isNameExpr()) {
            return expression.toNameExpr()
                    .map(NameExpr::getNameAsString);
        } else if (expression.isIntegerLiteralExpr()) {
            return expression.toIntegerLiteralExpr()
                    .map(IntegerLiteralExpr::asInt)
                    .map(String::valueOf);
        } else if (expression.isFieldAccessExpr() || expression.isBinaryExpr()) {
            return expressionOpt
                    .map(Expression::toString);
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return Optional.empty();
}
 
Example #7
Source File: AnnotatedMember.java    From jeddict with Apache License 2.0 6 votes vote down vote up
static Optional<Long> getLongAttribute(AnnotationExpr annotationExpr, String attributeName) {
    Optional<Expression> expressionOpt = getAttribute(annotationExpr, attributeName);
    if (expressionOpt.isPresent()) {
        Expression expression = expressionOpt.get();
        if (expression.isLongLiteralExpr()) {
            return expressionOpt.flatMap(exp -> exp.toLongLiteralExpr())
                    .map(exp -> exp.asLong());
        } else if (expression.isIntegerLiteralExpr()) {
            return expressionOpt.flatMap(exp -> exp.toIntegerLiteralExpr())
                    .map(exp -> exp.asInt())
                    .map(Long::valueOf);
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return Optional.empty();
}
 
Example #8
Source File: AnnotatedMember.java    From jeddict with Apache License 2.0 6 votes vote down vote up
static List<String> getClassNameAttributes(AnnotationExpr annotationExpr, String attributeName) {
    List<String> values = new ArrayList<>();
    Optional<Expression> expOptional = getAttribute(annotationExpr, attributeName);
    if (expOptional.isPresent()) {
        Expression expression = expOptional.get();
        if (expression.isClassExpr()) {
            values.add(expression.asClassExpr().getTypeAsString());
        } else if (expression.isArrayInitializerExpr()) {
            for (Node node : expression.asArrayInitializerExpr().getChildNodes()) {
                if (node instanceof ClassExpr) {
                    values.add(((ClassExpr) node).getTypeAsString());
                } else {
                    throw new UnsupportedOperationException();
                }
            }
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return values;
}
 
Example #9
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void visit(final TypeParameter n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    for (AnnotationExpr ann : n.getAnnotations()) {
        ann.accept(this, arg);
        printer.print(" ");
    }
    n.getName().accept(this, arg);
    if (!isNullOrEmpty(n.getTypeBound())) {
        printer.print(" extends ");
        for (final Iterator<ClassOrInterfaceType> i = n.getTypeBound().iterator(); i.hasNext(); ) {
            final ClassOrInterfaceType c = i.next();
            c.accept(this, arg);
            if (i.hasNext()) {
                printer.print(" & ");
            }
        }
    }
}
 
Example #10
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void visit(final ClassOrInterfaceType n, final Void arg) {
    printJavaComment(n.getComment(), arg);

    if (n.getScope().isPresent()) {
        n.getScope().get().accept(this, arg);
        printer.print(".");
    }
    for (AnnotationExpr ae : n.getAnnotations()) {
        ae.accept(this, arg);
        printer.print(" ");
    }

    n.getName().accept(this, arg);

    if (n.isUsingDiamondOperator()) {
        printer.print("<>");
    } else {
        printTypeArgs(n, arg);
    }
}
 
Example #11
Source File: RegistryMethodVisitor.java    From gauge-java with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(MethodDeclaration methodDeclaration, Object arg) {
    List<AnnotationExpr> annotations = methodDeclaration.getAnnotations();
    if (annotations.isEmpty()) {
        return;
    }

    for (AnnotationExpr annotationExpr : annotations) {
        if (!(annotationExpr instanceof SingleMemberAnnotationExpr)) {
            continue;
        }
        SingleMemberAnnotationExpr annotation = (SingleMemberAnnotationExpr) annotationExpr;
        if (annotation.getMemberValue() instanceof ArrayInitializerExpr) {
            ArrayInitializerExpr memberValue = (ArrayInitializerExpr) annotation.getMemberValue();
            for (Expression expression : memberValue.getValues()) {
                addStepToRegistry(expression, methodDeclaration, annotation);
            }
        } else {
            addStepToRegistry(annotation.getMemberValue(), methodDeclaration, annotation);
        }
    }
}
 
Example #12
Source File: AttributeSyncHandler.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void syncAnnotation(List<AnnotationExpr> annotationExprs, AttributeAnnotationLocationType locationType, Map<String, ImportDeclaration> imports) {
    for (AnnotationExpr annotationExpr : annotationExprs) {
        String annotationExprName = annotationExpr.getNameAsString();
        String annotationName;
        String annotationFQN;
        if (isFQN(annotationExprName)) {
            annotationFQN = annotationExprName;
            annotationName = unqualify(annotationExprName);
        } else {
            annotationFQN = imports.containsKey(annotationExprName)
                    ? imports.get(annotationExprName).getNameAsString() : annotationExprName;
            annotationName = annotationExprName;
        }

        if (!annotationFQN.startsWith(PERSISTENCE_PACKAGE)
                && !annotationFQN.startsWith(NOSQL_PACKAGE)
                && !annotationFQN.startsWith(BV_CONSTRAINTS_PACKAGE)
                && !annotationFQN.startsWith(JSONB_PACKAGE)
                && !annotationFQN.startsWith(JAXB_PACKAGE)
                && !JPA_ANNOTATIONS.contains(annotationFQN)
                && !JNOSQL_ANNOTATIONS.contains(annotationFQN)
                && !BV_ANNOTATIONS.contains(annotationFQN)
                && !JSONB_ANNOTATIONS.contains(annotationFQN)
                && !JAXB_ANNOTATIONS.contains(annotationFQN)) {
            String value = annotationExpr.toString();
            if (!attribute.getAnnotation()
                    .stream()
                    .filter(anot -> anot.getLocationType() == locationType)
                    .filter(anot -> anot.getName().contains(annotationName))
                    .findAny()
                    .isPresent()) {
                attribute.addRuntimeAnnotation(new AttributeAnnotation(value, locationType));
                addImportSnippet(value, imports);
            }
        }

    }
}
 
Example #13
Source File: ClassSourceVisitor.java    From wisdom with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the list of annotation contains the annotation  of given name.
 *
 * @param annos,          the annotation list
 * @param annotationName, the annotation name
 * @return <code>true</code> if the annotation list contains the given annotation.
 */
private boolean containsAnnotation(List<AnnotationExpr> annos, String annotationName) {
    for (AnnotationExpr anno : annos) {
        if (anno.getName().getName().equals(annotationName)) {
            return true;
        }
    }
    return false;
}
 
Example #14
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 #15
Source File: DSN.java    From scheduler with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void visit(MethodDeclaration n, Void arg) {
    for (AnnotationExpr a : n.getAnnotations()) {
        if (!a.getNameAsString().equals("CstrTest")) {
            return;
        }
    }
    System.out.println(n.getName());
    n.getRange().ifPresent(r -> l.add(r.end.line - r.begin.line));
    super.visit(n, arg);
}
 
Example #16
Source File: JavaDocParserVisitor.java    From jaxrs-analyzer with Apache License 2.0 5 votes vote down vote up
private MemberParameterTag createMemberParamTag(JavadocDescription javadocDescription, Stream<AnnotationExpr> annotationStream) {
    Map<String, String> annotations = annotationStream
            .filter(Expression::isSingleMemberAnnotationExpr)
            .collect(Collectors.toMap(a -> a.getName().getIdentifier(),
                    this::createMemberParamValue));
    return new MemberParameterTag(javadocDescription.toText(), annotations);
}
 
Example #17
Source File: JavaDocParserVisitor.java    From jaxrs-analyzer with Apache License 2.0 5 votes vote down vote up
private String createMemberParamValue(AnnotationExpr a) {
    Expression memberValue = a.asSingleMemberAnnotationExpr().getMemberValue();
    if (memberValue.getClass().isAssignableFrom(StringLiteralExpr.class))
        return memberValue.asStringLiteralExpr().asString();

    if (memberValue.getClass().isAssignableFrom(NameExpr.class))
        return memberValue.asNameExpr().getNameAsString();

    throw new IllegalArgumentException(String.format("Javadoc param type (%s) not supported.", memberValue.toString()));
}
 
Example #18
Source File: ReferenceTypeMerger.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@Override
public ReferenceType doMerge(ReferenceType first, ReferenceType second) {

  ReferenceType rf = new ReferenceType();
  rf.setArrayCount(first.getArrayCount());
  rf.setType(first.getType());
  rf.setAnnotations(mergeCollections(first.getAnnotations(), second.getAnnotations()));

  List<List<AnnotationExpr>> lists = null;
  if (first.getArraysAnnotations() == null) lists = second.getArraysAnnotations();
  if (second.getArraysAnnotations() == null) lists = first.getArraysAnnotations();

  if (lists == null && (first.getArraysAnnotations() != null && second.getArraysAnnotations() != null)) {
    lists = new ArrayList<>();

    List<List<AnnotationExpr>> faas = first.getArraysAnnotations();
    List<List<AnnotationExpr>> saas = second.getArraysAnnotations();

    int size = faas.size() > saas.size() ? faas.size() : saas.size();
    for (int i = 0; i < size; i++) {
      List<AnnotationExpr> faa = i < faas.size() ? faas.get(i) : null;
      List<AnnotationExpr> saa = i < saas.size() ? saas.get(i) : null;
      if (isAllNotNull(faa, saa)) {
        lists.add(mergeCollections(faa, saa));
      } else {
        lists.add(faa == null ? saa : faa);
      }
    }
  }
  rf.setArraysAnnotations(lists);

  return rf;
}
 
Example #19
Source File: OpenApiObjectGenerator.java    From flow with Apache License 2.0 5 votes vote down vote up
private String getEndpointName(ClassOrInterfaceDeclaration classDeclaration,
        AnnotationExpr endpointAnnotation) {
    String endpointName = Optional.ofNullable(endpointAnnotation)
            .filter(Expression::isSingleMemberAnnotationExpr)
            .map(Expression::asSingleMemberAnnotationExpr)
            .map(SingleMemberAnnotationExpr::getMemberValue)
            .map(Expression::asStringLiteralExpr)
            .map(LiteralStringValueExpr::getValue)
            .filter(GeneratorUtils::isNotBlank)
            .orElse(classDeclaration.getNameAsString());

    // detect the endpoint value name
    if (endpointName.equals(classDeclaration.getNameAsString()) && endpointAnnotation != null) {
        String endpointValueName = getParameterValueFromAnnotation(endpointAnnotation, "value");
        if (endpointValueName != null) {
            endpointName = endpointValueName.substring(1, endpointValueName.length() - 1);
        }
    }

    String validationError = endpointNameChecker.check(endpointName);
    if (validationError != null) {
        throw new IllegalStateException(
                String.format("Endpoint name '%s' is invalid, reason: '%s'",
                        endpointName, validationError));
    }
    return endpointName;
}
 
Example #20
Source File: AnnotatedMember.java    From jeddict with Apache License 2.0 5 votes vote down vote up
static Stream<AnnotationExplorer> getAnnotationAttributes(AnnotationExpr annotationExpr, String attributeName) {
    Stream<AnnotationExplorer> annotations = Stream.of();
    Optional<Expression> expressionOpt = getAttribute(annotationExpr, attributeName);
    if (expressionOpt.isPresent()) {
        Expression expression = expressionOpt.get();
        if (expression.isAnnotationExpr()) {
            annotations = expressionOpt
                    .map(exp -> exp.asAnnotationExpr())
                    .map(AnnotationExplorer::new)
                    .map(exp -> Stream.of(exp))
                    .orElse(Stream.of());
        } else if (expression.isArrayInitializerExpr()) {
            List<AnnotationExplorer> values = new ArrayList<>();
            List<Node> nodes = expression.asArrayInitializerExpr().getChildNodes();
            for (Node node : nodes) {
                if (node instanceof AnnotationExpr) {
                    AnnotationExplorer annotation = new AnnotationExplorer((AnnotationExpr) node);
                    values.add(annotation);
                } else if (node instanceof Comment) {
                    //ignore
                } else {
                    throw new UnsupportedOperationException();
                }
            }
            annotations = values.stream();
        } else {
            throw new UnsupportedOperationException();
        }

    }
    return annotations;
}
 
Example #21
Source File: JavaClassSyncHandler.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void syncAnnotations(List<AnnotationExpr> annotationExprs, ClassAnnotationLocationType locationType, Map<String, ImportDeclaration> imports) {
    for (AnnotationExpr annotationExpr : annotationExprs) {
        String annotationExprName = annotationExpr.getNameAsString();
        String annotationName;
        String annotationFQN;
        //TODO calculate using resolve type or find solution for static import ??
        if (isFQN(annotationExprName)) {
            annotationFQN = annotationExprName;
            annotationName = unqualify(annotationExprName);
        } else {
            annotationFQN = imports.containsKey(annotationExprName)
                    ? imports.get(annotationExprName).getNameAsString() : annotationExprName;
            annotationName = annotationExprName;
        }

        if (!annotationFQN.startsWith(PERSISTENCE_PACKAGE)
                && !annotationFQN.startsWith(NOSQL_PACKAGE)
                && !annotationFQN.startsWith(BV_CONSTRAINTS_PACKAGE)
                && !annotationFQN.startsWith(JSONB_PACKAGE)
                && !annotationFQN.startsWith(JAXB_PACKAGE)
                && !JPA_ANNOTATIONS.contains(annotationFQN)
                && !JNOSQL_ANNOTATIONS.contains(annotationFQN)
                && !BV_ANNOTATIONS.contains(annotationFQN)
                && !JSONB_ANNOTATIONS.contains(annotationFQN)
                && !JAXB_ANNOTATIONS.contains(annotationFQN)) {

            String value = annotationExpr.toString();
            if (!javaClass.getAnnotation()
                    .stream()
                    .filter(anot -> anot.getLocationType() == locationType)
                    .filter(anot -> anot.getName().contains(annotationName))
                    .findAny()
                    .isPresent()) {
                javaClass.addRuntimeAnnotation(new ClassAnnotation(value, locationType));
                syncImportSnippet(value, imports);;
            }
        }

    }
}
 
Example #22
Source File: AnnotatedClassPostProcessor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private String formatPattern(Parameter el) {
    Optional<AnnotationExpr> w = el.getAnnotationByName("When");
    AnnotationExpr when = w.orElseThrow(() -> new IllegalArgumentException("No When annotation"));
    return String.format(
            "  %s : %s\n",
            el.getNameAsString(),
            when.asSingleMemberAnnotationExpr().getMemberValue().asStringLiteralExpr().getValue());
}
 
Example #23
Source File: Sources.java    From sundrio with Apache License 2.0 5 votes vote down vote up
public AnnotationRef apply(AnnotationExpr annotation) {
    String name = annotation.getName().getName();
    String packageName = PACKAGENAME.apply(annotation);
    return new AnnotationRefBuilder()
            .withNewClassRef()
                .withNewDefinition()
                    .withName(name)
                    .withPackageName(packageName)
                .endDefinition()
            .endClassRef()
            .build();
}
 
Example #24
Source File: AnnotatedMember.java    From jeddict with Apache License 2.0 5 votes vote down vote up
static List<String> getEnumAttributes(AnnotationExpr annotationExpr, String attributeName) {
    List<String> values = emptyList();
    Optional<Expression> expressionOpt = getAttribute(annotationExpr, attributeName);
    if (expressionOpt.isPresent()) {
        Expression expression = expressionOpt.get();
        if (expression.isFieldAccessExpr()) {
            values = expressionOpt
                    .map(exp -> exp.asFieldAccessExpr())
                    .map(exp -> exp.getNameAsString())
                    .map(exp -> singletonList(exp))
                    .orElse(emptyList());
        } else if (expression.isNameExpr()) {
            values = expressionOpt
                    .map(exp -> exp.asNameExpr())
                    .map(exp -> exp.getNameAsString())
                    .map(exp -> singletonList(exp))
                    .orElse(emptyList());
        } else if (expression.isArrayInitializerExpr()) {
            values = new ArrayList<>();
            List<Node> nodes = expression.asArrayInitializerExpr().getChildNodes();
            for (Node node : nodes) {
                if (node instanceof NodeWithSimpleName) {
                    values.add(((NodeWithSimpleName) node).getNameAsString());
                } else {
                    throw new UnsupportedOperationException();
                }
            }
        } else {
            throw new UnsupportedOperationException();
        }

    }
    return values;
}
 
Example #25
Source File: AnnotatedMember.java    From jeddict with Apache License 2.0 5 votes vote down vote up
static Optional<String> getClassNameAttribute(AnnotationExpr annotationExpr, String attributeName) {
    try {
        return getResolvedClassAttribute(annotationExpr, attributeName)
                .map(ResolvedTypeDeclaration::getQualifiedName);
    } catch (Exception e) {
        return getTypeClassAttribute(annotationExpr, attributeName)
                .map(Type::toString);
    }
}
 
Example #26
Source File: ClassParser.java    From Briefness with Apache License 2.0 5 votes vote down vote up
private static Immersive checkImmersive(NodeList<AnnotationExpr> annotationExprs) {
    for (AnnotationExpr annotationExpr : annotationExprs) {
        if (annotationExpr.getNameAsString().equals(Immersive)) {
            String annotation = annotationExpr.toString();
            if (!annotation.contains("(")) return new Immersive();
            String content = annotation.substring(annotation.indexOf("(") + 1, annotation.indexOf(")")).replaceAll(" ", "");
            Immersive im = new Immersive();
            if (content.length() > 4) {
                String values[] = content.split(",");
                for (String value : values) {
                    String[] kv = value.split("=");
                    if (kv[0].equals(Immersive_statusColor)) {
                        im.setStatusColor(kv[1]);
                    } else if (kv[0].equals(Immersive_navigationColor)) {
                        im.setNavigationColor(kv[1]);
                    } else if (kv[0].equals(Immersive_statusEmbed)) {
                        im.setStatusEmbed(kv[1]);
                    } else if (kv[0].equals(Immersive_navigationEmbed)) {
                        im.setNavigationEmbed(kv[1]);
                    }
                }
            }
            return im;
        }
    }
    return null;
}
 
Example #27
Source File: AnnotatedClassPostProcessor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public static AnnotatedClassPostProcessor scan(Stream<Path> files) {
    List<CompilationUnit> annotatedUnits = files
            .peek(System.out::println)
            .map(p -> {
                try {
                    return StaticJavaParser.parse(p);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }).filter(cu -> cu.findFirst(AnnotationExpr.class, ann -> ann.getNameAsString().endsWith("When")).isPresent())
            .collect(Collectors.toList());

    return new AnnotatedClassPostProcessor(annotatedUnits);
}
 
Example #28
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
private void printMemberAnnotations(final NodeList<AnnotationExpr> annotations, final Void arg) {
    if (annotations.isEmpty()) {
        return;
    }
    for (final AnnotationExpr a : annotations) {
        a.accept(this, arg);
        printer.println();
    }
}
 
Example #29
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
private void printAnnotations(final NodeList<AnnotationExpr> annotations, boolean prefixWithASpace,
                              final Void arg) {
    if (annotations.isEmpty()) {
        return;
    }
    if (prefixWithASpace) {
        printer.print(" ");
    }
    for (AnnotationExpr annotation : annotations) {
        annotation.accept(this, arg);
        printer.print(" ");
    }
}
 
Example #30
Source File: RequestMappingHelper.java    From apigcc with MIT License 5 votes vote down vote up
/**
 * 解析HTTP Method
 * @param n
 * @return
 */
public static Method pickMethod(MethodDeclaration n){
    if(n.isAnnotationPresent(ANNOTATION_GET_MAPPING)){
        return Method.GET;
    }
    if(n.isAnnotationPresent(ANNOTATION_POST_MAPPING)){
        return Method.POST;
    }
    if(n.isAnnotationPresent(ANNOTATION_PUT_MAPPING)){
        return Method.PUT;
    }
    if(n.isAnnotationPresent(ANNOTATION_PATCH_MAPPING)){
        return Method.PATCH;
    }
    if(n.isAnnotationPresent(ANNOTATION_DELETE_MAPPING)){
        return Method.DELETE;
    }
    if(n.isAnnotationPresent(ANNOTATION_REQUEST_MAPPING)){
        AnnotationExpr annotationExpr = n.getAnnotationByName(ANNOTATION_REQUEST_MAPPING).get();
        Optional<Expression> expressionOptional = AnnotationHelper.attr(annotationExpr, "method");
        if (expressionOptional.isPresent()) {
            Expression expression = expressionOptional.get();
            if(expression.isArrayInitializerExpr()){
                NodeList<Expression> values = expression.asArrayInitializerExpr().getValues();
                if(values!=null&&values.size()>0){
                    return Method.valueOf(values.get(0).toString().replaceAll("RequestMethod.",""));
                }
            }
            return Method.of(expression.toString().replaceAll("RequestMethod.",""));
        }
    }
    return Method.GET;
}