Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handler #275

Merged
merged 3 commits into from
Mar 25, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Log errors with attachments for problematic areas
Log using LogMessageEx so that the entire file contents can attached,
which is important for these transient bugs that occur during typing as
by the time you see the error happened, the text may be different.
  • Loading branch information
KronicDeth committed Mar 24, 2016
commit 9feaff3dc6a4eb93f078b2931a3f95204411ed19
200 changes: 64 additions & 136 deletions src/org/elixir_lang/annonator/ModuleAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiRecursiveElementVisitor;
import com.intellij.psi.tree.TokenSet;
import org.apache.commons.lang.NotImplementedException;
import org.elixir_lang.ElixirSyntaxHighlighter;
import org.elixir_lang.errorreport.Logger;
import org.elixir_lang.psi.*;
import org.elixir_lang.psi.call.Call;
import org.elixir_lang.psi.impl.ElixirPsiImplUtil;
Expand Down Expand Up @@ -111,6 +111,14 @@ public void visitUsage(@NotNull final AtNonNumericOperation atNonNumericOperatio
* Private Instance Methods
*/

private void cannotHighlightTypes(PsiElement element) {
error("Cannot highlight types", element);
}

private void error(@NotNull String userMessage, PsiElement element) {
Logger.error(this.getClass(), userMessage, element);
}

/**
* Highlights `textRange` with the given `textAttributesKey`.
*
Expand Down Expand Up @@ -296,20 +304,10 @@ private void highlightType(@NotNull final AtUnqualifiedNoParenthesesCall atUnqua
);
}
} else {
throw new NotImplementedException(
"Highlighting types for " + call.getClass().getCanonicalName() + " PsiElements is " +
"not implemented yet. Please open an issue " +
"(https://github.com/KronicDeth/intellij-elixir/issues/new) with the class " +
"name of the sample text:\n" + ((PsiElement) call).getText()
);
cannotHighlightTypes(call);
}
} else {
throw new NotImplementedException(
"Highlighting types for " + leftOperand.getClass().getCanonicalName() + " PsiElements is " +
"not implemented yet. Please open an issue " +
"(https://github.com/KronicDeth/intellij-elixir/issues/new) with the class name of " +
"the sample text:\n" + leftOperand.getText()
);
cannotHighlightTypes(leftOperand);
}

PsiElement rightOperand = infix.rightOperand();
Expand Down Expand Up @@ -338,21 +336,10 @@ private void highlightType(@NotNull final AtUnqualifiedNoParenthesesCall atUnqua
);
}
} else {
throw new NotImplementedException(
"Highlighting types for " +
matchedUnqualifiedParenthesesCall.getClass().getCanonicalName() + " PsiElements " +
"is not implemented yet. Please open an issue " +
"(https://github.com/KronicDeth/intellij-elixir/issues/new) with the class name " +
"of the sample text:\n" + grandChild.getText()
);
cannotHighlightTypes(matchedUnqualifiedParenthesesCall);
}
} else {
throw new NotImplementedException(
"Highlighting types for " + grandChild.getClass().getCanonicalName() + " PsiElements is not " +
"implemented yet. Please open an issue " +
"(https://github.com/KronicDeth/intellij-elixir/issues/new) with the class name of " +
"the sample text:\n" + grandChild.getText()
);
cannotHighlightTypes(grandChild);
}
}
}
Expand Down Expand Up @@ -385,12 +372,7 @@ private void highlightTypesAndTypeTypeParameterDeclarations(PsiElement psiElemen
typeTextAttributesKey
);
} else {
throw new NotImplementedException(
"Highlighting types and type type parameter declarations for " +
psiElement.getClass().getCanonicalName() + " PsiElements is not implemented yet. Please " +
"open an issue (https://github.com/KronicDeth/intellij-elixir/issues/new) with the class " +
"name of the sample text:\n" + psiElement.getText()
);
error("Cannot highlight types and type parameter declarations", psiElement);
}
}

Expand Down Expand Up @@ -520,15 +502,7 @@ private void highlightSpecification(AtUnqualifiedNoParenthesesCall atUnqualified
);
}
} else {
throw new NotImplementedException(
"Highlighting types for " +
matchedTypeOperationLeftOperand.getClass().getCanonicalName() +
" PsiElements that are the left operand of " +
matchedTypeOperation.getClass().getCanonicalName() + " is not implemented " +
"yet. Please open an issue " +
"(https://github.com/KronicDeth/intellij-elixir/issues/new) with the class " +
"name of the sample text:\n" + matchedWhenOperation.getText()
);
cannotHighlightTypes(matchedTypeOperationLeftOperand);
}

PsiElement matchedTypeOperationRightOperand = matchedTypeOperation.rightOperand();
Expand All @@ -540,13 +514,7 @@ private void highlightSpecification(AtUnqualifiedNoParenthesesCall atUnqualified
ElixirSyntaxHighlighter.TYPE
);
} else {
throw new NotImplementedException(
"Highlighting types for " + leftOperand.getClass().getCanonicalName() + " PsiElements " +
"that are the left operand of " +
matchedWhenOperation.getClass().getCanonicalName() + " is not implemented yet. " +
"Please open an issue (https://github.com/KronicDeth/intellij-elixir/issues/new) " +
"with the class name of the sample text:\n" + matchedWhenOperation.getText()
);
cannotHighlightTypes(leftOperand);
}

highlightTypesAndSpecificationTypeParameterDeclarations(
Expand Down Expand Up @@ -613,27 +581,7 @@ private void highlightTypesAndSpecificationTypeParameterDeclarations(PsiElement
typeTextAttributesKey
);
} else {
throw new NotImplementedException(
"Highlighting types and type parameter declarations not implemented for your use case. Please " +
"open an issue (https://github.com/KronicDeth/intellij-elixir/issues/new) using the " +
"following:\n" +
"\n" +
"# Class\n" +
"\n" +
"`" + psiElement.getClass().getCanonicalName() + "`\n" +
"\n" +
"# Excerpt\n" +
"\n" +
"```\n" +
psiElement.getText() + "\n" +
"```\n" +
"\n" +
"# Full Text\n" +
"\n" +
"```\n" +
psiElement.getContainingFile().getText() + "\n" +
"```"
);
error("Cannot highlight types and specification type parameter declarations", psiElement);
}
}

Expand All @@ -659,8 +607,6 @@ private void highlightTypesAndSpecificationTypeParameterDeclarations(
if (typeParameterNameSet.contains(unqualifiedNoArgumentsCall.functionName())) {
PsiElement functionNameElement = unqualifiedNoArgumentsCall.functionNameElement();

assert functionNameElement != null;

highlight(
functionNameElement.getTextRange(),
annotationHolder,
Expand Down Expand Up @@ -754,12 +700,7 @@ private void highlightTypesAndTypeParameterUsages(
typeTextAttributesKey
);
} else {
throw new NotImplementedException(
"Highlighting types for " + stabParenthesesSignature.getClass().getCanonicalName() +
" PsiElements with neither 1 nor 3 children is not implemented yet. Please open an " +
"issue (https://github.com/KronicDeth/intellij-elixir/issues/new) with the class name " +
"of the sample text:\n" + stabParenthesesSignature.getText()
);
error("Cannot highlight types and type parameter usages", stabParenthesesSignature);
}
}

Expand Down Expand Up @@ -929,12 +870,7 @@ private void highlightTypesAndTypeParameterUsages(PsiElement psiElement,
typeTextAttributesKey
);
} else {
throw new NotImplementedException(
"Highlighting types for " + psiElement.getClass().getCanonicalName() +
" PsiElements is not implemented yet. Please open an issue " +
"(https://github.com/KronicDeth/intellij-elixir/issues/new) with the class name of the " +
"sample text:\n" + psiElement.getText()
);
cannotHighlightTypes(psiElement);
}
}

Expand Down Expand Up @@ -1032,15 +968,19 @@ private void highlightTypesAndTypeParameterUsages(
AnnotationHolder annotationHolder,
TextAttributesKey typeTextAttributesKey) {
PsiElement functionNameElement = unqualifiedNoParenthesesCall.functionNameElement();
assert functionNameElement != null;
highlight(functionNameElement.getTextRange(), annotationHolder, typeTextAttributesKey);

highlightTypesAndTypeParameterUsages(
unqualifiedNoParenthesesCall.primaryArguments(),
typeParameterNameSet,
annotationHolder,
typeTextAttributesKey
);
if (functionNameElement != null) {
highlight(functionNameElement.getTextRange(), annotationHolder, typeTextAttributesKey);

highlightTypesAndTypeParameterUsages(
unqualifiedNoParenthesesCall.primaryArguments(),
typeParameterNameSet,
annotationHolder,
typeTextAttributesKey
);
} else {
error("Cannot highlight types and type parameter usages", unqualifiedNoParenthesesCall);
}
}

private void highlightTypesAndTypeParameterUsages(
Expand All @@ -1050,26 +990,29 @@ private void highlightTypesAndTypeParameterUsages(
TextAttributesKey typeTextAttributesKey) {
PsiElement functionNameElement = unqualifiedParenthesesCall.functionNameElement();

assert functionNameElement != null;

highlight(functionNameElement.getTextRange(), annotationHolder, typeTextAttributesKey);
if (functionNameElement != null) {

highlightTypesAndTypeParameterUsages(
unqualifiedParenthesesCall.primaryArguments(),
typeParameterNameSet,
annotationHolder,
typeTextAttributesKey
);
highlight(functionNameElement.getTextRange(), annotationHolder, typeTextAttributesKey);

PsiElement[] secondaryArguments = unqualifiedParenthesesCall.secondaryArguments();

if (secondaryArguments != null) {
highlightTypesAndTypeParameterUsages(
secondaryArguments,
unqualifiedParenthesesCall.primaryArguments(),
typeParameterNameSet,
annotationHolder,
typeTextAttributesKey
);

PsiElement[] secondaryArguments = unqualifiedParenthesesCall.secondaryArguments();

if (secondaryArguments != null) {
highlightTypesAndTypeParameterUsages(
secondaryArguments,
typeParameterNameSet,
annotationHolder,
typeTextAttributesKey
);
}
} else {
error("Cannot highlight types and type parameter usages", unqualifiedParenthesesCall);
}
}

Expand Down Expand Up @@ -1116,40 +1059,25 @@ private Set<String> specificationTypeParameterNameSet(ElixirNoParenthesesKeyword
}

private Set<String> specificationTypeParameterNameSet(PsiElement psiElement) {
Set<String> parameterNameSet;

if (psiElement instanceof ElixirAccessExpression ||
psiElement instanceof ElixirKeywords ||
psiElement instanceof ElixirList ||
psiElement instanceof ElixirNoParenthesesKeywords) {
return specificationTypeParameterNameSet(psiElement.getChildren());
parameterNameSet = specificationTypeParameterNameSet(psiElement.getChildren());
} else if (psiElement instanceof ElixirKeywordPair) {
return specificationTypeParameterNameSet((ElixirKeywordPair) psiElement);
parameterNameSet = specificationTypeParameterNameSet((ElixirKeywordPair) psiElement);
} else if (psiElement instanceof ElixirNoParenthesesKeywordPair) {
return specificationTypeParameterNameSet((ElixirNoParenthesesKeywordPair) psiElement);
parameterNameSet = specificationTypeParameterNameSet((ElixirNoParenthesesKeywordPair) psiElement);
} else if (psiElement instanceof UnqualifiedNoArgumentsCall) {
return specificationTypeParameterNameSet((UnqualifiedNoArgumentsCall) psiElement);
parameterNameSet = specificationTypeParameterNameSet((UnqualifiedNoArgumentsCall) psiElement);
} else {
throw new NotImplementedException(
"Extracting specification type parameter name set not implemented for your use case. Please open " +
"an issue (https://github.com/KronicDeth/intellij-elixir/issues/new) using the " +
"following:\n" +
"\n" +
"# Class\n" +
"\n" +
"`" + psiElement.getClass().getCanonicalName() + "`\n" +
"\n" +
"# Excerpt\n" +
"\n" +
"```\n" +
psiElement.getText() + "\n" +
"```\n" +
"\n" +
"# Full Text\n" +
"\n" +
"```\n" +
psiElement.getContainingFile().getText() + "\n" +
"```"
);
error("Cannot extract specification type parameter name set", psiElement);
parameterNameSet = Collections.emptySet();
}

return parameterNameSet;
}

private Set<String> specificationTypeParameterNameSet(PsiElement[] psiElements) {
Expand Down Expand Up @@ -1191,16 +1119,16 @@ private Set<String> typeTypeParameterNameSet(
}

private Set<String> typeTypeParameterNameSet(PsiElement psiElement) {
Set<String> typeParameterNameSet;

if (psiElement instanceof ElixirUnmatchedUnqualifiedNoArgumentsCall) {
return Collections.singleton(psiElement.getText());
typeParameterNameSet = Collections.singleton(psiElement.getText());
} else {
throw new NotImplementedException(
"Extracting type type parameter name set for " + psiElement.getClass().getCanonicalName() +
" PsiElements is not implemented yet. Please open an issue " +
"(https://github.com/KronicDeth/intellij-elixir/issues/new) with the class name of the " +
"sample text:\n" + psiElement.getText()
);
error("Cannot extract type type parameter name set", psiElement);
typeParameterNameSet = Collections.emptySet();
}

return typeParameterNameSet;
}

private Set<String> typeTypeParameterNameSet(PsiElement[] psiElements) {
Expand Down
Loading