41 import java.util.ArrayList; |
41 import java.util.ArrayList; |
42 import java.util.Collections; |
42 import java.util.Collections; |
43 import java.util.HashMap; |
43 import java.util.HashMap; |
44 import java.util.HashSet; |
44 import java.util.HashSet; |
45 import java.util.List; |
45 import java.util.List; |
|
46 import java.util.Locale; |
46 import java.util.Map; |
47 import java.util.Map; |
47 |
48 |
48 import javax.annotation.processing.AbstractProcessor; |
49 import javax.annotation.processing.AbstractProcessor; |
49 import javax.annotation.processing.RoundEnvironment; |
50 import javax.annotation.processing.RoundEnvironment; |
50 import javax.annotation.processing.SupportedAnnotationTypes; |
51 import javax.annotation.processing.SupportedAnnotationTypes; |
83 DiagnosticProcessor[] diagProcessors; |
84 DiagnosticProcessor[] diagProcessors; |
84 Map<ElementKey, Candidate> candidatesMap = new HashMap<ElementKey, Candidate>(); |
85 Map<ElementKey, Candidate> candidatesMap = new HashMap<ElementKey, Candidate>(); |
85 Set<String> declaredKeys = new HashSet<>(); |
86 Set<String> declaredKeys = new HashSet<>(); |
86 List<Diagnostic<? extends JavaFileObject>> diags = new ArrayList<>(); |
87 List<Diagnostic<? extends JavaFileObject>> diags = new ArrayList<>(); |
87 List<ElementKey> seenCandidates = new ArrayList<>(); |
88 List<ElementKey> seenCandidates = new ArrayList<>(); |
|
89 Map<String, String> predefTranslationMap = new HashMap<>(); |
88 |
90 |
89 protected ResolveHarness(JavaFileObject jfo) { |
91 protected ResolveHarness(JavaFileObject jfo) { |
90 this.jfo = jfo; |
92 this.jfo = jfo; |
91 this.diagProcessors = new DiagnosticProcessor[] { |
93 this.diagProcessors = new DiagnosticProcessor[] { |
92 new VerboseResolutionNoteProcessor(), |
94 new VerboseResolutionNoteProcessor(), |
93 new VerboseDeferredInferenceNoteProcessor(), |
95 new VerboseDeferredInferenceNoteProcessor(), |
94 new ErrorProcessor() |
96 new ErrorProcessor() |
95 }; |
97 }; |
|
98 predefTranslationMap.put("+", "_plus"); |
|
99 predefTranslationMap.put("-", "_minus"); |
|
100 predefTranslationMap.put("~", "_not"); |
|
101 predefTranslationMap.put("++", "_plusplus"); |
|
102 predefTranslationMap.put("--", "_minusminus"); |
|
103 predefTranslationMap.put("!", "_bang"); |
|
104 predefTranslationMap.put("*", "_mul"); |
|
105 predefTranslationMap.put("/", "_div"); |
|
106 predefTranslationMap.put("%", "_mod"); |
|
107 predefTranslationMap.put("&", "_and"); |
|
108 predefTranslationMap.put("|", "_or"); |
|
109 predefTranslationMap.put("^", "_xor"); |
|
110 predefTranslationMap.put("<<", "_lshift"); |
|
111 predefTranslationMap.put(">>", "_rshift"); |
|
112 predefTranslationMap.put("<<<", "_lshiftshift"); |
|
113 predefTranslationMap.put(">>>", "_rshiftshift"); |
|
114 predefTranslationMap.put("<", "_lt"); |
|
115 predefTranslationMap.put(">", "_gt"); |
|
116 predefTranslationMap.put("<=", "_lteq"); |
|
117 predefTranslationMap.put(">=", "_gteq"); |
|
118 predefTranslationMap.put("==", "_eq"); |
|
119 predefTranslationMap.put("!=", "_neq"); |
|
120 predefTranslationMap.put("&&", "_andand"); |
|
121 predefTranslationMap.put("||", "_oror"); |
96 } |
122 } |
97 |
123 |
98 protected void check() throws Exception { |
124 protected void check() throws Exception { |
99 String[] options = { |
125 String[] options = { |
100 "-XDshouldStopPolicy=ATTR", |
126 "-XDshouldStopPolicy=ATTR", |
101 "-XDverboseResolution=success,failure,applicable,inapplicable,deferred-inference" |
127 "-XDverboseResolution=success,failure,applicable,inapplicable,deferred-inference,predef" |
102 }; |
128 }; |
103 |
129 |
104 AbstractProcessor[] processors = { new ResolveCandidateFinder(), null }; |
130 AbstractProcessor[] processors = { new ResolveCandidateFinder(), null }; |
105 |
131 |
106 @SuppressWarnings("unchecked") |
132 @SuppressWarnings("unchecked") |
442 return key.hashCode(); |
469 return key.hashCode(); |
443 } |
470 } |
444 |
471 |
445 String computeKey(Element e) { |
472 String computeKey(Element e) { |
446 StringBuilder buf = new StringBuilder(); |
473 StringBuilder buf = new StringBuilder(); |
447 while (e != null) { |
474 if (predefTranslationMap.containsKey(e.getSimpleName().toString())) { |
|
475 //predef element |
|
476 buf.append("<predef>."); |
|
477 String replacedName = predefTranslationMap.get(e.getSimpleName().toString()); |
|
478 buf.append(e.toString().replace(e.getSimpleName().toString(), replacedName)); |
|
479 } else if (e.getSimpleName().toString().startsWith("_")) { |
|
480 buf.append("<predef>."); |
448 buf.append(e.toString()); |
481 buf.append(e.toString()); |
449 e = e.getEnclosingElement(); |
482 } else { |
450 } |
483 while (e != null) { |
451 buf.append(jfo.getName()); |
484 buf.append(e.toString()); |
|
485 e = e.getEnclosingElement(); |
|
486 } |
|
487 buf.append(jfo.getName()); |
|
488 } |
452 return buf.toString(); |
489 return buf.toString(); |
453 } |
490 } |
454 |
491 |
455 @Override |
492 @Override |
456 public String toString() { |
493 public String toString() { |