Java Code Examples for com.github.javaparser.ast.body.MethodDeclaration#getModifiers()

The following examples show how to use com.github.javaparser.ast.body.MethodDeclaration#getModifiers() . 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: LazyTest.java    From TestSmellDetector with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The purpose of this method is to 'visit' all test methods.
 */
@Override
public void visit(MethodDeclaration n, Void arg) {
    // ensure that this method is only executed for the test file
    if (Objects.equals(fileType, TEST_FILE)) {
        if (Util.isValidTestMethod(n)) {
            currentMethod = n;
            testMethod = new TestMethod(currentMethod.getNameAsString());
            testMethod.setHasSmell(false); //default value is false (i.e. no smell)
            super.visit(n, arg);

            //reset values for next method
            currentMethod = null;
            productionVariables = new ArrayList<>();
        }
    } else { //collect a list of all public/protected members of the production class
        for (Modifier modifier : n.getModifiers()) {
            if (modifier.name().toLowerCase().equals("public") || modifier.name().toLowerCase().equals("protected")) {
                productionMethods.add(n);
            }
        }

    }
}
 
Example 2
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 3
Source File: EagerTest.java    From TestSmellDetector with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The purpose of this method is to 'visit' all test methods.
 */
@Override
public void visit(MethodDeclaration n, Void arg) {
    // ensure that this method is only executed for the test file
    if (Objects.equals(fileType, TEST_FILE)) {
        if (Util.isValidTestMethod(n)) {
            currentMethod = n;
            testMethod = new TestMethod(currentMethod.getNameAsString());
            testMethod.setHasSmell(false); //default value is false (i.e. no smell)
            super.visit(n, arg);

            testMethod.setHasSmell(eagerCount > 1); //the method has a smell if there is more than 1 call to production methods
            smellyElementList.add(testMethod);

            //reset values for next method
            currentMethod = null;
            eagerCount = 0;
            productionVariables = new ArrayList<>();
            calledMethods = new ArrayList<>();
        }
    } else { //collect a list of all public/protected members of the production class
        for (Modifier modifier : n.getModifiers()) {
            if (modifier.name().toLowerCase().equals("public") || modifier.name().toLowerCase().equals("protected")) {
                productionMethods.add(n);
            }
        }

    }
}
 
Example 4
Source File: ConfigurableEagerTest.java    From CodeDefenders with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * The purpose of this method is to 'visit' all test methods.
 */
@Override
public void visit(MethodDeclaration n, Void arg) {
    // ensure that this method is only executed for the test file
    if (Objects.equals(fileType, TEST_FILE)) {
        if (Util.isValidTestMethod(n)) {
            currentMethod = n;
            testMethod = new TestMethod(currentMethod.getNameAsString());
            testMethod.setHasSmell(false); // default value is false
                                           // (i.e. no smell)
            super.visit(n, arg);

            /*
             * the method has a smell if there is more than threshold calls to
             * production methods (not considering the ones inside assertions!)
             */

            testMethod.setHasSmell(eagerCount > threshold);
            smellyElementList.add(testMethod);

            // reset values for next method
            currentMethod = null;
            eagerCount = 0;
            productionVariables = new ArrayList<>();
            calledMethods = new ArrayList<>();
        }
    } else { // collect a list of all public/protected members of the
             // production class
        for (Modifier modifier : n.getModifiers()) {
            if (modifier.name().toLowerCase().equals("public")
                    || modifier.name().toLowerCase().equals("protected")) {
                productionMethods.add(n);
            }
        }

    }
}