Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better resolve for variables (especially for case expression)

  • Loading branch information...
commit 36090e9b18f13992cb4328996b9804fa86e4cb2e 1 parent 7378a72
@ignatov authored
View
2  src/org/intellij/erlang/psi/impl/ErlangPsiImplUtil.java
@@ -709,7 +709,7 @@ public static ErlangModule getModule(PsiFile file) {
return null;
}
- static boolean isInModule(PsiElement psiElement) {
+ static boolean inModule(PsiElement psiElement) {
return PsiTreeUtil.getParentOfType(psiElement, ErlangModule.class) != null;
}
View
23 src/org/intellij/erlang/psi/impl/ErlangVarProcessor.java
@@ -47,15 +47,19 @@ public ErlangVarProcessor(String requestedName, PsiElement origin) {
public boolean execute(@NotNull PsiElement psiElement, ResolveState resolveState) {
if (psiElement instanceof ErlangFunction) return false;
if (psiElement instanceof ErlangSpecification) return false;
- ErlangFunctionClause clause = PsiTreeUtil.getTopmostParentOfType(myOrigin, ErlangFunctionClause.class);
+ ErlangFunctionClause functionClause = PsiTreeUtil.getTopmostParentOfType(myOrigin, ErlangFunctionClause.class);
ErlangSpecification spec = PsiTreeUtil.getTopmostParentOfType(myOrigin, ErlangSpecification.class);
if (!psiElement.equals(myOrigin) && psiElement instanceof ErlangQVar && psiElement.getText().equals(myRequestedName)) {
- if (
- (PsiTreeUtil.isAncestor(clause, psiElement, false) && (inDefinition(psiElement) || inAssignment(psiElement)))
- || isInModule(psiElement)
- || PsiTreeUtil.isAncestor(spec, psiElement, false)) {
+ boolean inFunctionClause = PsiTreeUtil.isAncestor(functionClause, psiElement, false);
+ boolean inSpecification = PsiTreeUtil.isAncestor(spec, psiElement, false);
+ boolean inDefinitionOrAssignment = inDefinition(psiElement) || inAssignment(psiElement);
+ if ((inFunctionClause && inDefinitionOrAssignment) || inModule(psiElement) || inSpecification) {
+ boolean inArgumentList = inArgumentList(psiElement);
//noinspection unchecked
- if (inArgumentList(psiElement) && PsiTreeUtil.getParentOfType(psiElement, ErlangArgumentList.class, ErlangAssignmentExpression.class) instanceof ErlangArgumentList) return true;
+ boolean inArgumentListBeforeAssignment =
+ PsiTreeUtil.getParentOfType(psiElement, ErlangArgumentList.class, ErlangAssignmentExpression.class) instanceof ErlangArgumentList;
+ if (inArgumentList && inArgumentListBeforeAssignment) return true;
+ if (inDifferentCrClauses(psiElement)) return true;
myVarList.add(0, (ErlangQVar) psiElement); // put all possible variables to list
return true;
@@ -64,6 +68,13 @@ public boolean execute(@NotNull PsiElement psiElement, ResolveState resolveState
return true;
}
+ private boolean inDifferentCrClauses(PsiElement psiElement) {
+ ErlangCrClause crClause = PsiTreeUtil.getParentOfType(psiElement, ErlangCrClause.class);
+ ErlangCrClause crClauseOrigin = PsiTreeUtil.getParentOfType(myOrigin, ErlangCrClause.class);
+ if (crClause != null && crClauseOrigin != null && crClause != crClauseOrigin) return true;
+ return false;
+ }
+
@Nullable
public ErlangQVar getResult() {
return ContainerUtil.getFirstItem(myVarList); // return the topmost one
View
2  testData/highlighting/Mp4Mux.erl
@@ -223,7 +223,7 @@ read_atom_header({Module, Device}, Pos) ->
case Module:pread(Device, Pos, 8) of
{ok, <<0:32, AtomName/binary>>} ->
{atom, binary_to_atom(AtomName, latin1), Pos + 8, all_file};
- {ok, <<1:32, AtomName/binary>>} ->
+ {ok, <<1:32, <warning>AtomName</warning>/binary>>} ->
case Module:pread(Device, Pos+4, 12) of
{ok, <<AtomName:4/binary, AtomLength:64>>} when AtomLength >= 12 ->
{atom, binary_to_atom(AtomName, latin1), Pos + 16, AtomLength - 16};
View
15 testData/highlighting/VariableResolve.erl
@@ -0,0 +1,15 @@
+-author("ignatov").
+
+%% API
+-export([name_to_pid/1]).
+
+name_to_pid(Name) ->
+ case Name of
+ undefined ->
+ case Name of
+ undefined ->
+ exit(could_not_find_registered_name);
+ <warning>Pid</warning> -> null
+ end;
+ <warning>Pid</warning> -> 1
+ end.
View
2  tests/org/intellij/erlang/highlighting/ErlangHighlightingTest.java
@@ -106,7 +106,7 @@ protected String getTestDataPath() {
public void test158() { doTest(); }
public void testIoFormat() { doTest(); }
public void testSuppression() { doTest(); }
-
+ public void testVariableResolve() { doTest(); }
public void testUnresolvedMacros() {
//noinspection unchecked
Please sign in to comment.
Something went wrong with that request. Please try again.