Skip to content

Commit 58a2f5e

Browse files
committed
Further reworking of local variable resolution: compileLikeVariables
1 parent 3cce1b2 commit 58a2f5e

5 files changed

Lines changed: 65 additions & 27 deletions

File tree

.idea/runConfigurations/Mathematica_Plugin.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/de/halirutan/mathematica/codeinsight/formatter/MathematicaSpacingBuilderProvider.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ class MathematicaSpacingBuilderProvider {
107107

108108
}
109109

110-
public static SpacingBuilder getSpacingBuilder(CommonCodeStyleSettings settings, MathematicaCodeStyleSettings mathematicaSettings) {
110+
static SpacingBuilder getSpacingBuilder(CommonCodeStyleSettings settings, MathematicaCodeStyleSettings mathematicaSettings) {
111111
return new SpacingBuilder(settings.getRootSettings(), MathematicaLanguage.INSTANCE)
112-
.around(ourAssignments).spaceIf(MathematicaCodeStyleSettings.SPACE_AROUND_ASSIGNMENT_OPERATIONS)
113-
.around(ourArithmeticOperations).spaceIf(MathematicaCodeStyleSettings.SPACE_AROUND_ARITHMETIC_OPERATIONS)
114-
.aroundInside(MINUS, MINUS_EXPRESSION).spaceIf(MathematicaCodeStyleSettings.SPACE_AROUND_ARITHMETIC_OPERATIONS)
115-
.around(ourRelationalOperations).spaceIf(MathematicaCodeStyleSettings.SPACE_AROUND_RELATION_OPERATIONS)
116-
.around(ourRuleOperations).spaceIf(MathematicaCodeStyleSettings.SPACE_AROUND_RULE_OPERATIONS)
117-
.around(ourFunctionalOperations).spaceIf(MathematicaCodeStyleSettings.SPACE_AROUND_FUNCTIONAL_OPERATIONS)
118-
.around(ourOtherOperations).spaceIf(MathematicaCodeStyleSettings.SPACE_AROUND_OTHER_OPERATIONS)
112+
.around(ourAssignments).spaceIf(mathematicaSettings.SPACE_AROUND_ASSIGNMENT_OPERATIONS)
113+
.around(ourArithmeticOperations).spaceIf(mathematicaSettings.SPACE_AROUND_ARITHMETIC_OPERATIONS)
114+
.aroundInside(MINUS, MINUS_EXPRESSION).spaceIf(mathematicaSettings.SPACE_AROUND_ARITHMETIC_OPERATIONS)
115+
.around(ourRelationalOperations).spaceIf(mathematicaSettings.SPACE_AROUND_RELATION_OPERATIONS)
116+
.around(ourRuleOperations).spaceIf(mathematicaSettings.SPACE_AROUND_RULE_OPERATIONS)
117+
.around(ourFunctionalOperations).spaceIf(mathematicaSettings.SPACE_AROUND_FUNCTIONAL_OPERATIONS)
118+
.around(ourOtherOperations).spaceIf(mathematicaSettings.SPACE_AROUND_OTHER_OPERATIONS)
119119
.after(COMMA).spaceIf(settings.SPACE_AFTER_COMMA)
120120
.before(LEFT_BRACKET).none()
121121
.after(RIGHT_BRACKET).none();

src/de/halirutan/mathematica/codeinsight/formatter/settings/MathematicaCodeStyleSettings.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
/**
2828
* @author patrick (11/2/13)
2929
*/
30-
@SuppressWarnings({"StaticVariableNamingConvention", "NonConstantFieldWithUpperCaseName"})
30+
@SuppressWarnings({"InstanceVariableNamingConvention", "NonConstantFieldWithUpperCaseName"})
3131
public class MathematicaCodeStyleSettings extends CustomCodeStyleSettings {
3232

33-
public static final boolean SPACE_AROUND_ARITHMETIC_OPERATIONS = true;
34-
public static final boolean SPACE_AROUND_ASSIGNMENT_OPERATIONS = true;
35-
public static final boolean SPACE_AROUND_RULE_OPERATIONS = true;
36-
public static final boolean SPACE_AROUND_FUNCTIONAL_OPERATIONS = true;
37-
public static final boolean SPACE_AROUND_OTHER_OPERATIONS = true;
38-
public static final boolean SPACE_AROUND_RELATION_OPERATIONS = true;
33+
public boolean SPACE_AROUND_ARITHMETIC_OPERATIONS = true;
34+
public boolean SPACE_AROUND_ASSIGNMENT_OPERATIONS = true;
35+
public boolean SPACE_AROUND_RULE_OPERATIONS = true;
36+
public boolean SPACE_AROUND_FUNCTIONAL_OPERATIONS = true;
37+
public boolean SPACE_AROUND_OTHER_OPERATIONS = true;
38+
public boolean SPACE_AROUND_RELATION_OPERATIONS = true;
3939

4040
public MathematicaCodeStyleSettings(CodeStyleSettings container) {
4141
super("MathematicaCodeStyleSettings", container);

src/de/halirutan/mathematica/lang/psi/util/MathematicaPsiUtilities.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static boolean isBuiltInSymbol(PsiElement element) {
7171
* @return List of symbols which are assigned.
7272
*/
7373
@Nullable
74-
public static List<Symbol> getAssignmentSymbols(PsiElement element) {
74+
static List<Symbol> getAssignmentSymbols(PsiElement element) {
7575
PsiElement firstChild = element.getFirstChild();
7676
final List<Symbol> assignees = Lists.newArrayList();
7777

@@ -525,6 +525,48 @@ public static List<Symbol> getLocalCompileLikeVariables(FunctionCall element) {
525525
return localVariables;
526526
}
527527

528+
529+
@Nullable
530+
public static SymbolResolveResult resolveLocalCompileLikeVariables(Symbol myStartElement, FunctionCall functionCall, ResolveState state) {
531+
532+
final PsiElement lastParent = state.get(SymbolResolveHint.LAST_PARENT);
533+
final List<PsiElement> arguments = getArguments(functionCall);
534+
if (arguments.size() < 1) {
535+
return null;
536+
}
537+
538+
final PsiElement firstArgument = arguments.get(0);
539+
boolean inDef = firstArgument.equals(lastParent);
540+
541+
542+
final MScope scopingConstruct = functionCall.getScopingConstruct();
543+
if (firstArgument instanceof Symbol) {
544+
if (((Symbol) firstArgument).getFullSymbolName().equals(myStartElement.getFullSymbolName())) {
545+
return new SymbolResolveResult(firstArgument, scopingConstruct, true);
546+
}
547+
} else if (firstArgument instanceof de.halirutan.mathematica.lang.psi.api.lists.List) {
548+
final PsiElement[] children = firstArgument.getChildren();
549+
for (PsiElement child : children) {
550+
if (child instanceof de.halirutan.mathematica.lang.psi.api.lists.List) {
551+
child = child.getFirstChild();
552+
}
553+
if (child instanceof Symbol) {
554+
if (inDef) {
555+
if (child.equals(myStartElement)) {
556+
return new SymbolResolveResult(child, scopingConstruct, true);
557+
}
558+
} else {
559+
if (((Symbol) child).getFullSymbolName().equals(myStartElement.getFullSymbolName())) {
560+
return new SymbolResolveResult(child, scopingConstruct, true);
561+
}
562+
}
563+
}
564+
}
565+
}
566+
return null;
567+
}
568+
569+
528570
/**
529571
* This extracts the local defined argument for a <code>Limit[Sin[x]/x, x-> 0]</code> call. Note that the returned
530572
* list has always only one element since <code>Limit</code> always uses only one variable.
@@ -578,7 +620,7 @@ public static PsiElement getFirstListElement(@Nullable PsiElement list) {
578620
* @return List of arguments
579621
*/
580622
@NotNull
581-
public static List<PsiElement> getArguments(@Nullable PsiElement func) {
623+
static List<PsiElement> getArguments(@Nullable PsiElement func) {
582624
List<PsiElement> allArguments = Lists.newLinkedList();
583625
if (!(func instanceof FunctionCall)) {
584626
return allArguments;
@@ -636,7 +678,7 @@ public static String getBeginContext(@NotNull PsiElement element) {
636678
* @return context string or null if it could not be extracted
637679
*/
638680
@Nullable
639-
public static String getContext(@NotNull PsiElement element, final boolean beginPackageOnly) {
681+
private static String getContext(@NotNull PsiElement element, final boolean beginPackageOnly) {
640682
if (element instanceof FunctionCall) {
641683
final FunctionCall functionCall = (FunctionCall) element;
642684
if (functionCall.matchesHead("BeginPackage") || (!beginPackageOnly && functionCall.matchesHead("Begin"))) {

src/de/halirutan/mathematica/lang/resolve/processors/LocalDefinitionResolveProcessor2.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,12 @@ public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state)
122122
myResolveResult = MathematicaPsiUtilities.resolveLocalModuleLikeVariables(myStartElement, functionCall, state);
123123
} else if (LocalizationConstruct.isTableLike(scopingConstruct)) {
124124
myResolveResult = MathematicaPsiUtilities.resolveLocalTableLikeVariables(myStartElement, functionCall, state);
125+
} else if (LocalizationConstruct.isManipulateLike(scopingConstruct)) {
126+
myResolveResult = MathematicaPsiUtilities.resolveLocalTableLikeVariables(myStartElement, functionCall, state);
127+
} else if (LocalizationConstruct.isCompileLike(scopingConstruct)) {
128+
myResolveResult = MathematicaPsiUtilities.resolveLocalCompileLikeVariables(myStartElement, functionCall, state);
125129
}
126130
//
127-
// if (LocalizationConstruct.isManipulateLike(scopingConstruct)) {
128-
// vars = MathematicaPsiUtilities.getLocalManipulateLikeVariables(functionCall);
129-
// }
130-
//
131-
// if (LocalizationConstruct.isCompileLike(scopingConstruct)) {
132-
// vars = MathematicaPsiUtilities.getLocalCompileLikeVariables(functionCall);
133-
// }
134-
//
135131
// if (LocalizationConstruct.isLimitLike(scopingConstruct)) {
136132
// vars = MathematicaPsiUtilities.getLocalLimitVariables(functionCall);
137133
// }

0 commit comments

Comments
 (0)