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

The following examples show how to use com.github.javaparser.ast.body.BodyDeclaration. 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: CdpClientGenerator.java    From selenium with Apache License 2.0 6 votes vote down vote up
public BodyDeclaration<?> toMethodDeclaration() {
  MethodDeclaration methodDecl = new MethodDeclaration().setName(name).setPublic(true).setStatic(true);
  if (type == null) {
    methodDecl.setType("Event<Void>").getBody().get().addStatement(
        String.format("return new Event<>(\"%s.%s\");", domain.name, name));
  } else {
    methodDecl.setType(String.format("Event<%s>", getFullJavaType()));
    if (type instanceof VoidType) {
      methodDecl.getBody().get().addStatement(
          String.format("return new Event<>(\"%s.%s\", input -> null);", domain.name, name));
    } else if (type instanceof ObjectType) {
      methodDecl.getBody().get().addStatement(String.format(
          "return new Event<>(\"%s.%s\", input -> %s);",
          domain.name, name, type.getMapper()));
    } else {
      methodDecl.getBody().get().addStatement(String.format(
          "return new Event<>(\"%s.%s\", ConverterFunctions.map(\"%s\", %s));",
          domain.name, name, type.getName(), type.getTypeToken()));
    }
  }
  return methodDecl;
}
 
Example #2
Source File: RuleConfigGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public List<BodyDeclaration<?>> members() {

        if (annotator != null) {
            FieldDeclaration relcFieldDeclaration = annotator.withOptionalInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.multiInstanceInjectionType(), RuleEventListenerConfig.class), VAR_RULE_EVENT_LISTENER_CONFIGS)));
            members.add(relcFieldDeclaration);

            FieldDeclaration aelFieldDeclaration = annotator.withOptionalInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.multiInstanceInjectionType(), AgendaEventListener.class), VAR_AGENDA_EVENT_LISTENERS)));
            members.add(aelFieldDeclaration);

            FieldDeclaration rrelFieldDeclaration = annotator.withOptionalInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.multiInstanceInjectionType(), RuleRuntimeEventListener.class), VAR_RULE_RUNTIME_EVENT_LISTENERS)));
            members.add(rrelFieldDeclaration);

            members.add(generateExtractEventListenerConfigMethod());
            members.add(generateMergeEventListenerConfigMethod());
        } else {
            FieldDeclaration defaultRelcFieldDeclaration = new FieldDeclaration()
                    .setModifiers(Modifier.Keyword.PRIVATE)
                    .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, RuleEventListenerConfig.class.getCanonicalName()), VAR_DEFAULT_RULE_EVENT_LISTENER_CONFIG, newObject(DefaultRuleEventListenerConfig.class)));
            members.add(defaultRelcFieldDeclaration);
        }

        return members;
    }
 
Example #3
Source File: DecisionConfigGenerator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public List<BodyDeclaration<?>> members() {

        if (annotator != null) {
            FieldDeclaration delcFieldDeclaration = annotator.withOptionalInjection(new FieldDeclaration()
                    .addVariable(new VariableDeclarator(genericType(annotator.multiInstanceInjectionType(), DecisionEventListenerConfig.class), VAR_DECISION_EVENT_LISTENER_CONFIG)));
            members.add(delcFieldDeclaration);

            FieldDeclaration drelFieldDeclaration = annotator.withOptionalInjection(new FieldDeclaration()
                    .addVariable(new VariableDeclarator(genericType(annotator.multiInstanceInjectionType(), DMNRuntimeEventListener.class), VAR_DMN_RUNTIME_EVENT_LISTENERS)));
            members.add(drelFieldDeclaration);

            members.add(generateExtractEventListenerConfigMethod());
            members.add(generateMergeEventListenerConfigMethod());
        } else {
            FieldDeclaration defaultDelcFieldDeclaration = new FieldDeclaration()
                    .setModifiers(Modifier.Keyword.PRIVATE)
                    .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, DecisionEventListenerConfig.class.getCanonicalName()), VAR_DEFAULT_DECISION_EVENT_LISTENER_CONFIG, newObject(DefaultDecisionEventListenerConfig.class)));
            members.add(defaultDelcFieldDeclaration);
        }

        return members;
    }
 
Example #4
Source File: ASTHelper.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Gets the field declaration map.
 *
 * @param <T> the generic type
 * @param node the class declaration
 * @param type the type
 * @return the field declaration map
 */
static <T extends BodyDeclaration> Map<String, T> getBodyDeclarationMap(Node node, Class<T> type) {
    List<Node> children = node.getChildNodes();
    if (CollectionUtil.isEmpty(children)) {
        return new HashMap<String, T>(0);
    }

    Map<String, T> bodyMap = new CaseInsensitiveHashMap<T>(children.size());

    List<T> bodyDeclarations = getNodesByType(node, type);

    for (T bodyDeclaration : bodyDeclarations) {
        if (bodyDeclaration instanceof FieldDeclaration) {
            FieldDeclaration fieldDeclaration = (FieldDeclaration) bodyDeclaration;
            VariableDeclarator variableDeclaratorId = getOneNodesByType(fieldDeclaration, VariableDeclarator.class);
            bodyMap.put(variableDeclaratorId.getName().toString(), bodyDeclaration);
        } else if (bodyDeclaration instanceof MethodDeclaration) {
            MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
            bodyMap.put(methodDeclaration.getNameAsString(), bodyDeclaration);
        }
    }
    return bodyMap;
}
 
Example #5
Source File: ASTHelper.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
private static String getAllCommentsText(BodyDeclaration declaration) {
    List<Comment> allContainedComments = declaration.getAllContainedComments();
    StringBuffer sb = new StringBuffer();
    boolean append =false;
    Optional<Comment> commentOp = declaration.getComment();
    if (commentOp.isPresent()){
        sb.append(commentOp.get().getContent()) ;
        append=true;
    }
    for (Comment comment : allContainedComments) {
        if (append){
            sb.append(" ");
        }
        sb.append(comment.toString());
        append=true;
    }
    String oldCommentText = sb.toString();
    return oldCommentText;
}
 
Example #6
Source File: FinalRClassBuilder.java    From Briefness with Apache License 2.0 6 votes vote down vote up
private static void addResourceType(List<String> supportedTypes, TypeSpec.Builder result,
                                    ClassOrInterfaceDeclaration node, boolean useLegacyTypes) {
  if (!supportedTypes.contains(node.getNameAsString())) {
    return;
  }

  String type = node.getNameAsString();
  TypeSpec.Builder resourceType = TypeSpec.classBuilder(type)
      .addModifiers(PUBLIC, STATIC, FINAL);

  for (BodyDeclaration field : node.getMembers()) {
    if (field instanceof FieldDeclaration) {
      FieldDeclaration declaration = (FieldDeclaration) field;
      // Check that the field is an Int because styleable also contains Int arrays which can't be
      // used in annotations.
      if (isInt(declaration)) {
        addResourceField(resourceType, declaration.getVariables().get(0),
                getSupportAnnotationClass(type, useLegacyTypes));
      }
    }
  }

  result.addType(resourceType.build());
}
 
Example #7
Source File: BodyDeclarationComparator.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(BodyDeclaration<?> o1, BodyDeclaration<?> o2) {
    if (o1 instanceof FieldDeclaration && o2 instanceof FieldDeclaration) {
        return 0;
    }
    if (o1 instanceof FieldDeclaration && !(o2 instanceof FieldDeclaration)) {
        return -1;
    }
    
    if (o1 instanceof ConstructorDeclaration && o2 instanceof ConstructorDeclaration) {
        return 0;
    }
    if (o1 instanceof ConstructorDeclaration && o2 instanceof MethodDeclaration) {
        return -1;
    }
    if (o1 instanceof ConstructorDeclaration && o2 instanceof FieldDeclaration) {
        return 1;
    }
    return 1;
}
 
Example #8
Source File: Reverser.java    From android-reverse-r with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(ClassOrInterfaceDeclaration clazz, Object arg) {
    for (BodyDeclaration member : clazz.getMembers()) {
        if (member instanceof ClassOrInterfaceDeclaration)
            visit((ClassOrInterfaceDeclaration)member, arg);
        else if (member instanceof FieldDeclaration) {
            FieldDeclaration field = (FieldDeclaration)member;
            String type = null != field.getType() ? field.getType().toString() : "";
            if (type.equals("int")) {
                VariableDeclarator variable = field.getVariables().stream().findFirst().get();
                String name = variable.getId().toString();
                Integer value = null != variable.getInit() ? Integer.parseInt(variable.getInit().toString()) : 0;
                // decimal value of 0x7f000000, which is what AAPT starts numbering at - https://stackoverflow.com/questions/6517151/how-does-the-mapping-between-android-resources-and-resources-id-work/6646113#6646113
                if (value >= 2130706432) {
                    name = "R." + ((ClassOrInterfaceDeclaration)field.getParentNode()).getName() + "." + name;
                    transform.put(value, name);
                }
            }
        }
    }
}
 
