use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-community by JetBrains.
the class PyExecuteFileLineMarkerProvider method collectSlowLineMarkers.
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
if (elements.isEmpty()) {
return;
}
Optional<PsiElement> psiElement = elements.stream().filter((element) -> element instanceof PsiFile).findFirst();
if (!psiElement.isPresent())
return;
final PsiElement file = psiElement.get();
final RunContextAction runAction = new PyStudyRunContextAction(DefaultRunExecutor.getRunExecutorInstance());
final PyExecuteFileExtensionPoint[] extensions = ApplicationManager.getApplication().getExtensions(PyExecuteFileExtensionPoint.EP_NAME);
final List<AnAction> actions = new ArrayList<>();
final DefaultActionGroup group = new DefaultActionGroup();
if (PlatformUtils.isPyCharmEducational()) {
group.add(runAction);
}
for (PyExecuteFileExtensionPoint extension : extensions) {
AnAction action = extension.getRunAction();
if (action != null && extension.accept(file.getProject())) {
actions.add(action);
group.add(action);
}
}
if (actions.isEmpty() && !PlatformUtils.isPyCharmEducational()) {
return;
}
Icon icon = PlatformUtils.isPyCharmEducational() ? AllIcons.Actions.Execute : actions.get(0).getTemplatePresentation().getIcon();
final LineMarkerInfo<PsiElement> markerInfo = new LineMarkerInfo<PsiElement>(file, file.getTextRange(), icon, Pass.LINE_MARKERS, e -> {
String text = "Execute '" + e.getContainingFile().getName() + "'";
return PlatformUtils.isPyCharmEducational() ? text : actions.get(0).getTemplatePresentation().getText();
}, null, GutterIconRenderer.Alignment.RIGHT) {
@Nullable
@Override
public GutterIconRenderer createGutterRenderer() {
return new LineMarkerGutterIconRenderer<PsiElement>(this) {
@Override
public AnAction getClickAction() {
return PlatformUtils.isPyCharmEducational() ? runAction : actions.get(0);
}
@Nullable
@Override
public ActionGroup getPopupMenuActions() {
if (!PlatformUtils.isPyCharmEducational() && actions.isEmpty()) {
return null;
}
if (actions.size() == 1) {
return null;
}
return group;
}
};
}
};
result.add(markerInfo);
}
use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-community by JetBrains.
the class PyLineMarkerProvider method getMethodMarker.
@Nullable
private static LineMarkerInfo<PsiElement> getMethodMarker(final PsiElement element, final PyFunction function) {
if (PyNames.INIT.equals(function.getName())) {
return null;
}
final TypeEvalContext context = TypeEvalContext.codeAnalysis(element.getProject(), (function != null ? function.getContainingFile() : null));
final PsiElement superMethod = PySuperMethodsSearch.search(function, context).findFirst();
if (superMethod != null) {
PyClass superClass = null;
if (superMethod instanceof PyFunction) {
superClass = ((PyFunction) superMethod).getContainingClass();
}
// TODO: show "implementing" instead of "overriding" icon for Python implementations of Java interface methods
return new LineMarkerInfo<PsiElement>(element, element.getTextRange().getStartOffset(), AllIcons.Gutter.OverridingMethod, Pass.LINE_MARKERS, superClass == null ? null : new TooltipProvider("Overrides method in " + superClass.getName()), ourSuperMethodNavigator);
}
return null;
}
use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-community by JetBrains.
the class PyLineMarkerProvider method getAttributeMarker.
@Nullable
private static LineMarkerInfo<PsiElement> getAttributeMarker(PyTargetExpression element) {
final String name = element.getReferencedName();
if (name == null) {
return null;
}
PyClass containingClass = PsiTreeUtil.getParentOfType(element, PyClass.class);
if (containingClass == null)
return null;
for (PyClass ancestor : containingClass.getAncestorClasses(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()))) {
final PyTargetExpression ancestorAttr = ancestor.findClassAttribute(name, false, null);
if (ancestorAttr != null) {
return new LineMarkerInfo<PsiElement>(element, element.getTextRange().getStartOffset(), AllIcons.Gutter.OverridingMethod, Pass.LINE_MARKERS, new TooltipProvider("Overrides attribute in " + ancestor.getName()), ourSuperAttributeNavigator);
}
}
return null;
}
use of com.intellij.codeInsight.daemon.LineMarkerInfo in project intellij-community by JetBrains.
the class GroovyLineMarkerProvider method getLineMarkerInfo.
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
final PsiElement parent = element.getParent();
if (parent instanceof PsiNameIdentifierOwner) {
if (parent instanceof GrField && element == ((GrField) parent).getNameIdentifierGroovy()) {
for (GrAccessorMethod method : GroovyPropertyUtils.getFieldAccessors((GrField) parent)) {
MethodSignatureBackedByPsiMethod superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst();
if (superSignature != null) {
PsiMethod superMethod = superSignature.getMethod();
boolean overrides = method.hasModifierProperty(PsiModifier.ABSTRACT) == superMethod.hasModifierProperty(PsiModifier.ABSTRACT) || superMethod.getBody() != null && GrTraitUtil.isTrait(superMethod.getContainingClass());
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
final MarkerType type = GroovyMarkerTypes.OVERRIDING_PROPERTY_TYPE;
return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
}
}
} else if (parent instanceof GrMethod && element == ((GrMethod) parent).getNameIdentifierGroovy() && hasSuperMethods((GrMethod) element.getParent())) {
final Icon icon = AllIcons.Gutter.OverridingMethod;
final MarkerType type = GroovyMarkerTypes.GR_OVERRIDING_METHOD;
return new LineMarkerInfo<>(element, element.getTextRange(), icon, Pass.LINE_MARKERS, type.getTooltip(), type.getNavigationHandler(), GutterIconRenderer.Alignment.LEFT);
}
}
//need to draw method separator above docComment
if (myDaemonSettings.SHOW_METHOD_SEPARATORS && element.getFirstChild() == null) {
PsiElement element1 = element;
boolean isMember = false;
while (element1 != null && !(element1 instanceof PsiFile) && element1.getPrevSibling() == null) {
element1 = element1.getParent();
if (element1 instanceof PsiMember || element1 instanceof GrVariableDeclarationImpl) {
isMember = true;
break;
}
}
if (isMember && !(element1 instanceof PsiAnonymousClass || element1.getParent() instanceof PsiAnonymousClass)) {
PsiFile file = element1.getContainingFile();
Document document = file == null ? null : PsiDocumentManager.getInstance(file.getProject()).getLastCommittedDocument(file);
boolean drawSeparator = false;
if (document != null) {
CharSequence documentChars = document.getCharsSequence();
int category = getGroovyCategory(element1, documentChars);
for (PsiElement child = element1.getPrevSibling(); child != null; child = child.getPrevSibling()) {
int category1 = getGroovyCategory(child, documentChars);
if (category1 == 0)
continue;
drawSeparator = category != 1 || category1 != 1;
break;
}
}
if (drawSeparator) {
GrDocComment comment = null;
if (element1 instanceof GrDocCommentOwner) {
comment = ((GrDocCommentOwner) element1).getDocComment();
}
LineMarkerInfo info = new LineMarkerInfo<>(element, comment != null ? comment.getTextRange() : element.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 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;
}
Aggregations