Skip to content

Commit add69be

Browse files
committed
Fixed LightElement and slowly turned on all extensions.
1 parent 9c41ed9 commit add69be

9 files changed

Lines changed: 306 additions & 221 deletions

File tree

.idea/codeStyleSettings.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/META-INF/plugin.xml

Lines changed: 61 additions & 94 deletions
Large diffs are not rendered by default.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2017 Patrick Scheibe
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*/
21+
22+
package de.halirutan.mathematica.find;
23+
24+
import com.intellij.find.findUsages.FindUsagesHandler;
25+
import com.intellij.lang.LighterAST;
26+
import com.intellij.lang.LighterASTNode;
27+
import com.intellij.openapi.util.text.StringUtil;
28+
import com.intellij.psi.PsiElement;
29+
import com.intellij.psi.PsiFile;
30+
import com.intellij.psi.PsiReference;
31+
import com.intellij.psi.impl.search.CachesBasedRefSearcher;
32+
import com.intellij.psi.search.GlobalSearchScope;
33+
import com.intellij.psi.search.SearchRequestCollector;
34+
import com.intellij.psi.search.SearchScope;
35+
import com.intellij.psi.search.searches.ReferencesSearch;
36+
import com.intellij.psi.util.PsiElementFilter;
37+
import com.intellij.psi.util.PsiTreeUtil;
38+
import com.intellij.util.Processor;
39+
import com.intellij.util.Query;
40+
import de.halirutan.mathematica.lang.psi.api.Symbol;
41+
import de.halirutan.mathematica.lang.psi.impl.LightBuiltInSymbol;
42+
import de.halirutan.mathematica.lang.psi.impl.LightSymbol;
43+
import org.jetbrains.annotations.NotNull;
44+
45+
import java.util.*;
46+
47+
/**
48+
* @author patrick (12.07.17).
49+
*/
50+
class LigthtSymbolFindUsageHandler extends FindUsagesHandler {
51+
private boolean myForHighlighting;
52+
53+
LigthtSymbolFindUsageHandler(@NotNull LightSymbol psiElement, boolean forHighlightUsages) {
54+
super(psiElement);
55+
myForHighlighting = forHighlightUsages;
56+
}
57+
58+
@Override
59+
@NotNull
60+
public Collection<PsiReference> findReferencesToHighlight(@NotNull PsiElement target, @NotNull SearchScope searchScope) {
61+
62+
if (target instanceof LightBuiltInSymbol) {
63+
ReferencesSearch.SearchParameters parameters = new ReferencesSearch.SearchParameters(
64+
target,
65+
GlobalSearchScope.fileScope(target.getContainingFile()),
66+
true,
67+
null);
68+
CachesBasedRefSearcher searcher = new CachesBasedRefSearcher();
69+
final CachesBasedRefSearcher searcher1 = searcher;
70+
searcher1.processQuery(parameters, new Processor<PsiReference>() {
71+
@Override
72+
public boolean process(PsiReference psiReference) {
73+
if (psiReference instanceof Symbol) {
74+
return true;
75+
}
76+
return false;
77+
}
78+
});
79+
final Query<PsiReference> all = ReferencesSearch.search(parameters);
80+
final Collection<PsiReference> all1 = all.findAll();
81+
return all1;
82+
83+
}
84+
// if (target instanceof LightBuiltInSymbol) {
85+
// final PsiFile containingFile = target.getContainingFile();
86+
// PsiElementFilter filter = element -> element instanceof Symbol;
87+
// final PsiElement[] psiElements = PsiTreeUtil.collectElements(containingFile, filter);
88+
// Set<PsiReference> result = new HashSet<>();
89+
// for (PsiElement element : psiElements) {
90+
// if (element instanceof Symbol && ((Symbol) element).resolve() == target) {
91+
// result.add(element.getReference());
92+
// }
93+
// }
94+
// return result;
95+
// }
96+
return Arrays.asList(PsiReference.EMPTY_ARRAY);
97+
}
98+
99+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2017 Patrick Scheibe
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*/
21+
22+
package de.halirutan.mathematica.find;
23+
24+
import com.intellij.find.findUsages.FindUsagesHandler;
25+
import com.intellij.find.findUsages.FindUsagesHandlerFactory;
26+
import com.intellij.psi.PsiElement;
27+
import de.halirutan.mathematica.lang.psi.impl.LightSymbol;
28+
import org.jetbrains.annotations.NotNull;
29+
import org.jetbrains.annotations.Nullable;
30+
31+
/**
32+
* @author patrick (12.07.17).
33+
*/
34+
public class MathematicaFindUsageHandlerFactory extends FindUsagesHandlerFactory {
35+
@Override
36+
public boolean canFindUsages(@NotNull PsiElement element) {
37+
return element instanceof LightSymbol;
38+
}
39+
40+
@Nullable
41+
@Override
42+
public FindUsagesHandler createFindUsagesHandler(@NotNull PsiElement element, boolean forHighlightUsages) {
43+
if (element instanceof LightSymbol) {
44+
return new LigthtSymbolFindUsageHandler((LightSymbol) element, forHighlightUsages);
45+
}
46+
return null;
47+
}
48+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2017 Patrick Scheibe
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy
4+
* of this software and associated documentation files (the "Software"), to deal
5+
* in the Software without restriction, including without limitation the rights
6+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
* copies of the Software, and to permit persons to whom the Software is
8+
* furnished to do so, subject to the following conditions:
9+
*
10+
* The above copyright notice and this permission notice shall be included in
11+
* all copies or substantial portions of the Software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
* THE SOFTWARE.
20+
*/
21+
22+
package de.halirutan.mathematica.lang.psi.impl;
23+
24+
import com.intellij.psi.SyntheticElement;
25+
import de.halirutan.mathematica.lang.psi.api.Symbol;
26+
import org.jetbrains.annotations.NotNull;
27+
28+
/**
29+
* @author patrick (12.07.17).
30+
*/
31+
public class LightBuiltInSymbol extends LightSymbol implements SyntheticElement{
32+
33+
public LightBuiltInSymbol(@NotNull Symbol symbol) {
34+
super(symbol);
35+
}
36+
37+
}

src/de/halirutan/mathematica/lang/psi/impl/LightSymbol.java

Lines changed: 14 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -21,106 +21,40 @@
2121

2222
package de.halirutan.mathematica.lang.psi.impl;
2323

24-
import com.intellij.openapi.util.TextRange;
25-
import com.intellij.psi.PsiElement;
26-
import com.intellij.psi.PsiElementVisitor;
27-
import com.intellij.psi.PsiFile;
28-
import com.intellij.psi.PsiReference;
24+
import com.intellij.psi.*;
2925
import com.intellij.psi.impl.light.LightElement;
26+
import com.intellij.psi.search.SearchScope;
3027
import com.intellij.util.IncorrectOperationException;
3128
import de.halirutan.mathematica.lang.MathematicaLanguage;
3229
import de.halirutan.mathematica.lang.psi.api.Symbol;
33-
import de.halirutan.mathematica.lang.psi.util.LocalizationConstruct;
34-
import de.halirutan.mathematica.lang.resolve.SymbolResolveResult;
3530
import org.jetbrains.annotations.NotNull;
36-
import org.jetbrains.annotations.Nullable;
3731

3832
/**
3933
* @author patrick (10.07.17).
4034
*/
41-
public class LightSymbol extends LightElement implements Symbol {
42-
private final PsiFile myFile;
35+
public class LightSymbol extends LightElement implements PsiNamedElement {
4336
private String myName;
37+
private PsiFile myFile;
4438

45-
46-
public LightSymbol(@NotNull final Symbol symbol) {
39+
LightSymbol(@NotNull Symbol symbol) {
4740
super(symbol.getManager(), MathematicaLanguage.INSTANCE);
4841
myName = symbol.getText();
4942
myFile = symbol.getContainingFile();
5043
}
5144

52-
@Override
53-
public void accept(@NotNull PsiElementVisitor visitor){
54-
visitor.visitElement(this);
55-
}
56-
5745
@Override
5846
public String toString() {
59-
return "LightSymbol[" + myName + "]";
60-
}
61-
62-
@Override
63-
public PsiFile getContainingFile() {
64-
return myFile;
65-
}
66-
67-
@Override
68-
public boolean equals(Object obj) {
69-
if (obj instanceof LightSymbol) {
70-
return ((LightSymbol) obj).getSymbolName().equals(myName);
71-
}
72-
return false;
73-
}
74-
75-
@Override
76-
public boolean isEquivalentTo(PsiElement another) {
77-
if (another instanceof PsiReference) {
78-
final PsiElement resolve = ((PsiReference) another).resolve();
79-
return resolve != null && resolve.equals(this);
80-
}
81-
return false;
82-
}
83-
84-
@Override
85-
public int hashCode() {
86-
int hash = 1;
87-
hash = hash * 31 + myName.hashCode();
88-
return hash;
89-
}
90-
91-
@Override
92-
public String getMathematicaContext() {
93-
return null;
94-
}
95-
96-
public String getSymbolName() {
9747
return myName;
9848
}
9949

10050
@Override
101-
public String getFullSymbolName() {
51+
public String getName() {
10252
return myName;
10353
}
10454

10555
@Override
106-
public LocalizationConstruct.MScope getLocalizationConstruct() {
107-
return null;
108-
}
109-
110-
@Override
111-
public PsiElement[] getElementsReferencingToMe() {
112-
return new PsiElement[0];
113-
}
114-
115-
@Override
116-
public SymbolResolveResult advancedResolve() {
117-
return null;
118-
}
119-
120-
@Nullable
121-
@Override
122-
public PsiElement getNameIdentifier() {
123-
return this;
56+
public PsiFile getContainingFile() {
57+
return myFile;
12458
}
12559

12660
@Override
@@ -129,62 +63,18 @@ public PsiElement setName(@NotNull String name) throws IncorrectOperationExcepti
12963
return this;
13064
}
13165

132-
@Override
133-
public PsiElement getElement() {
134-
return this;
135-
}
136-
137-
@Override
138-
public TextRange getRangeInElement() {
139-
return TextRange.create(0, getTextLength());
140-
}
141-
142-
@Nullable
143-
@Override
144-
public PsiElement resolve() {
145-
return this;
146-
}
147-
148-
@Override
149-
public String getText() {
150-
return myName;
151-
}
152-
15366
@NotNull
15467
@Override
155-
public String getCanonicalText() {
156-
return getText();
157-
}
158-
159-
@Override
160-
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
161-
return setName(newElementName);
68+
public SearchScope getUseScope() {
69+
return myFile.getUseScope();
16270
}
16371

16472
@Override
165-
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
166-
return null;
167-
}
168-
169-
@Override
170-
public boolean isReferenceTo(PsiElement element) {
171-
if (element == this) {
172-
return true;
173-
}
174-
if (element instanceof PsiReference) {
175-
return ((PsiReference) element).resolve() == this;
73+
public boolean isEquivalentTo(PsiElement another) {
74+
if (another instanceof Symbol || another instanceof LightSymbol) {
75+
final String name = ((PsiNamedElement) another).getName();
76+
return myName.equals(name);
17677
}
17778
return false;
17879
}
179-
180-
@NotNull
181-
@Override
182-
public Object[] getVariants() {
183-
return new Object[0];
184-
}
185-
186-
@Override
187-
public boolean isSoft() {
188-
return true;
189-
}
19080
}

0 commit comments

Comments
 (0)