use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.
the class Issue480Test method assertResolvedNameArityRange.
private void assertResolvedNameArityRange(@NotNull PsiElement element, @NotNull String name, int arity) {
PsiReference reference = element.getReference();
assertNotNull(reference);
PsiElement resolved = reference.resolve();
assertNotNull(resolved);
assertInstanceOf(resolved, ElixirIdentifier.class);
PsiElement maybeDefMaybeCall = resolved.getParent().getParent().getParent();
assertInstanceOf(maybeDefMaybeCall, Call.class);
Call maybeDefCall = (Call) maybeDefMaybeCall;
assertTrue(CallDefinitionClause.is(maybeDefCall));
assertEquals(pair(name, new IntRange(arity)), nameArityRange(maybeDefCall));
}
use of org.apache.commons.lang.math.IntRange 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.apache.commons.lang.math.IntRange 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.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.
the class CallDefinitionClause method callDefinitionClauseLookupElements.
/*
* Private Instance Methods
*/
@NotNull
private static Iterable<LookupElement> callDefinitionClauseLookupElements(@NotNull Call scope) {
Call[] childCalls = macroChildCalls(scope);
List<LookupElement> lookupElementList = null;
if (childCalls != null && childCalls.length > 0) {
for (Call childCall : childCalls) {
if (org.elixir_lang.structure_view.element.CallDefinitionClause.is(childCall)) {
Pair<String, IntRange> nameArityRange = nameArityRange(childCall);
if (nameArityRange != null) {
String name = nameArityRange.first;
if (name != null) {
if (lookupElementList == null) {
lookupElementList = new ArrayList<LookupElement>();
}
lookupElementList.add(org.elixir_lang.code_insight.lookup.element.CallDefinitionClause.createWithSmartPointer(nameArityRange.first, childCall));
}
}
}
}
}
if (lookupElementList == null) {
lookupElementList = Collections.emptyList();
}
return lookupElementList;
}
use of org.apache.commons.lang.math.IntRange in project intellij-elixir by KronicDeth.
the class CallDefinition method fromCall.
/*
* Constructors
*/
/**
* @param call a def(macro)?p? call
*/
@Nullable
public static CallDefinition fromCall(@NotNull Call call) {
Modular modular = CallDefinitionClause.enclosingModular(call);
CallDefinition callDefinition = null;
if (modular != null) {
Pair<String, IntRange> nameArityRange = CallDefinitionClause.nameArityRange(call);
if (nameArityRange != null) {
String name = nameArityRange.first;
/* arity is assumed to be max arity in the range because that's how {@code h} and ExDoc treat functions
with defaults. */
int arity = nameArityRange.second.getMaximumInteger();
Time time = CallDefinitionClause.time(call);
callDefinition = new CallDefinition(modular, time, name, arity);
}
}
return callDefinition;
}
Aggregations