Example #9
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 #10
Source File: JavaClassSyncHandler.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void syncInnerClassOrInterfaceOrEnumSnippet(BodyDeclaration<?> lastScannedMember, Attribute lastScannedAttribute, BodyDeclaration<?> member, Map<String, ImportDeclaration> imports) {
    if (lastScannedAttribute == null) {
        syncInnerClassOrInterfaceOrEnumSnippet(member, imports);
    } else {
        if (lastScannedMember instanceof MethodDeclaration) {
            syncAttributeSnippet(lastScannedAttribute, AttributeSnippetLocationType.AFTER_METHOD, member.toString(), imports);
        } else if (lastScannedMember instanceof FieldDeclaration) {
            syncAttributeSnippet(lastScannedAttribute, AttributeSnippetLocationType.AFTER_FIELD, member.toString(), imports);
        } else {
            syncInnerClassOrInterfaceOrEnumSnippet(member, imports);
        }
    }
}
 
Example #11
Source File: JavaClassSyncHandler.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void syncMethodSnippet(BodyDeclaration<?> lastScannedMember, Attribute lastScannedAttribute, MethodDeclaration method, Map<String, ImportDeclaration> imports) {
    if (lastScannedAttribute == null) {
        syncMethodSnippet(method, imports);
    } else {
        if (lastScannedMember instanceof MethodDeclaration) {
            syncAttributeSnippet(lastScannedAttribute, AttributeSnippetLocationType.AFTER_METHOD, method.toString(), imports);
        } else if (lastScannedMember instanceof FieldDeclaration) {
            syncAttributeSnippet(lastScannedAttribute, AttributeSnippetLocationType.AFTER_FIELD, method.toString(), imports);
        } else {
            syncMethodSnippet(method, imports);
        }
    }
}
 
Example #12
Source File: JavaClassSyncHandler.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void syncInitializationBlockSnippet(BodyDeclaration<?> lastScannedMember, Attribute lastScannedAttribute, InitializerDeclaration initializationBlock, Map<String, ImportDeclaration> imports) {
    if (lastScannedAttribute == null) {
        syncInitializationBlockSnippet(initializationBlock, imports);
    } else {
        if (lastScannedMember instanceof MethodDeclaration) {
            syncAttributeSnippet(lastScannedAttribute, AttributeSnippetLocationType.AFTER_METHOD, initializationBlock.toString(), imports);
        } else if (lastScannedMember instanceof FieldDeclaration) {
            syncAttributeSnippet(lastScannedAttribute, AttributeSnippetLocationType.AFTER_FIELD, initializationBlock.toString(), imports);
        } else {
            syncInitializationBlockSnippet(initializationBlock, imports);
        }
    }
}
 
Example #13
Source File: JavaClassSyncHandler.java    From jeddict with Apache License 2.0 5 votes vote down vote up
private void syncFieldSnippet(BodyDeclaration<?> lastScannedMember, Attribute lastScannedAttribute, FieldDeclaration field, Map<String, ImportDeclaration> imports) {
    if (lastScannedAttribute == null) {
        syncFieldSnippet(field, imports);
    } else {
        if (lastScannedMember instanceof MethodDeclaration) {
            syncAttributeSnippet(lastScannedAttribute, AttributeSnippetLocationType.AFTER_METHOD, field.toString(), imports);
        } else if (lastScannedMember instanceof FieldDeclaration) {
            syncAttributeSnippet(lastScannedAttribute, AttributeSnippetLocationType.AFTER_FIELD, field.toString(), imports);
        } else {
            syncFieldSnippet(field, imports);
        }
    }
}
 
Example #14
Source File: OpenApiObjectGenerator.java    From flow with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("squid:S1172")
private SourceRoot.Callback.Result process(Path localPath,
        Path absolutePath, ParseResult<CompilationUnit> result) {
    result.ifSuccessful(compilationUnit -> compilationUnit.getPrimaryType()
            .filter(BodyDeclaration::isClassOrInterfaceDeclaration)
            .map(BodyDeclaration::asClassOrInterfaceDeclaration)
            .filter(classOrInterfaceDeclaration -> !classOrInterfaceDeclaration
                    .isInterface())
            .map(this::appendNestedClasses).orElse(Collections.emptyList())
            .forEach(classOrInterfaceDeclaration -> this.parseClass(
                    classOrInterfaceDeclaration, compilationUnit)));
    pathItems.forEach((pathName, pathItem) -> openApiModel.getPaths()
            .addPathItem(pathName, pathItem));
    return SourceRoot.Callback.Result.DONT_SAVE;
}
 
