Last active
          January 19, 2018 06:51 
        
      - 
      
- 
        Save dileeph/e2b35a83ae9fe60c402acd8debc01d82 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | @Override | |
| public void visit(ClassOrInterfaceDeclaration n, Struts2InputOutput io) { | |
| // System.out.println("Name of class: " + n.getn.getName()); | |
| final StringBuilder fullClassName = new StringBuilder(); | |
| final List<ImportDeclaration> imports = new ArrayList<>(); | |
| n.getParentNode().ifPresent(parent -> { | |
| ((CompilationUnit) parent).getPackageDeclaration() | |
| .ifPresent(packageName -> fullClassName.append(packageName.getNameAsString())); | |
| imports.addAll(((CompilationUnit) parent).getImports()); | |
| }); | |
| fullClassName.append(".").append(n.getNameAsString()); | |
| //boolean isAction = false; | |
| n.getParentNode().ifPresent(parent -> { | |
| NodeList<ImportDeclaration> importNodes = ((CompilationUnit) parent).getImports(); | |
| if (importNodes.stream().anyMatch(id -> upgradeImports.contains(id.getNameAsString()))) { | |
| io.addClassesToUpgradableImports(parent); | |
| } | |
| if (importNodes.stream().anyMatch(id -> codeBehindImports.contains(id.getNameAsString()))) { | |
| io.addClassesToUpgradableImports(parent); | |
| } | |
| if (importNodes.stream().anyMatch(id -> annotatedActionImport.contains(id.getNameAsString()))) { | |
| io.addActionClassWithAnnotation(parent); | |
| io.addActionClass(parent); | |
| } | |
| if(io.getActionClassesFromStrutsConfig().contains(fullClassName.toString())){ | |
| io.addActionClass(parent); | |
| } | |
| }); | |
| /* | |
| * For Struts 1 only List<MethodDeclaration> executes = | |
| * n.getMethodsBySignature("execute", new | |
| * String[]{"ActionMapping","ActionForm","HttpServletRequest", | |
| * "HttpServletResponse"}); System.out.println("Class : "+ | |
| * fullClassName.toString() + " contains " + executes.size() + | |
| * " execute methods"); | |
| */ | |
| List<MethodDeclaration> executes = n.getMethodsBySignature("execute"); | |
| System.out | |
| .println("Class : " + fullClassName.toString() + " contains " + executes.size() + " execute methods"); | |
| List<MethodDeclaration> publicMethods = n.getMethods().stream().filter(decl -> decl.isPublic()) | |
| .collect(Collectors.toList()); | |
| n.getParentNode().ifPresent(parent -> { | |
| if (publicMethods.size() > 1 && executes.size() == 1) { | |
| io.addActionClassWithExecuteAndMoreMethods(parent); | |
| io.addActionClass(parent); | |
| } else if (io.getActionClasses().contains(fullClassName.toString()) | |
| && publicMethods.size() >= 1 && executes.size() == 0) { | |
| io.addActionClassWithNoExecuteAndMoreMethods(n.getParentNode().get()); | |
| } else if (publicMethods.size() == 1 && executes.size() == 1) { | |
| io.addActionClassWithOnlyExecute(n.getParentNode().get()); | |
| io.addActionClass(parent); | |
| } | |
| }); | |
| // TODO: test this | |
| if (io.getActionClasses().contains(fullClassName.toString()) && !io.getActionClassesFromStrutsConfig().contains(fullClassName.toString())) { | |
| io.addActionClassNotInStrutsConfig(n.getParentNode().get()); | |
| } | |
| n.getParentNode().ifPresent(parent -> { | |
| NodeList<ImportDeclaration> importNodes = ((CompilationUnit) parent).getImports(); | |
| if (io.getActionClasses().contains(fullClassName.toString()) | |
| && importNodes.stream().noneMatch(id -> struts2Imports.contains(id.getNameAsString()))) { | |
| io.addActionClassWithNonStandardParents(parent); | |
| } | |
| }); | |
| } | |
| ====================== | |
| private Set<Node> actionClasses = new HashSet<>(); | |
| public Set<Node> getActionClasses() { | |
| return actionClasses; | |
| } | |
| public void addActionClass(Node classNode) { | |
| actionClasses.add(classNode); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment