Skip to content

Commit 756a8c3

Browse files
committed
LightElement
1 parent 3f6f576 commit 756a8c3

File tree

1 file changed

+210
-0
lines changed

1 file changed

+210
-0
lines changed
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
/*
2+
* Copyright 2000-2014 JetBrains s.r.o.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.intellij.psi.impl.light;
18+
19+
import com.intellij.lang.ASTNode;
20+
import com.intellij.lang.Language;
21+
import com.intellij.openapi.util.TextRange;
22+
import com.intellij.psi.PsiElement;
23+
import com.intellij.psi.PsiElementVisitor;
24+
import com.intellij.psi.PsiFile;
25+
import com.intellij.psi.PsiManager;
26+
import com.intellij.psi.impl.PsiElementBase;
27+
import com.intellij.util.IncorrectOperationException;
28+
import org.jetbrains.annotations.NotNull;
29+
30+
public abstract class LightElement extends PsiElementBase {
31+
protected final PsiManager myManager;
32+
private final Language myLanguage;
33+
private volatile PsiElement myNavigationElement = this;
34+
35+
protected LightElement(@NotNull PsiManager manager, @NotNull Language language) {
36+
myManager = manager;
37+
myLanguage = language;
38+
}
39+
40+
@Override
41+
@NotNull
42+
public Language getLanguage() {
43+
return myLanguage;
44+
}
45+
46+
@Override
47+
public PsiManager getManager() {
48+
return myManager;
49+
}
50+
51+
@Override
52+
public PsiElement getParent() {
53+
return null;
54+
}
55+
56+
@Override
57+
@NotNull
58+
public PsiElement[] getChildren() {
59+
return PsiElement.EMPTY_ARRAY;
60+
}
61+
62+
@Override
63+
public PsiFile getContainingFile() {
64+
return null;
65+
}
66+
67+
@Override
68+
public TextRange getTextRange() {
69+
return null;
70+
}
71+
72+
@Override
73+
public int getStartOffsetInParent() {
74+
return -1;
75+
}
76+
77+
@Override
78+
public final int getTextLength() {
79+
String text = getText();
80+
return text != null ? text.length() : 0;
81+
}
82+
83+
@Override
84+
@NotNull
85+
public char[] textToCharArray() {
86+
return getText().toCharArray();
87+
}
88+
89+
@Override
90+
public boolean textMatches(@NotNull CharSequence text) {
91+
return getText().equals(text.toString());
92+
}
93+
94+
@Override
95+
public boolean textMatches(@NotNull PsiElement element) {
96+
return getText().equals(element.getText());
97+
}
98+
99+
@Override
100+
public PsiElement findElementAt(int offset) {
101+
return null;
102+
}
103+
104+
@Override
105+
public int getTextOffset() {
106+
return -1;
107+
}
108+
109+
@Override
110+
public boolean isValid() {
111+
final PsiElement navElement = getNavigationElement();
112+
if (navElement != this) {
113+
return navElement.isValid();
114+
}
115+
116+
return true;
117+
}
118+
119+
@Override
120+
public boolean isWritable() {
121+
return false;
122+
}
123+
124+
@Override
125+
public boolean isPhysical() {
126+
return false;
127+
}
128+
129+
@Override
130+
public abstract String toString();
131+
132+
@Override
133+
public void checkAdd(@NotNull PsiElement element) throws IncorrectOperationException {
134+
throw new IncorrectOperationException(getClass().getName());
135+
}
136+
137+
@Override
138+
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
139+
throw new IncorrectOperationException(getClass().getName());
140+
}
141+
142+
@Override
143+
public PsiElement addBefore(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
144+
throw new IncorrectOperationException(getClass().getName());
145+
}
146+
147+
@Override
148+
public PsiElement addAfter(@NotNull PsiElement element, PsiElement anchor) throws IncorrectOperationException {
149+
throw new IncorrectOperationException(getClass().getName());
150+
}
151+
152+
@Override
153+
public void delete() throws IncorrectOperationException {
154+
throw new IncorrectOperationException(getClass().getName());
155+
}
156+
157+
@Override
158+
public void checkDelete() throws IncorrectOperationException {
159+
throw new IncorrectOperationException(getClass().getName());
160+
}
161+
162+
@Override
163+
public PsiElement replace(@NotNull PsiElement newElement) throws IncorrectOperationException {
164+
throw new IncorrectOperationException(getClass().getName());
165+
}
166+
167+
@Override
168+
public ASTNode getNode() {
169+
return null;
170+
}
171+
172+
@Override
173+
public String getText() {
174+
return null;
175+
}
176+
177+
@Override
178+
public void accept(@NotNull PsiElementVisitor visitor) {
179+
}
180+
181+
@Override
182+
public PsiElement copy() {
183+
return null;
184+
}
185+
186+
@NotNull
187+
@Override
188+
public PsiElement getNavigationElement() {
189+
return myNavigationElement;
190+
}
191+
192+
public void setNavigationElement(@NotNull PsiElement navigationElement) {
193+
PsiElement nnElement = navigationElement.getNavigationElement();
194+
if (nnElement != navigationElement && nnElement != null) {
195+
navigationElement = nnElement;
196+
}
197+
myNavigationElement = navigationElement;
198+
}
199+
200+
@Override
201+
public PsiElement getPrevSibling() {
202+
return null;
203+
}
204+
205+
@Override
206+
public PsiElement getNextSibling() {
207+
return null;
208+
}
209+
210+
}

0 commit comments

Comments
 (0)