Example #15
Source File: JavaFileAnalyzer.java    From deadcode4j with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Optional<String> resolveInnerReference(
        @Nonnull Qualifier firstQualifier,
        @Nullable Iterable<? extends BodyDeclaration> bodyDeclarations) {
    for (TypeDeclaration typeDeclaration : emptyIfNull(bodyDeclarations).filter(TypeDeclaration.class)) {
        if (firstQualifier.getName().equals(typeDeclaration.getName())) {
            return of(resolveReferencedType(firstQualifier, typeDeclaration));
        }
    }
    return absent();
}
 
Example #16
Source File: ParameterNameVisitor.java    From meghanada-server with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(ClassOrInterfaceDeclaration n, Object arg) {
  super.visit(n, arg);
  NodeList<Modifier> modifiers = n.getModifiers();
  if (!modifiers.contains(Modifier.privateModifier())) {
    final List<BodyDeclaration<?>> members = n.getMembers();
    final SimpleName simpleName = n.getName();
    final String clazz = simpleName.getId();
    // String clazz = n.getName();
    this.className = this.pkg + '.' + clazz;
    log.debug("class {}", this.className);
    int i = 0;
    for (final BodyDeclaration<?> body : members) {
      if (body instanceof MethodDeclaration) {
        MethodDeclaration methodDeclaration = (MethodDeclaration) body;
        this.getParameterNames(methodDeclaration, n.isInterface());
        i++;
      } else if (body instanceof ConstructorDeclaration) {
        // Constructor
      } else if (body instanceof ClassOrInterfaceDeclaration) {
        final ClassOrInterfaceDeclaration classOrInterfaceDeclaration =
            (ClassOrInterfaceDeclaration) body;
        String name = classOrInterfaceDeclaration.getName().getIdentifier();
        String key = this.pkg + '.' + name;
        name = this.originClassName + '.' + name;
        for (MethodParameterNames mpn : this.parameterNamesList) {
          if (mpn != null && mpn.className != null && mpn.className.equals(key)) {
            mpn.className = name;
          }
        }
      }
    }

    if (i > 0 && this.names.className != null) {
      this.parameterNamesList.add(this.names);
      this.names = new MethodParameterNames();
    }
  }
}
 
Example #17
Source File: GeneralFixture.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(ClassOrInterfaceDeclaration n, Void arg) {
    NodeList<BodyDeclaration<?>> members = n.getMembers();
    for (int i = 0; i < members.size(); i++) {
        if (members.get(i) instanceof MethodDeclaration) {
            methodDeclaration = (MethodDeclaration) members.get(i);

            //Get a list of all test methods
            if (Util.isValidTestMethod(methodDeclaration)) {
                methodList.add(methodDeclaration);
            }

            //Get the setup method
            if (Util.isValidSetupMethod(methodDeclaration)) {
                //It should have a body
                if (methodDeclaration.getBody().isPresent()) {
                    setupMethod = methodDeclaration;
                }
            }
        }

        //Get all fields in the class
        if (members.get(i) instanceof FieldDeclaration) {
            fieldList.add((FieldDeclaration) members.get(i));
        }
    }
}
 
Example #18
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
private void printMembers(final NodeList<BodyDeclaration<?>> members, final Void arg) {
    for (final BodyDeclaration<?> member : members) {
        printer.println();
        member.accept(this, arg);
        printer.println();
    }
}
 
Example #19
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private int findConstructor(NodeList<BodyDeclaration<?>> classMembers) {
  int i = 0;
  for (BodyDeclaration<?> bd : classMembers) {
    if (bd instanceof ConstructorDeclaration) {
      return i;
    }
    i++;
  }
  return -1;
}
 
