Project

General

Profile

CheckAssignments.java

Ioana-Cristina Prioteasa, 02/17/2025 05:13 AM

Download (3.2 KB)

 
1
import java.util.*;
2

    
3
import spoon.Launcher;
4
import spoon.reflect.code.*;
5
import spoon.reflect.declaration.*;
6
import spoon.reflect.visitor.CtScanner;
7

    
8
public class CheckAssignments
9
{
10
   public static void main(String[] args) throws Exception
11
   {
12
      Launcher launcher = new Launcher();
13
      launcher.addInputResource("/home/icp/projects/branches/9060a/src/com/goldencode/p2j");
14
      launcher.getEnvironment().setNoClasspath(true);
15
      launcher.getEnvironment().setAutoImports(true);
16
      Collection<CtType<?>> allTypes = launcher.buildModel().getAllTypes();
17

    
18
      List<String> mathOps = new ArrayList<>();
19
      List<String> textOps = new ArrayList<>();
20
      List<String> dynamicOps = new ArrayList<>();
21
      List<String> compareOps= new ArrayList<>();
22
      List<String> environmentOps= new ArrayList<>();
23

    
24
      for (CtType<?> type : allTypes)
25
      {
26
         type.accept(new CtScanner()
27
         {
28
            @Override
29
            public void scan(CtElement element)
30
            {
31
               if (element instanceof CtAssignment<?, ?>)
32
               {
33
                  CtAssignment<?, ?> assignment = (CtAssignment<?, ?>) element;
34

    
35
                  if (assignment.getAssignment() instanceof CtInvocation<?>)
36
                  {
37
                     CtInvocation<?> invocation = (CtInvocation<?>) assignment.getAssignment();
38
                     String position = assignment.getPosition().toString();
39

    
40
                     if (invocation.getTarget() != null)
41
                     {
42
                        String target = invocation.getTarget().toString();
43
                        if (target.equals("MathOps"))
44
                        {
45
                           mathOps.add(position);
46
                        }
47
                        else if (target.equals("TextOps"))
48
                        {
49
                           textOps.add(position);
50
                        }
51
                        else if (target.equals("DynamicOps"))
52
                        {
53
                           dynamicOps.add(position);
54
                        }
55
                        else if (target.equals("CompareOps"))
56
                        {
57
                           compareOps.add(position);
58
                        }
59
                        else if (target.equals("EnvironmentOps"))
60
                        {
61
                           environmentOps.add(position);
62
                        }
63
                     }
64
                  }
65
               }
66
               super.scan(element);
67
            }
68
         });
69
      }
70

    
71
      System.out.println("\n==== MathOps ====");
72
      for (String location : mathOps)
73
      {
74
         System.out.println(location);
75
      }
76

    
77
      System.out.println("\n==== TextOps ====");
78
      for (String location : textOps)
79
      {
80
         System.out.println(location);
81
      }
82

    
83
      System.out.println("\n==== DynamicOps ====");
84
      for (String location : dynamicOps)
85
      {
86
         System.out.println(location);
87
      }
88
      System.out.println("\n==== CompareOps ====");
89
      for (String location : compareOps)
90
      {
91
         System.out.println(location);
92
      }
93
      System.out.println("\n==== EnvironmentOps ====");
94
      for (String location : environmentOps)
95
      {
96
         System.out.println(location);
97
      }
98
   }
99
}