use of org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall in project intellij-elixir by KronicDeth.
the class CallDefinition method getLineMarkerInfo.
@Nullable
private LineMarkerInfo getLineMarkerInfo(@NotNull Call call) {
LineMarkerInfo lineMarkerInfo = null;
if (daemonCodeAnalyzerSettings.SHOW_METHOD_SEPARATORS && CallDefinitionClause.is(call)) {
Call previousCallDefinitionClause = siblingCallDefinitionClause(call, PREVIOUS_SIBLING);
boolean firstClause;
if (previousCallDefinitionClause == null) {
firstClause = true;
} else {
Pair<String, IntRange> callNameArityRange = nameArityRange(call);
if (callNameArityRange != null) {
Pair<String, IntRange> previousNameArityRange = nameArityRange(previousCallDefinitionClause);
firstClause = previousNameArityRange == null || !previousNameArityRange.equals(callNameArityRange);
} else {
firstClause = true;
}
}
if (firstClause) {
PsiElement previousExpression = previousSiblingExpression(call);
if (previousExpression instanceof AtUnqualifiedNoParenthesesCall) {
AtUnqualifiedNoParenthesesCall previousModuleAttributeDefinition = (AtUnqualifiedNoParenthesesCall) previousExpression;
String moduleAttributeName = moduleAttributeName(previousModuleAttributeDefinition);
if (moduleAttributeName.equals("@doc")) {
firstClause = false;
} else if (moduleAttributeName.equals("@spec")) {
Pair<String, IntRange> callNameArityRange = nameArityRange(call);
if (callNameArityRange != null) {
Pair<String, Integer> specNameArity = moduleAttributeNameArity(previousModuleAttributeDefinition);
if (specNameArity != null) {
Integer specArity = specNameArity.second;
IntRange callArityRange = callNameArityRange.second;
if (callArityRange.containsInteger(specArity)) {
firstClause = false;
}
}
}
}
}
}
if (firstClause) {
lineMarkerInfo = callDefinitionSeparator(call);
}
}
return lineMarkerInfo;
}
use of org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall in project intellij-elixir by KronicDeth.
the class CallDefinition method getLineMarkerInfo.
@Nullable
private LineMarkerInfo getLineMarkerInfo(@NotNull AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall) {
LineMarkerInfo lineMarkerInfo = null;
String moduleAttributeName = moduleAttributeName(atUnqualifiedNoParenthesesCall);
if (moduleAttributeName.equals("@doc")) {
PsiElement previousExpression = siblingExpression(atUnqualifiedNoParenthesesCall, PREVIOUS_SIBLING);
boolean firstInGroup = true;
if (previousExpression instanceof AtUnqualifiedNoParenthesesCall) {
AtUnqualifiedNoParenthesesCall previousModuleAttribute = (AtUnqualifiedNoParenthesesCall) previousExpression;
String previousModuleAttributeName = moduleAttributeName(previousModuleAttribute);
if (previousModuleAttributeName.equals("@spec")) {
Pair<String, Integer> moduleAttributeNameArity = moduleAttributeNameArity(previousModuleAttribute);
if (moduleAttributeNameArity != null) {
Call nextSiblingCallDefinitionClause = siblingCallDefinitionClause(atUnqualifiedNoParenthesesCall, NEXT_SIBLING);
if (nextSiblingCallDefinitionClause != null) {
Pair<String, IntRange> nameArityRange = nameArityRange(nextSiblingCallDefinitionClause);
if (nameArityRange != null) {
IntRange arityRange = nameArityRange.second;
if (arityRange.containsInteger(moduleAttributeNameArity.second)) {
// the previous spec is part of the group
firstInGroup = false;
}
}
}
}
}
}
if (firstInGroup) {
lineMarkerInfo = callDefinitionSeparator(atUnqualifiedNoParenthesesCall);
}
} else if (moduleAttributeName.equals("@spec")) {
PsiElement previousExpression = siblingExpression(atUnqualifiedNoParenthesesCall, PREVIOUS_SIBLING);
boolean firstInGroup = true;
if (previousExpression instanceof AtUnqualifiedNoParenthesesCall) {
AtUnqualifiedNoParenthesesCall previousModuleAttribute = (AtUnqualifiedNoParenthesesCall) previousExpression;
String previousModuleAttributeName = moduleAttributeName(previousModuleAttribute);
if (previousModuleAttributeName.equals("@doc")) {
firstInGroup = false;
} else if (previousModuleAttributeName.equals("@spec")) {
Pair<String, Integer> moduleAttributeNameArity = moduleAttributeNameArity(atUnqualifiedNoParenthesesCall);
if (moduleAttributeNameArity != null) {
Pair<String, Integer> previousModuleAttributeNameArity = moduleAttributeNameArity(previousModuleAttribute);
if (previousModuleAttributeNameArity != null) {
// name match, now check if the arities match.
if (moduleAttributeNameArity.first.equals(previousModuleAttributeNameArity.first)) {
Integer moduleAttributeArity = moduleAttributeNameArity.second;
Integer previousModuleAttributeArity = previousModuleAttributeNameArity.second;
if (moduleAttributeArity.equals(previousModuleAttributeArity)) {
/* same arity with different pattern is same function, so the previous @spec should
check if it is first because this one isn't */
firstInGroup = false;
} else {
/* same name, but different arity needs to determine if the call definition has an
arity range. */
Call specification = specification(atUnqualifiedNoParenthesesCall);
if (specification != null) {
Call type = specificationType(specification);
if (type != null) {
PsiReference reference = type.getReference();
if (reference != null) {
List<PsiElement> resolvedList = null;
if (reference instanceof PsiPolyVariantReference) {
PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
if (resolveResults.length > 0) {
resolvedList = new ArrayList<PsiElement>();
for (ResolveResult resolveResult : resolveResults) {
resolvedList.add(resolveResult.getElement());
}
}
} else {
PsiElement resolved = reference.resolve();
if (resolved != null) {
resolvedList = Collections.singletonList(resolved);
}
}
if (resolvedList != null && resolvedList.size() > 0) {
for (PsiElement resolved : resolvedList) {
if (resolved instanceof Call) {
Pair<String, IntRange> resolvedNameArityRange = nameArityRange((Call) resolved);
if (resolvedNameArityRange != null) {
IntRange resolvedArityRange = resolvedNameArityRange.second;
if (resolvedArityRange.containsInteger(moduleAttributeArity) && resolvedArityRange.containsInteger(previousModuleAttributeArity)) {
// the current @spec and the previous @spec apply to the same call definition clause
firstInGroup = false;
break;
}
}
}
}
}
}
}
}
}
}
}
}
}
} else {
Call specification = specification(atUnqualifiedNoParenthesesCall);
if (specification != null) {
Call type = specificationType(specification);
if (type != null) {
PsiReference reference = type.getReference();
if (reference != null) {
if (reference instanceof PsiPolyVariantReference) {
PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
PsiFile containingFile = type.getContainingFile();
for (ResolveResult resolveResult : resolveResults) {
PsiElement element = resolveResult.getElement();
if (element != null) {
if (element.getContainingFile().equals(containingFile) && element.getTextOffset() < type.getTextOffset()) {
firstInGroup = false;
break;
}
}
}
}
}
}
}
}
if (firstInGroup) {
lineMarkerInfo = callDefinitionSeparator(atUnqualifiedNoParenthesesCall);
}
}
return lineMarkerInfo;
}
use of org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall in project intellij-elixir by KronicDeth.
the class Type method is.
public static boolean is(@NotNull Call call) {
boolean is = false;
if (call instanceof AtUnqualifiedNoParenthesesCall) {
AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall = (AtUnqualifiedNoParenthesesCall) call;
String moduleAttributeName = ElixirPsiImplUtil.moduleAttributeName(atUnqualifiedNoParenthesesCall);
is = moduleAttributeName.equals("@opaque") || moduleAttributeName.equals("@type") || moduleAttributeName.equals("@typep");
}
return is;
}
Aggregations