Example #20
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private boolean hasTypeFields(NodeList<BodyDeclaration<?>> members) {
    boolean hasType = false;
    boolean hasTypeId = false;
    for (BodyDeclaration<?> bd : members) {
      if (bd instanceof FieldDeclaration) {
        FieldDeclaration f = (FieldDeclaration)bd;
        EnumSet<Modifier> m = f.getModifiers();
        if (m.contains(Modifier.PUBLIC) &&
            m.contains(Modifier.STATIC) &&
            m.contains(Modifier.FINAL) 
//            &&
//            getTypeName(f.getType()).equals("int")
            ) {
          List<VariableDeclarator> vds = f.getVariables();
          for (VariableDeclarator vd : vds) {
            if (vd.getType().equals(intType)) {
              String n = vd.getNameAsString();
              if (n.equals("type")) hasType = true;
              if (n.equals("typeIndexID")) hasTypeId = true;
              if (hasTypeId && hasType) {
                return true;
              }
            }
          }
        }
      }
    } // end of for
    return false;
  }
 
Example #21
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Check if the top level class looks like a JCas class, and report if not:
 *   has 0, 1, and 2 element constructors
 *   has static final field defs for type and typeIndexID
 *   
 *   Also check if V2 style: 2 arg constructor arg types
 *   Report if looks like V3 style due to args of 2 arg constructor
 *   
 *   if class doesn't extend anything, not a JCas class.
 *   if class is enum, not a JCas class
 * @param n -
 * @param ignore -
 */
@Override
public void visit(ClassOrInterfaceDeclaration n, Object ignore) {
  // do checks to see if this is a JCas class; if not report skipped
 
  Optional<Node> maybeParent = n.getParentNode();
  if (maybeParent.isPresent()) {
    Node parent = maybeParent.get();
    if (parent instanceof CompilationUnit) {
      updateClassName(n);
      if (isBuiltinJCas) {
        // is a built-in class, skip it
        super.visit(n, ignore);
        return;
      }
      NodeList<ClassOrInterfaceType> supers = n.getExtendedTypes();
      if (supers == null || supers.size() == 0) {
        reportNotJCasClass("class doesn't extend a superclass");
        super.visit(n, ignore);
        return; 
      }
      
      NodeList<BodyDeclaration<?>> members = n.getMembers();
      setHasJCasConstructors(members);
      if (hasV2Constructors && hasTypeFields(members)) {
        reportV2Class();
        super.visit(n,  ignore);
        return;
      }
      if (hasV2Constructors) {
        reportNotJCasClassMissingTypeFields();
        return;
      }
      if (hasV3Constructors) {
        reportV3Class();
        return;
      }
      reportNotJCasClass("missing v2 constructors");
      return;        
    }
  }
  
  super.visit(n,  ignore);
  return;
  
}
 
Example #22
Source File: BodyDeclarationMerger.java    From dolphin with Apache License 2.0 4 votes vote down vote up
/**
 * Without further information, we can do nothing
 */
@Override
public boolean doIsEquals(BodyDeclaration first, BodyDeclaration second) {
  return first.equals(second);
}
 
Example #23
Source File: ClassExplorer.java    From jeddict with Apache License 2.0 4 votes vote down vote up
private boolean findFieldAccess() {
    boolean fieldAccessValue = false;
    boolean accessTypeDetected = false;
    NodeList<BodyDeclaration<?>> members = type.getMembers();

    if (isEntity() || isMappedSuperclass() || isEmbeddable()) {
        for (BodyDeclaration<?> member : members) {
            if (member.isAnnotationPresent(javax.persistence.Id.class)
                    || member.isAnnotationPresent(javax.persistence.Basic.class)
                    || member.isAnnotationPresent(javax.persistence.Transient.class)
                    || member.isAnnotationPresent(javax.persistence.Version.class)
                    || member.isAnnotationPresent(javax.persistence.ElementCollection.class)
                    || member.isAnnotationPresent(javax.persistence.Embedded.class)
                    || member.isAnnotationPresent(javax.persistence.EmbeddedId.class)
                    || member.isAnnotationPresent(javax.persistence.OneToMany.class)
                    || member.isAnnotationPresent(javax.persistence.OneToOne.class)
                    || member.isAnnotationPresent(javax.persistence.ManyToMany.class)
                    || member.isAnnotationPresent(javax.persistence.ManyToOne.class)
                    || member.isAnnotationPresent(javax.persistence.Column.class)) {
                if (member instanceof FieldDeclaration) {
                    fieldAccessValue = true;
                }
                accessTypeDetected = true;
            }
            if (accessTypeDetected) {
                break;
            }
        }
    } else {
        if (type instanceof ClassOrInterfaceDeclaration) {
            ClassOrInterfaceDeclaration clazz = (ClassOrInterfaceDeclaration) type;
            if (!clazz.getExtendedTypes().isEmpty()) {
                ClassOrInterfaceType parentClassType = clazz.getExtendedTypes().get(0);
                String parentClassQualifiedName = parentClassType.resolve().asReferenceType().getQualifiedName();
                try {
                    fieldAccessValue = getSource().createClass(parentClassQualifiedName)
                            .map(ClassExplorer::isFieldAccess)
                            .orElse(true);
                } catch (FileNotFoundException ex) {
                    Exceptions.printStackTrace(ex);
                    fieldAccessValue = true;
                }
            } else {
                fieldAccessValue = true;
            }
        }
    }
    if (!accessTypeDetected) {
        LOG.log(WARNING, "Failed to detect correct access type for class: {0}", type.getName());
    }
    return fieldAccessValue;
}
 
