Skip to content

Commit df66a18

Browse files
committed
Implemented unresolved symbols as inspection
1 parent 457fb68 commit df66a18

7 files changed

Lines changed: 88 additions & 33 deletions

File tree

src/de/halirutan/mathematica/codeinsight/highlighting/MathematicaHighlightingAnnotator.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ class MathematicaHighlightingAnnotator : MathematicaVisitor(), Annotator {
7676
override fun visitSymbol(symbol: Symbol) {
7777
symbol.resolve()
7878
val scope = symbol.localizationConstruct
79+
if (scope == LocalizationConstruct.MScope.NULL) {
80+
return
81+
}
7982
when (scope) {
8083
LocalizationConstruct.MScope.FILE -> setHighlighting(symbol, myHolder!!, MathematicaSyntaxHighlighterColors.IDENTIFIER)
81-
LocalizationConstruct.MScope.NULL -> setHighlighting(symbol, myHolder!!, CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES)
84+
// LocalizationConstruct.MScope.NULL -> setHighlighting(symbol, myHolder!!, CodeInsightColors.WRONG_REFERENCES_ATTRIBUTES)
8285
LocalizationConstruct.MScope.BUILT_IN -> setHighlighting(symbol, myHolder!!, MathematicaSyntaxHighlighterColors.BUILTIN_FUNCTION)
8386
LocalizationConstruct.MScope.MODULE -> setHighlighting(symbol, myHolder!!, MathematicaSyntaxHighlighterColors.MODULE_LOCALIZED)
8487
LocalizationConstruct.MScope.BLOCK -> setHighlighting(symbol, myHolder!!, MathematicaSyntaxHighlighterColors.BLOCK_LOCALIZED)

src/de/halirutan/mathematica/codeinsight/inspections/MathematicaInspectionBundle.java renamed to src/de/halirutan/mathematica/codeinsight/inspections/InspectionBundle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
/**
3232
* @author patrick (7/8/14)
3333
*/
34-
public class MathematicaInspectionBundle {
34+
public class InspectionBundle {
3535
private static final String BUNDLE = "de.halirutan.mathematica.MathematicaInspectionBundle";
3636
private static Reference<ResourceBundle> ourBundle = null;
3737

38-
private MathematicaInspectionBundle() {
38+
private InspectionBundle() {
3939
}
4040

4141
public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {

src/de/halirutan/mathematica/codeinsight/inspections/MathematicaInspectionProvider.java renamed to src/de/halirutan/mathematica/codeinsight/inspections/MathematicaInspectionProvider.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@
1919
* THE SOFTWARE.
2020
*/
2121

22-
package de.halirutan.mathematica.codeinsight.inspections;
22+
package de.halirutan.mathematica.codeinsight.inspections
2323

24-
import com.intellij.codeInspection.InspectionToolProvider;
25-
import de.halirutan.mathematica.codeinsight.inspections.bugs.ImplicitTimesThroughLinebreak;
26-
import de.halirutan.mathematica.codeinsight.inspections.bugs.UnsupportedVersion;
27-
import de.halirutan.mathematica.codeinsight.inspections.codestyle.ConsistentCompoundExpressionInFile;
24+
import com.intellij.codeInspection.InspectionToolProvider
25+
import de.halirutan.mathematica.codeinsight.inspections.bugs.ImplicitTimesThroughLinebreak
26+
import de.halirutan.mathematica.codeinsight.inspections.bugs.UnsupportedVersion
27+
import de.halirutan.mathematica.codeinsight.inspections.codestyle.ConsistentCompoundExpressionInFile
28+
import de.halirutan.mathematica.codeinsight.inspections.symbol.UnresolvedSymbolInspection
2829

2930
/**
3031
* @author patrick (7/8/14)
3132
*/
32-
public class MathematicaInspectionProvider implements InspectionToolProvider {
33-
@Override
34-
public Class[] getInspectionClasses() {
35-
return new Class[]{
36-
ConsistentCompoundExpressionInFile.class,
37-
ImplicitTimesThroughLinebreak.class,
38-
UnsupportedVersion.class
39-
};
40-
41-
}
33+
class MathematicaInspectionProvider : InspectionToolProvider {
34+
override fun getInspectionClasses(): Array<Class<*>> {
35+
return arrayOf(
36+
UnresolvedSymbolInspection::class.java,
37+
ConsistentCompoundExpressionInFile::class.java,
38+
ImplicitTimesThroughLinebreak::class.java,
39+
UnsupportedVersion::class.java
40+
)
41+
}
4242
}

src/de/halirutan/mathematica/codeinsight/inspections/bugs/ImplicitTimesThroughLinebreak.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import com.intellij.psi.PsiErrorElement;
3030
import com.intellij.psi.impl.source.tree.LeafPsiElement;
3131
import de.halirutan.mathematica.codeinsight.inspections.AbstractInspection;
32-
import de.halirutan.mathematica.codeinsight.inspections.MathematicaInspectionBundle;
32+
import de.halirutan.mathematica.codeinsight.inspections.InspectionBundle;
3333
import de.halirutan.mathematica.file.MathematicaFileType;
3434
import de.halirutan.mathematica.lang.psi.MathematicaVisitor;
3535
import de.halirutan.mathematica.lang.psi.api.FunctionCall;
@@ -55,20 +55,20 @@ public class ImplicitTimesThroughLinebreak extends AbstractInspection {
5555
@NotNull
5656
@Override
5757
public String getDisplayName() {
58-
return MathematicaInspectionBundle.message("bugs.implicit.times.through.linebreak.name");
58+
return InspectionBundle.message("bugs.implicit.times.through.linebreak.name");
5959
}
6060

6161
@Nullable
6262
@Override
6363
public String getStaticDescription() {
64-
return MathematicaInspectionBundle.message("bugs.implicit.times.through.linebreak.description");
64+
return InspectionBundle.message("bugs.implicit.times.through.linebreak.description");
6565
}
6666

6767
@Nls
6868
@NotNull
6969
@Override
7070
public String getGroupDisplayName() {
71-
return MathematicaInspectionBundle.message("group.bugs");
71+
return InspectionBundle.message("group.bugs");
7272
}
7373

7474
@NotNull
@@ -86,15 +86,15 @@ private static class ImplicitTimesVisitor extends MathematicaVisitor {
8686

8787
private final ProblemsHolder myHolder;
8888

89-
public ImplicitTimesVisitor(final ProblemsHolder holder) {
89+
ImplicitTimesVisitor(final ProblemsHolder holder) {
9090
this.myHolder = holder;
9191
}
9292

9393
private void registerProblem(final PsiElement element) {
9494
myHolder.registerProblem(
9595
element,
9696
TextRange.from(element.getTextLength()-1,1),
97-
MathematicaInspectionBundle.message("bugs.implicit.times.through.linebreak.message"));
97+
InspectionBundle.message("bugs.implicit.times.through.linebreak.message"));
9898
}
9999

100100
@Override

src/de/halirutan/mathematica/codeinsight/inspections/bugs/UnsupportedVersion.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import com.intellij.psi.PsiElementVisitor;
3434
import de.halirutan.mathematica.codeinsight.completion.SymbolVersionProvider;
3535
import de.halirutan.mathematica.codeinsight.inspections.AbstractInspection;
36-
import de.halirutan.mathematica.codeinsight.inspections.MathematicaInspectionBundle;
36+
import de.halirutan.mathematica.codeinsight.inspections.InspectionBundle;
3737
import de.halirutan.mathematica.file.MathematicaFileType;
3838
import de.halirutan.mathematica.lang.psi.MathematicaVisitor;
3939
import de.halirutan.mathematica.lang.psi.api.FunctionCall;
@@ -122,20 +122,20 @@ public JComponent createOptionsPanel() {
122122
@NotNull
123123
@Override
124124
public String getDisplayName() {
125-
return MathematicaInspectionBundle.message("bugs.unsupported.version.name");
125+
return InspectionBundle.message("bugs.unsupported.version.name");
126126
}
127127

128128
@Nullable
129129
@Override
130130
public String getStaticDescription() {
131-
return MathematicaInspectionBundle.message("bugs.unsupported.version.description");
131+
return InspectionBundle.message("bugs.unsupported.version.description");
132132
}
133133

134134
@Nls
135135
@NotNull
136136
@Override
137137
public String getGroupDisplayName() {
138-
return MathematicaInspectionBundle.message("group.bugs");
138+
return InspectionBundle.message("group.bugs");
139139
}
140140

141141
@NotNull

src/de/halirutan/mathematica/codeinsight/inspections/codestyle/ConsistentCompoundExpressionInFile.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.intellij.openapi.util.TextRange;
2727
import com.intellij.psi.*;
2828
import de.halirutan.mathematica.codeinsight.inspections.AbstractInspection;
29-
import de.halirutan.mathematica.codeinsight.inspections.MathematicaInspectionBundle;
29+
import de.halirutan.mathematica.codeinsight.inspections.InspectionBundle;
3030
import de.halirutan.mathematica.file.MathematicaFileType;
3131
import de.halirutan.mathematica.lang.psi.MathematicaVisitor;
3232
import de.halirutan.mathematica.lang.psi.api.CompoundExpression;
@@ -53,20 +53,20 @@ public class ConsistentCompoundExpressionInFile extends AbstractInspection {
5353
@NotNull
5454
@Override
5555
public String getDisplayName() {
56-
return MathematicaInspectionBundle.message("consistent.compound.expression.in.file.name");
56+
return InspectionBundle.message("consistent.compound.expression.in.file.name");
5757
}
5858

5959
@NotNull
6060
@Override
6161
public String getStaticDescription() {
62-
return MathematicaInspectionBundle.message("consistent.compound.expression.in.file.description");
62+
return InspectionBundle.message("consistent.compound.expression.in.file.description");
6363
}
6464

6565
@Nls
6666
@NotNull
6767
@Override
6868
public String getGroupDisplayName() {
69-
return MathematicaInspectionBundle.message("group.codestyle");
69+
return InspectionBundle.message("group.codestyle");
7070
}
7171

7272
@SuppressWarnings("OverlyComplexAnonymousInnerClass")
@@ -89,7 +89,7 @@ child instanceof CompoundExpression && getNextSiblingSkippingWhitespace(child) =
8989
holder.registerProblem(
9090
file,
9191
TextRange.from(Math.max(child.getTextOffset() + child.getTextLength() - 1, 0), 1),
92-
MathematicaInspectionBundle.message("consistent.compound.expression.in.file.message"),
92+
InspectionBundle.message("consistent.compound.expression.in.file.message"),
9393
new ConsistentCompoundExpressionQuickFix());
9494
// }
9595
child = child.getNextSibling();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package de.halirutan.mathematica.codeinsight.inspections.symbol
2+
3+
import com.intellij.codeHighlighting.HighlightDisplayLevel
4+
import com.intellij.codeInspection.LocalInspectionToolSession
5+
import com.intellij.codeInspection.ProblemHighlightType
6+
import com.intellij.codeInspection.ProblemsHolder
7+
import com.intellij.openapi.util.TextRange
8+
import com.intellij.psi.PsiElementVisitor
9+
import de.halirutan.mathematica.codeinsight.inspections.AbstractInspection
10+
import de.halirutan.mathematica.codeinsight.inspections.InspectionBundle
11+
import de.halirutan.mathematica.lang.psi.MathematicaVisitor
12+
import de.halirutan.mathematica.lang.psi.api.Symbol
13+
import de.halirutan.mathematica.lang.psi.impl.LightUndefinedSymbol
14+
15+
/**
16+
*
17+
* @author patrick (13.09.17).
18+
*/
19+
class UnresolvedSymbolInspection : AbstractInspection() {
20+
21+
22+
override fun getDisplayName(): String {
23+
return InspectionBundle.message("symbol.unresolved.name")
24+
}
25+
26+
override fun getStaticDescription(): String? {
27+
return InspectionBundle.message("symbol.unresolved.description")
28+
}
29+
30+
override fun getGroupDisplayName(): String {
31+
return InspectionBundle.message("group.symbol")
32+
}
33+
34+
override fun getDefaultLevel(): HighlightDisplayLevel {
35+
return HighlightDisplayLevel.ERROR
36+
}
37+
38+
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
39+
return object: MathematicaVisitor(){
40+
override fun visitSymbol(symbol: Symbol?) {
41+
symbol?.let {
42+
val resolve = symbol.resolve()
43+
if (resolve is LightUndefinedSymbol) {
44+
holder.registerProblem(symbol, InspectionBundle.message("symbol.unresolved.message"), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, TextRange.create(0,symbol.textLength))
45+
}
46+
47+
}
48+
}
49+
}
50+
51+
}
52+
}

0 commit comments

Comments
 (0)