IntelliJ IDEA 引用搜索原理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

private void reparse(@NotNull String str, @NotNull PsiElement element, final boolean isStaticImport, JavaClassReferenceSet context) {
myElement = element;
myContext = context;
List<JavaClassReference> referencesList = new ArrayList<>();
int currentDot = -1;
int referenceIndex = 0;
boolean allowDollarInNames = isAllowDollarInNames();
boolean allowSpaces = isAllowSpaces();
boolean allowGenerics = false;
boolean allowWildCards = JavaClassReferenceProvider.ALLOW_WILDCARDS.getBooleanValue(getOptions());
boolean allowGenericsCalculated = false;
boolean parsingClassNames = true;

while (parsingClassNames) {
int nextDotOrDollar = -1;
for (int curIndex = currentDot + 1; curIndex < str.length(); ++curIndex) {
char ch = str.charAt(curIndex);

if (ch == DOT || ch == DOLLAR && allowDollarInNames) {
nextDotOrDollar = curIndex;
break;
}

if (ch == LT || ch == COMMA) {
if (!allowGenericsCalculated) {
allowGenerics = !isStaticImport && PsiUtil.isLanguageLevel5OrHigher(element);
allowGenericsCalculated = true;
}

if (allowGenerics) {
nextDotOrDollar = curIndex;
break;
}
}
}

if (nextDotOrDollar == -1) {
nextDotOrDollar = currentDot + 1;
for (int i = nextDotOrDollar; i < str.length() && Character.isJavaIdentifierPart(str.charAt(i)); ++i) nextDotOrDollar++;
parsingClassNames = false;
int j = skipSpaces(nextDotOrDollar, str.length(), str, allowSpaces);

if (j < str.length()) {
char ch = str.charAt(j);
boolean recognized = false;

if (ch == '[') {
j = skipSpaces(j + 1, str.length(), str, allowSpaces);
if (j < str.length() && str.charAt(j) == ']') {
j = skipSpaces(j + 1, str.length(), str, allowSpaces);
recognized = j == str.length();
}
}

Boolean aBoolean = JavaClassReferenceProvider.JVM_FORMAT.getValue(getOptions());
if (!recognized && (aBoolean == null || !aBoolean.booleanValue())) {
nextDotOrDollar = -1;
}
}
}

if (nextDotOrDollar != -1 && nextDotOrDollar < str.length()) {
char c = str.charAt(nextDotOrDollar);
if (c == LT) {
boolean recognized = false;
int start = skipSpaces(nextDotOrDollar + 1, str.length(), str, allowSpaces);
int j = str.lastIndexOf(GT);
int end = skipSpacesBackward(j, 0, str, allowSpaces);
if (end != -1 && end > start) {
if (myNestedGenericParameterReferences == null) myNestedGenericParameterReferences = new ArrayList<>(1);
myNestedGenericParameterReferences.add(new JavaClassReferenceSet(
str.substring(start, end), myElement, myStartInElement + start, isStaticImport, myProvider, this));
parsingClassNames = false;
j = skipSpaces(j + 1, str.length(), str, allowSpaces);
recognized = j == str.length();
}
if (!recognized) {
nextDotOrDollar = -1;
}
}
else if (c == COMMA && myContext != null) {
if (myContext.myNestedGenericParameterReferences == null) myContext.myNestedGenericParameterReferences = new ArrayList<>(1);
int start = skipSpaces(nextDotOrDollar + 1, str.length(), str, allowSpaces);
myContext.myNestedGenericParameterReferences.add(new JavaClassReferenceSet(
str.substring(start), myElement, myStartInElement + start, isStaticImport, myProvider, this));
parsingClassNames = false;
}
}

int maxIndex = nextDotOrDollar > 0 ? nextDotOrDollar : str.length();
int beginIndex = skipSpaces(currentDot + 1, maxIndex, str, allowSpaces);
int endIndex = skipSpacesBackward(maxIndex, beginIndex, str, allowSpaces);
boolean skipReference = false;
if (allowWildCards && str.charAt(beginIndex) == QUESTION) {
int next = skipSpaces(beginIndex + 1, endIndex, str, allowSpaces);
if (next != beginIndex + 1) {
String keyword = str.startsWith(EXTENDS, next) ? EXTENDS : str.startsWith(SUPER, next) ? SUPER : null;
if (keyword != null) {
next = skipSpaces(next + keyword.length(), endIndex, str, allowSpaces);
beginIndex = next;
}
}
else if (endIndex == beginIndex + 1) {
skipReference = true;
}
}
if (!skipReference) {
TextRange textRange = TextRange.create(myStartInElement + beginIndex, myStartInElement + endIndex);
JavaClassReference currentContextRef = createReference(
referenceIndex, str.substring(beginIndex, endIndex), textRange, isStaticImport);
referenceIndex++;
referencesList.add(currentContextRef);
}
if ((currentDot = nextDotOrDollar) < 0) {
break;
}
}

myReferences = referencesList.toArray(new JavaClassReference[0]);
}

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.125.1. UTC+08:00, 2024-05-17 15:01
浙ICP备14020137号-1 $访客地图$