Example #24
Source File: MemberExplorer.java    From jeddict with Apache License 2.0 4 votes vote down vote up
public void setAnnotatedMember(BodyDeclaration annotationMember) {
    this.annotatedMember = annotationMember;
}
 
Example #25
Source File: MemberExplorer.java    From jeddict with Apache License 2.0 4 votes vote down vote up
@Override
protected BodyDeclaration getAnnotatedMember() {
    return annotatedMember;
}
 
Example #26
Source File: JavaClassSyncHandler.java    From jeddict with Apache License 2.0 4 votes vote down vote up
private void syncInnerClassOrInterfaceOrEnumSnippet(BodyDeclaration<?> member, Map<String, ImportDeclaration> imports) {
    if (isClassMemberSnippetExist()) {
        return;
    }
    syncClassSnippet(AFTER_METHOD, member.toString(), imports);
}
 
Example #27
Source File: BodyDeclarationMerger.java    From dolphin with Apache License 2.0 4 votes vote down vote up
@Override
public BodyDeclaration doMerge(BodyDeclaration first, BodyDeclaration second) {
  return first;
}
 
Example #28
Source File: IRRepresentation.java    From SnowGraph with Apache License 2.0 4 votes vote down vote up
private IRRepresentation(String methodBody) {
    final BodyDeclaration<?> cu = JavaParser.parseBodyDeclaration(methodBody);
    cu.accept(new IRVisitor(this), new VisitorContext(this, null, null));
}
 
Example #29
Source File: RuleUnitContainerGenerator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public ClassOrInterfaceDeclaration classDeclaration() {

    NodeList<BodyDeclaration<?>> declarations = new NodeList<>();

    // declare field `application`
    FieldDeclaration applicationFieldDeclaration = new FieldDeclaration();
    applicationFieldDeclaration
            .addVariable( new VariableDeclarator( new ClassOrInterfaceType(null, "Application"), "application") )
            .setModifiers( Modifier.Keyword.PRIVATE, Modifier.Keyword.FINAL );
    declarations.add(applicationFieldDeclaration);

    ConstructorDeclaration constructorDeclaration = new ConstructorDeclaration("RuleUnits")
            .addModifier(Modifier.Keyword.PUBLIC)
            .addParameter( "Application", "application" )
            .setBody( new BlockStmt().addStatement( "this.application = application;" ) );
    declarations.add(constructorDeclaration);

    // declare field `ruleRuntimeBuilder`
    FieldDeclaration kieRuntimeFieldDeclaration = new FieldDeclaration();
    kieRuntimeFieldDeclaration
            .addVariable(new VariableDeclarator( new ClassOrInterfaceType(null, KieRuntimeBuilder.class.getCanonicalName()), "ruleRuntimeBuilder")
            .setInitializer(new ObjectCreationExpr().setType(ProjectSourceClass.PROJECT_RUNTIME_CLASS)))
            .setModifiers( Modifier.Keyword.PRIVATE, Modifier.Keyword.FINAL );
    declarations.add(kieRuntimeFieldDeclaration);

    // declare method ruleRuntimeBuilder()
    MethodDeclaration methodDeclaration = new MethodDeclaration()
            .addModifier(Modifier.Keyword.PUBLIC)
            .setName("ruleRuntimeBuilder")
            .setType(KieRuntimeBuilder.class.getCanonicalName())
            .setBody(new BlockStmt().addStatement(new ReturnStmt(new FieldAccessExpr(new ThisExpr(), "ruleRuntimeBuilder"))));
    declarations.add(methodDeclaration);

    declarations.addAll(factoryMethods);
    declarations.add(genericFactoryById());

    ClassOrInterfaceDeclaration cls = super.classDeclaration()
            .setMembers(declarations);

    cls.getMembers().sort(new BodyDeclarationComparator());

    return cls;
}
 
