use of com.intellij.codeInsight.daemon.LineMarkerInfo 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 com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-community by JetBrains.
the class ExpectedHighlightingData method extractExpectedLineMarkerSet.
private void extractExpectedLineMarkerSet(Document document) {
String text = document.getText();
String pat = ".*?((<" + LINE_MARKER + ")(?: descr=\"((?:[^\"\\\\]|\\\\\")*)\")?>)(.*)";
final Pattern p = Pattern.compile(pat, Pattern.DOTALL);
final Pattern pat2 = Pattern.compile("(.*?)(</" + LINE_MARKER + ">)(.*)", Pattern.DOTALL);
while (true) {
Matcher m = p.matcher(text);
if (!m.matches())
break;
int startOffset = m.start(1);
final String descr = m.group(3) != null ? m.group(3) : ANY_TEXT;
String rest = m.group(4);
document.replaceString(startOffset, m.end(1), "");
final Matcher matcher2 = pat2.matcher(rest);
LOG.assertTrue(matcher2.matches(), "Cannot find closing </" + LINE_MARKER + ">");
String content = matcher2.group(1);
int endOffset = startOffset + matcher2.start(3);
String endTag = matcher2.group(2);
document.replaceString(startOffset, endOffset, content);
endOffset -= endTag.length();
LineMarkerInfo markerInfo = new LineMarkerInfo<PsiElement>(myFile, new TextRange(startOffset, endOffset), null, Pass.LINE_MARKERS, new ConstantFunction<>(descr), null, GutterIconRenderer.Alignment.RIGHT);
myLineMarkerInfos.put(document.createRangeMarker(startOffset, endOffset), markerInfo);
text = document.getText();
}
}
use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-plugins by JetBrains.
the class DartServerOverrideMarkerProvider method tryCreateOverrideMarker.
@Nullable
private static LineMarkerInfo tryCreateOverrideMarker(@NotNull final DartComponentName componentName, @Nullable final DartComponent superclassComponent, @NotNull final List<DartComponent> interfaceComponents) {
if (superclassComponent == null && interfaceComponents.isEmpty()) {
return null;
}
final String name = componentName.getName();
final boolean overrides;
final DartComponent superComponent;
if (superclassComponent != null) {
overrides = true;
superComponent = superclassComponent;
} else {
overrides = false;
superComponent = interfaceComponents.iterator().next();
}
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
return new LineMarkerInfo<>(componentName, componentName.getTextRange(), icon, Pass.LINE_MARKERS, element -> {
final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
if (superClass == null)
return "null";
if (overrides) {
return DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in" : "overrides.method.in", name, superClass.getName());
}
return DartBundle.message("implements.method.in", name, superClass.getName());
}, (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
List<DartComponent> superComponents = Lists.newArrayList();
if (superclassComponent != null) {
superComponents.add(superclassComponent);
}
superComponents.addAll(interfaceComponents);
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents), DaemonBundle.message("navigation.title.super.method", name), DaemonBundle.message("navigation.findUsages.title.super.method", name), new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.LEFT);
}
use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-plugins by JetBrains.
the class DartMethodLineMarkerProvider method getLineMarkerInfo.
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
if (!myDaemonSettings.SHOW_METHOD_SEPARATORS) {
return null;
}
// only continue if element is one of the markable elements (such as methods)
if (isMarkableElement(element)) {
// the method line markers are not nestable, aka, methods inside of methods, are not marked
if (PsiTreeUtil.findFirstParent(element, true, DartMethodLineMarkerProvider::isMarkableElement) != null) {
return null;
}
// move the marker to previous siblings until comments have been included
PsiElement markerLocation = element;
while (markerLocation.getPrevSibling() != null && (markerLocation.getPrevSibling() instanceof PsiComment || (markerLocation.getPrevSibling() instanceof PsiWhiteSpace && markerLocation.getPrevSibling().getPrevSibling() != null && markerLocation.getPrevSibling().getPrevSibling() instanceof PsiComment))) {
markerLocation = markerLocation.getPrevSibling();
}
// if the markerLocation element doesn't have a previous sibling (not whitespace), do not mark
PsiElement prevElement = markerLocation;
while (prevElement.getPrevSibling() != null && prevElement.getPrevSibling() instanceof PsiWhiteSpace) {
prevElement = prevElement.getPrevSibling();
}
if (prevElement.getPrevSibling() == null) {
return null;
}
// finally, create the marker
LineMarkerInfo info = new LineMarkerInfo<>(markerLocation, markerLocation.getTextRange(), null, Pass.LINE_MARKERS, FunctionUtil.<Object, String>nullConstant(), null, GutterIconRenderer.Alignment.RIGHT);
EditorColorsScheme scheme = myColorsManager.getGlobalScheme();
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;
}
return null;
}
use of com.intellij.codeInsight.daemon.LineMarkerInfo in project android by JetBrains.
the class AndroidGotoRelatedTest method doCheckLineMarkers.
private void doCheckLineMarkers(List<VirtualFile> expectedTargetFiles, Class<?> targetElementClass) {
final List<LineMarkerInfo> relatedMarkers = doGetRelatedLineMarkers();
assertEquals(relatedMarkers.toString(), 1, relatedMarkers.size());
final LineMarkerInfo marker = relatedMarkers.get(0);
doCheckItems(expectedTargetFiles, ((AndroidLineMarkerProvider.MyNavigationHandler) marker.getNavigationHandler()).doComputeItems(), targetElementClass);
}
Aggregations