Example #30
Source File: ProcessConfigGenerator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public List<BodyDeclaration<?>> members() {

        FieldDeclaration defaultWihcFieldDeclaration = new FieldDeclaration()
                .setModifiers(Modifier.Keyword.PRIVATE)
                .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, WorkItemHandlerConfig.class.getCanonicalName()), VAR_DEFAULT_WORK_ITEM_HANDLER_CONFIG, newObject(DefaultWorkItemHandlerConfig.class)));
        members.add(defaultWihcFieldDeclaration);

        FieldDeclaration defaultUowFieldDeclaration = new FieldDeclaration()
                .setModifiers(Modifier.Keyword.PRIVATE)
                .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, UnitOfWorkManager.class.getCanonicalName()), VAR_DEFAULT_UNIT_OF_WORK_MANAGER, newObject(DefaultUnitOfWorkManager.class, newObject(CollectingUnitOfWorkFactory.class))));
        members.add(defaultUowFieldDeclaration);

        FieldDeclaration defaultJobsServiceFieldDeclaration = new FieldDeclaration()
                .setModifiers(Modifier.Keyword.PRIVATE)
                .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, JobsService.class.getCanonicalName()), VAR_DEFAULT_JOBS_SEVICE, new NullLiteralExpr()));
        members.add(defaultJobsServiceFieldDeclaration);

        if (annotator != null) {
            FieldDeclaration wihcFieldDeclaration = annotator.withInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.optionalInstanceInjectionType(), WorkItemHandlerConfig.class), VAR_WORK_ITEM_HANDLER_CONFIG)));
            members.add(wihcFieldDeclaration);

            FieldDeclaration uowmFieldDeclaration = annotator.withInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.optionalInstanceInjectionType(), UnitOfWorkManager.class), VAR_UNIT_OF_WORK_MANAGER)));
            members.add(uowmFieldDeclaration);

            FieldDeclaration jobsServiceFieldDeclaration = annotator.withInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.optionalInstanceInjectionType(), JobsService.class), VAR_JOBS_SERVICE)));
            members.add(jobsServiceFieldDeclaration);

            FieldDeclaration pelcFieldDeclaration = annotator.withOptionalInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.multiInstanceInjectionType(), ProcessEventListenerConfig.class), VAR_PROCESS_EVENT_LISTENER_CONFIGS)));
            members.add(pelcFieldDeclaration);

            FieldDeclaration pelFieldDeclaration = annotator.withOptionalInjection(new FieldDeclaration().addVariable(new VariableDeclarator(genericType(annotator.multiInstanceInjectionType(), ProcessEventListener.class), VAR_PROCESS_EVENT_LISTENERS)));
            members.add(pelFieldDeclaration);

            members.add(extractOptionalInjection(WorkItemHandlerConfig.class.getCanonicalName(), VAR_WORK_ITEM_HANDLER_CONFIG, VAR_DEFAULT_WORK_ITEM_HANDLER_CONFIG, annotator));
            members.add(extractOptionalInjection(UnitOfWorkManager.class.getCanonicalName(), VAR_UNIT_OF_WORK_MANAGER, VAR_DEFAULT_UNIT_OF_WORK_MANAGER, annotator));
            members.add(extractOptionalInjection(JobsService.class.getCanonicalName(), VAR_JOBS_SERVICE, VAR_DEFAULT_JOBS_SEVICE, annotator));

            members.add(generateExtractEventListenerConfigMethod());
            members.add(generateMergeEventListenerConfigMethod());
        } else {
            FieldDeclaration defaultPelcFieldDeclaration = new FieldDeclaration()
                    .setModifiers(Modifier.Keyword.PRIVATE)
                    .addVariable(new VariableDeclarator(new ClassOrInterfaceType(null, ProcessEventListenerConfig.class.getCanonicalName()), VAR_DEFAULT_PROCESS_EVENT_LISTENER_CONFIG, newObject(DefaultProcessEventListenerConfig.class)));
            members.add(defaultPelcFieldDeclaration);
        }

        return members;
    }