com.intellij.codeInsight.daemon.LineMarkerInfo Java Examples

The following examples show how to use com.intellij.codeInsight.daemon.LineMarkerInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
public void assertLineMarker(@NotNull PsiElement psiElement, @NotNull LineMarker.Assert assertMatch) {

        final List<PsiElement> elements = collectPsiElementsRecursive(psiElement);

        for (LineMarkerProvider lineMarkerProvider : LineMarkerProviders.INSTANCE.allForLanguage(psiElement.getLanguage())) {
            Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<LineMarkerInfo>();
            lineMarkerProvider.collectSlowLineMarkers(elements, lineMarkerInfos);

            if(lineMarkerInfos.size() == 0) {
                continue;
            }

            for (LineMarkerInfo lineMarkerInfo : lineMarkerInfos) {
                if(assertMatch.match(lineMarkerInfo)) {
                    return;
                }
            }
        }

        fail(String.format("Fail that '%s' matches on of '%s' PsiElements", assertMatch.getClass(), elements.size()));
    }
 
Example #2
Source File: NavigationMarkerProvider.java    From android-butterknife-zelezny with Apache License 2.0 6 votes vote down vote up
/**
 * Check if element is a method annotated with <em>@OnClick</em> or a field annotated with
 * <em>@InjectView</em> and create corresponding navigation link.
 *
 * @return a {@link com.intellij.codeInsight.daemon.GutterIconNavigationHandler} for the
 * appropriate type, or null if we don't care about it.
 */
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
    final IButterKnife butterKnife = ButterKnifeFactory.findButterKnifeForPsiElement(element.getProject(), element);
    if (butterKnife == null) {
        return null;
    }
    if (IS_FIELD_IDENTIFIER.apply(element)) {
        return getNavigationLineMarker((PsiIdentifier) element,
                ButterKnifeLink.getButterKnifeLink(butterKnife, IS_FIELD_IDENTIFIER));
    } else if (IS_METHOD_IDENTIFIER.apply(element)) {
        return getNavigationLineMarker((PsiIdentifier) element,
                ButterKnifeLink.getButterKnifeLink(butterKnife, IS_METHOD_IDENTIFIER));
    }

    return null;
}
 
Example #3
Source File: SideEffectLineMarkerProvider.java    From here-be-dragons with MIT License 6 votes vote down vote up
/**
 * @return a {@link com.intellij.codeInsight.daemon.GutterIconNavigationHandler} if the element
 * is a PsiMethod annotated with @SideEffect.
 */
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
    // Check if expression
    if (element instanceof PsiReferenceExpression) {
        PsiReferenceExpression referenceExpression = (PsiReferenceExpression) element;

        // Check if expression has method
        if (referenceExpression.resolve() instanceof PsiMethod) {
            PsiMethod method = (PsiMethod) referenceExpression.resolve();

            // Does it have a @SideEffect?
            if (hasAnnotation(method, CLASS_SIDE_EFFECT)) {
                return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), ICON,
                        UPDATE_ALL, null, null, LEFT);
            }
        }
    }

    return null;
}
 
Example #4
Source File: XmlLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void attachRouteActions(@NotNull PsiElement psiElement, @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {
    PsiElement xmlTag = psiElement.getParent();
    if(!(xmlTag instanceof XmlTag) || !Pattern.getRouteTag().accepts(xmlTag)) {
        return;
    }

    String controller = RouteHelper.getXmlController((XmlTag) xmlTag);
    if(controller != null) {
        PsiElement[] methods = RouteHelper.getMethodsOnControllerShortcut(xmlTag.getProject(), controller);
        if(methods.length > 0) {
            NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.TWIG_CONTROLLER_LINE_MARKER).
                setTargets(methods).
                setTooltipText("Navigate to action");

            lineMarkerInfos.add(builder.createLineMarkerInfo(psiElement));
        }
    }
}
 
Example #5
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
public void assertLineMarker(@NotNull PsiElement psiElement, @NotNull LineMarker.Assert assertMatch) {

        final List<PsiElement> elements = collectPsiElementsRecursive(psiElement);

        for (LineMarkerProvider lineMarkerProvider : LineMarkerProviders.getInstance().allForLanguage(psiElement.getLanguage())) {
            Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<>();
            lineMarkerProvider.collectSlowLineMarkers(elements, lineMarkerInfos);

            if(lineMarkerInfos.size() == 0) {
                continue;
            }

            for (LineMarkerInfo lineMarkerInfo : lineMarkerInfos) {
                if(assertMatch.match(lineMarkerInfo)) {
                    return;
                }
            }
        }

        fail(String.format("Fail that '%s' matches on of '%s' PsiElements", assertMatch.getClass(), elements.size()));
    }
 
Example #6
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private LineMarkerInfo getRelatedPopover(String singleItemTitle, String singleItemTooltipPrefix, PsiElement lineMarkerTarget, List<GotoRelatedItem> gotoRelatedItems, Icon icon) {

        // single item has no popup
        String title = singleItemTitle;
        if(gotoRelatedItems.size() == 1) {
            String customName = gotoRelatedItems.get(0).getCustomName();
            if(customName != null) {
                title = String.format(singleItemTooltipPrefix, customName);
            }
        }

        return new LineMarkerInfo<>(
            lineMarkerTarget,
            lineMarkerTarget.getTextRange(),
            icon,
            6,
            new ConstantFunction<>(title),
            new RelatedPopupGotoLineMarker.NavigationHandler(gotoRelatedItems),
            GutterIconRenderer.Alignment.RIGHT
        );
    }
 
Example #7
Source File: FileSeparatorUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredReadAction
public static List<LineMarkerInfo> getFileSeparators(final PsiFile file, final Document document) {
  final List<LineMarkerInfo> result = new ArrayList<LineMarkerInfo>();
  for (LineMarkerInfo lineMarkerInfo : LineMarkersPass.queryLineMarkers(file, document)) {
    if (lineMarkerInfo.separatorColor != null) {
      result.add(lineMarkerInfo);
    }
  }

  Collections.sort(result, new Comparator<LineMarkerInfo>() {
    @Override
    public int compare(final LineMarkerInfo i1, final LineMarkerInfo i2) {
      return getDisplayLine(i1, document) - getDisplayLine(i2, document);
    }
  });
  return result;
}
 
Example #8
Source File: DoctrineMetadataLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> results) {
    // we need project element; so get it from first item
    if(psiElements.size() == 0) {
        return;
    }

    Project project = psiElements.get(0).getProject();
    if(!Symfony2ProjectComponent.isEnabled(project)) {
        return;
    }

    for(PsiElement psiElement: psiElements) {
        if(psiElement.getNode().getElementType() != XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN) {
            continue;
        }

        PsiElement xmlAttributeValue = psiElement.getParent();
        if(xmlAttributeValue instanceof XmlAttributeValue && (DoctrineMetadataPattern.getXmlTargetDocumentClass().accepts(xmlAttributeValue) || DoctrineMetadataPattern.getXmlTargetEntityClass().accepts(xmlAttributeValue) || DoctrineMetadataPattern.getEmbeddableNameClassPattern().accepts(xmlAttributeValue))) {
            attachXmlRelationMarker(psiElement, (XmlAttributeValue) xmlAttributeValue, results);
        }
    }
}
 
Example #9
Source File: LaravelLightCodeInsightFixtureTestCase.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
public void assertLineMarker(@NotNull PsiElement psiElement, @NotNull LineMarker.Assert assertMatch) {

        final List<PsiElement> elements = collectPsiElementsRecursive(psiElement);

        for (LineMarkerProvider lineMarkerProvider : LineMarkerProviders.INSTANCE.allForLanguage(psiElement.getLanguage())) {
            Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<LineMarkerInfo>();
            lineMarkerProvider.collectSlowLineMarkers(elements, lineMarkerInfos);

            if(lineMarkerInfos.size() == 0) {
                continue;
            }

            for (LineMarkerInfo lineMarkerInfo : lineMarkerInfos) {
                if(assertMatch.match(lineMarkerInfo)) {
                    return;
                }
            }
        }

        fail(String.format("Fail that '%s' matches on of '%s' PsiElements", assertMatch.getClass(), elements.size()));
    }
 
Example #10
Source File: ConfigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void visitRootElements(@NotNull Collection<LineMarkerInfo> result, @NotNull PsiElement psiElement, @NotNull LazyConfigTreeSignatures function) {
    PsiElement parent = psiElement.getParent();
    if(!(parent instanceof YAMLKeyValue)) {
        return;
    }

    String keyText = ((YAMLKeyValue) parent).getKeyText();
    Map<String, Collection<String>> treeSignatures = function.value();
    if(!treeSignatures.containsKey(keyText)) {
        return;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.SYMFONY_LINE_MARKER)
        .setTargets(new MyClassIdLazyValue(psiElement.getProject(), treeSignatures.get(keyText), keyText))
        .setTooltipText("Navigate to configuration");

    result.add(builder.createLineMarkerInfo(psiElement));
}
 
Example #11
Source File: XmlLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> result) {
    if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) {
        return;
    }

    LazyDecoratedParentServiceValues lazyDecoratedParentServiceValues = null;

    for (PsiElement psiElement : psiElements) {
        if(!XmlHelper.getXmlTagNameLeafStartPattern().accepts(psiElement)) {
            continue;
        }

        PsiElement xmlTag = psiElement.getParent();
        if(!(xmlTag instanceof XmlTag) || !getServiceIdPattern().accepts(xmlTag)) {
            continue;
        }

        if(lazyDecoratedParentServiceValues == null) {
            lazyDecoratedParentServiceValues = new LazyDecoratedParentServiceValues(psiElement.getProject());
        }

        // <services><service id="foo"/></services>
        visitServiceId(psiElement, (XmlTag) xmlTag, result, lazyDecoratedParentServiceValues);
    }
}
 
Example #12
Source File: RecursiveCallCollector.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Override
public void collect(PsiElement psiElement, @Nonnull Consumer<LineMarkerInfo> consumer)
{
	if(psiElement.getNode().getElementType() == CSharpTokens.IDENTIFIER && psiElement.getParent() instanceof CSharpReferenceExpression &&
			psiElement.getParent().getParent() instanceof CSharpMethodCallExpressionImpl)
	{
		PsiElement resolvedElement = ((CSharpReferenceExpression) psiElement.getParent()).resolve();
		if(resolvedElement instanceof CSharpMethodDeclaration)
		{
			CSharpMethodDeclaration methodDeclaration = PsiTreeUtil.getParentOfType(psiElement, CSharpMethodDeclaration.class);
			if(resolvedElement.isEquivalentTo(methodDeclaration))
			{
				LineMarkerInfo<PsiElement> lineMarkerInfo = new LineMarkerInfo<PsiElement>(psiElement, psiElement.getTextRange(), AllIcons.Gutter.RecursiveMethod, Pass.LINE_MARKERS,
						FunctionUtil.constant("Recursive call"), null, GutterIconRenderer.Alignment.CENTER);
				consumer.consume(lineMarkerInfo);
			}
		}
	}
}
 
Example #13
Source File: ProvidesLineMarkerProvider.java    From dagger-intellij-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * @return a {@link com.intellij.codeInsight.daemon.GutterIconNavigationHandler} if the element
 *         is a PsiMethod annotated with @Provides.
 */
@Nullable @Override
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
  // Check methods first (includes constructors).
  if (element instanceof PsiMethod) {
    PsiMethod methodElement = (PsiMethod) element;

    // Does it have an @Provides?
    if (hasAnnotation(element, CLASS_PROVIDES)) {
      PsiTypeElement returnTypeElement = methodElement.getReturnTypeElement();
      if (returnTypeElement != null) {
        return new LineMarkerInfo<PsiElement>(element, returnTypeElement.getTextRange(), ICON,
            UPDATE_ALL, null, new ProvidesToInjectHandler(), LEFT);
      }
    }

    // Is it an @Inject-able constructor?
    if (methodElement.isConstructor() && hasAnnotation(element, CLASS_INJECT)) {
      return new LineMarkerInfo<PsiElement>(element, element.getTextRange(), ICON,
          UPDATE_ALL, null, new ConstructorInjectToInjectionPlaceHandler(), LEFT);
    }
  }

  return null;
}
 
Example #14
Source File: DoctrineMetadataLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void attachXmlRelationMarker(@NotNull PsiElement target, @NotNull XmlAttributeValue psiElement, @NotNull Collection<LineMarkerInfo> results) {
    String value = psiElement.getValue();
    if(StringUtils.isBlank(value)) {
        return;
    }

    Collection<PhpClass> classesInterface = DoctrineMetadataUtil.getClassInsideScope(psiElement, value);
    if(classesInterface.size() == 0) {
        return;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.DOCTRINE_LINE_MARKER).
        setTargets(classesInterface).
        setTooltipText("Navigate to class");

    results.add(builder.createLineMarkerInfo(target));
}
 
Example #15
Source File: ExtJsTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private void attachControllerAction(PsiElement sourceElement, Collection<LineMarkerInfo> lineMarkerInfos) {

        if(!ShopwareProjectComponent.isValidForProject(sourceElement)) {
            return;
        }

        String text = PsiElementUtils.trimQuote(sourceElement.getText());
        if(text.startsWith("{") && text.endsWith("}")) {

            List<PsiElement> controllerTargets = ExtJsUtil.getControllerTargets(sourceElement, text);
            if(controllerTargets.size() > 0) {
                NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(ShopwarePluginIcons.SHOPWARE_LINEMARKER).
                    setTargets(controllerTargets).
                    setTooltipText("Navigate to action");

                lineMarkerInfos.add(builder.createLineMarkerInfo(sourceElement));
            }
        }

    }
 
Example #16
Source File: ConfigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> result) {
    if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) {
        return;
    }

    LazyConfigTreeSignatures function = null;

    for (PsiElement psiElement : psiElements) {
        if(psiElement.getNode().getElementType() == YAMLTokenTypes.SCALAR_KEY && YamlElementPatternHelper.getRootConfigKeyPattern().accepts(psiElement)) {
            if(function == null) {
                function = new LazyConfigTreeSignatures(psiElements.get(0).getProject());
            }
            visitRootElements(result, psiElement, function);
        }
    }
}
 
Example #17
Source File: MethodLineMarkerProvider.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    for (PsiElement el : elements) {
        if (el instanceof Method && ((Method) el).getAccess().isPublic()) {
            VirtualFile template = ResolveEngine.findTemplate((Method) el);
            if (template != null) {
                PsiFile target = PsiManager.getInstance(el.getProject()).findFile(template);
                RelatedItemLineMarkerInfo info = NavigationGutterIconBuilder
                        .create(NeosIcons.NODE_TYPE)
                        .setTarget(target)
                        .setTooltipText("Go to template")
                        .createLineMarkerInfo(el);
                result.add(info);
            }
        }
    }
}
 
Example #18
Source File: SmartyTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private LineMarkerInfo getRelatedPopover(String singleItemTitle, String singleItemTooltipPrefix, PsiElement lineMarkerTarget, List<GotoRelatedItem> gotoRelatedItems) {

        // single item has no popup
        String title = singleItemTitle;
        if(gotoRelatedItems.size() == 1) {
            String customName = gotoRelatedItems.get(0).getCustomName();
            if(customName != null) {
                title = String.format(singleItemTooltipPrefix, customName);
            }
        }

        return new LineMarkerInfo<>(
            lineMarkerTarget,
            lineMarkerTarget.getTextRange(),
            ShopwarePluginIcons.SHOPWARE_LINEMARKER,
            6,
            new ConstantFunction<>(title),
            new fr.adrienbrault.idea.symfony2plugin.dic.RelatedPopupGotoLineMarker.NavigationHandler(gotoRelatedItems),
            GutterIconRenderer.Alignment.RIGHT
        );
    }
 
Example #19
Source File: SmartyTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
public void attachTemplateBlocks(PsiElement psiElement, Collection<LineMarkerInfo> lineMarkerInfos) {

        SmartyBlockGoToHandler goToHandler = new SmartyBlockGoToHandler();
        PsiElement[] gotoDeclarationTargets = goToHandler.getGotoDeclarationTargets(psiElement, 0, null);

        if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) {
            return;
        }

        List<PsiElement> psiElements = Arrays.asList(gotoDeclarationTargets);
        if(psiElements.size() == 0) {
            return;
        }

        NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.OVERRIDES).
            setTargets(psiElements).
            setTooltipText("Navigate to block");

        lineMarkerInfos.add(builder.createLineMarkerInfo(psiElement));

    }
 
Example #20
Source File: TextPainter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public TextPainter(DocumentEx editorDocument,
                   EditorHighlighter highlighter,
                   String fileName,
                   final Project project,
                   final FileType fileType, final List<LineMarkerInfo> separators) {
  myCodeStyleSettings = CodeStyleSettingsManager.getSettings(project);
  myDocument = editorDocument;
  myPrintSettings = PrintSettings.getInstance();
  String fontName = myPrintSettings.FONT_NAME;
  int fontSize = myPrintSettings.FONT_SIZE;
  myPlainFont = new Font(fontName, Font.PLAIN, fontSize);
  myBoldFont = new Font(fontName, Font.BOLD, fontSize);
  myItalicFont = new Font(fontName, Font.ITALIC, fontSize);
  myBoldItalicFont = new Font(fontName, Font.BOLD | Font.ITALIC, fontSize);
  myHighlighter = highlighter;
  myHeaderFont = new Font(myPrintSettings.FOOTER_HEADER_FONT_NAME, Font.PLAIN,
                          myPrintSettings.FOOTER_HEADER_FONT_SIZE);
  myFileName = fileName;
  mySegmentEnd = myDocument.getTextLength();
  myFileType = fileType;
  myMethodSeparators = separators != null ? separators.toArray(new LineMarkerInfo[separators.size()]) : new LineMarkerInfo[0];
  myCurrentMethodSeparator = 0;
}
 
Example #21
Source File: UnityEventCSharpMethodLineMarkerProvider.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
private static LineMarkerInfo createMarker(final PsiElement element)
{
	CSharpMethodDeclaration methodDeclaration = CSharpLineMarkerUtil.getNameIdentifierAs(element, CSharpMethodDeclaration.class);
	if(methodDeclaration != null)
	{
		Unity3dModuleExtension extension = ModuleUtilCore.getExtension(element, Unity3dModuleExtension.class);
		if(extension == null)
		{
			return null;
		}

		UnityFunctionManager.FunctionInfo magicMethod = findMagicMethod(methodDeclaration);
		if(magicMethod != null)
		{
			return new LineMarkerInfo<>(element, element.getTextRange(), Unity3dIcons.EventMethod, Pass.LINE_MARKERS, new ConstantFunction<>(magicMethod.getDescription()), null,
					GutterIconRenderer.Alignment.LEFT);
		}
	}

	return null;
}
 
Example #22
Source File: SmartyTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {

    if(psiElements.size() == 0 || !ShopwareProjectComponent.isValidForProject(psiElements.get(0))) {
        return;
    }

    Set<VirtualFile> extendsPathFiles = null;

    for(PsiElement psiElement: psiElements) {

        if(psiElement instanceof SmartyFile) {
            attachFileContextMaker((SmartyFile) psiElement, lineMarkerInfos);
        }

        if(SmartyPattern.getBlockPattern().accepts(psiElement)) {
            attachTemplateBlocks(psiElement, lineMarkerInfos);
        }

        if(SmartyPattern.getBlockPattern().accepts(psiElement)) {

            // cache template extends path
            if(extendsPathFiles == null) {
                extendsPathFiles = new HashSet<>();
                getImplementedBlocks(psiElement.getProject(), psiElement.getContainingFile().getVirtualFile(), extendsPathFiles, 10);
            }

            attachImplementsBlocks(psiElement, lineMarkerInfos, extendsPathFiles);
        }

    }

}
 
Example #23
Source File: ExtJsTemplateLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
private void attachDefineTargets(PsiElement psiElement, Collection<LineMarkerInfo> lineMarkerInfos, boolean attachController) {
    if(!ShopwareProjectComponent.isValidForProject(psiElement)) {
        return;
    }

    String text = PsiElementUtils.trimQuote(psiElement.getText());
    if(!text.startsWith("Shopware.apps.")) {
        return;
    }

    String[] namespaces = StringUtils.split(text, ".");
    if(namespaces.length < 3) {
        return;
    }

    List<PsiElement> psiElementList = new ArrayList<>();

    if(attachController) {
        attachController(psiElement.getProject(), namespaces, psiElementList);
    }

    attachModels(psiElement.getProject(), namespaces, psiElementList);

    if(psiElementList.size() == 0) {
        return;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(ShopwarePluginIcons.SHOPWARE_LINEMARKER).
        setTargets(psiElementList).
        setTooltipText("Navigate");

    lineMarkerInfos.add(builder.createLineMarkerInfo(psiElement));
}
 
Example #24
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public void assertLineMarkerIsEmpty(@NotNull PsiElement psiElement) {

        final List<PsiElement> elements = collectPsiElementsRecursive(psiElement);

        for (LineMarkerProvider lineMarkerProvider : LineMarkerProviders.getInstance().allForLanguage(psiElement.getLanguage())) {
            Collection<LineMarkerInfo> lineMarkerInfos = new ArrayList<LineMarkerInfo>();
            lineMarkerProvider.collectSlowLineMarkers(elements, lineMarkerInfos);

            if(lineMarkerInfos.size() > 0) {
                fail(String.format("Fail that line marker is empty because it matches '%s'", lineMarkerProvider.getClass()));
            }
        }
    }
 
Example #25
Source File: PhpLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
private void collectSubscriberTargets(@NotNull List<PsiElement> psiElements, final @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {
    Collection<PhpClass> phpClasses = new ArrayList<>();

    for (PsiElement psiElement : psiElements) {
        if(psiElement instanceof PhpClass && PhpElementsUtil.isInstanceOf((PhpClass) psiElement, "Enlight\\Event\\SubscriberInterface")) {
            phpClasses.add((PhpClass) psiElement);
        }
    }

    for (PhpClass phpClass : phpClasses) {
        Method getSubscribedEvents = phpClass.findOwnMethodByName("getSubscribedEvents");
        if(getSubscribedEvents == null) {
            continue;
        }

        Map<String, Pair<String, PsiElement>> methodEvent = new HashMap<>();

        HookSubscriberUtil.visitSubscriberEvents(getSubscribedEvents, (event, methodName, key) ->
            methodEvent.put(methodName, Pair.create(event, key))
        );

        for (Method method : phpClass.getOwnMethods()) {
            if(!methodEvent.containsKey(method.getName()) || !method.getAccess().isPublic()) {
                continue;
            }

            Pair<String, PsiElement> result = methodEvent.get(method.getName());
            NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(ShopwarePluginIcons.SHOPWARE_LINEMARKER).
                setTargets(new MyCollectionNotNullLazyValue(result.getSecond(), result.getFirst())).
                setTooltipText("Related Targets");

            // attach linemarker to leaf item which is our function name for performance reasons
            ASTNode node = method.getNode().findChildByType(PhpTokenTypes.IDENTIFIER);
            if(node != null) {
                lineMarkerInfos.add(builder.createLineMarkerInfo(node.getPsi()));
            }
        }
    }
}
 
Example #26
Source File: BeanInjectLineMarkerProviderTest.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@NotNull
private List<RelatedItemLineMarkerInfo<? extends PsiElement>> findBeanInjectMarkers() {
    List<GutterMark> gutters = myFixture.findAllGutters();
    return gutters.stream()
            .filter(g -> BeanInjectLineMarkerProvider.MARKER_TOOLTIP_TEXT.equals(g.getTooltipText()))
            .map(g -> (LineMarkerInfo.LineMarkerGutterIconRenderer<? extends PsiElement>) g)
            .map(LineMarkerInfo.LineMarkerGutterIconRenderer::getLineMarkerInfo)
            .map(info -> (RelatedItemLineMarkerInfo<? extends PsiElement>) info)
            .collect(Collectors.toList());
}
 
Example #27
Source File: ExpectedHighlightingData.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void extractExpectedLineMarkerSet(Document document) {
  String text = document.getText();

  @NonNls 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<PsiElement, String>(descr), null,
                                                               GutterIconRenderer.Alignment.RIGHT);

    lineMarkerInfos.put(document.createRangeMarker(startOffset, endOffset), markerInfo);
    text = document.getText();
  }
}
 
Example #28
Source File: PhpLineMarkerProvider.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, final @NotNull Collection<LineMarkerInfo> lineMarkerInfos) {
    if(psiElements.size() == 0 || !ShopwareProjectComponent.isValidForProject(psiElements.get(0))) {
        return;
    }

    PsiFile containingFile = psiElements.get(0).getContainingFile();
    if(containingFile.getName().contains("Bootstrap")) {
        collectBootstrapSubscriber(psiElements, lineMarkerInfos, containingFile);
        return;
    }

    // Enlight\Event\SubscriberInterface::getSubscribedEvents
    collectSubscriberTargets(psiElements, lineMarkerInfos);
}
 
Example #29
Source File: XmlCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testCamelGutter() {
    myFixture.configureByFiles("XmlCamelRouteLineMarkerProviderTestData.xml");
    List<GutterMark> gutters = myFixture.findAllGutters();
    assertNotNull(gutters);

    assertEquals("Does not contain the expected amount of Camel gutters", 3, gutters.size());

    Icon defaultIcon = ServiceManager.getService(CamelPreferenceService.class).getCamelIcon();
    gutters.forEach(gutterMark -> {
        assertSame("Gutter should have the Camel icon", defaultIcon, gutterMark.getIcon());
        assertEquals("Camel route", gutterMark.getTooltipText());
    });

    LineMarkerInfo.LineMarkerGutterIconRenderer firstGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(1);

    assertTrue(firstGutter.getLineMarkerInfo().getElement() instanceof XmlToken);
    assertEquals("The navigation start element doesn't match", "file:inbox",
            PsiTreeUtil.getParentOfType(firstGutter.getLineMarkerInfo().getElement(), XmlTag.class).getAttribute("uri").getValue());

    List<GotoRelatedItem> firstGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstGutter);
    assertEquals("Navigation should have one target", 1, firstGutterTargets.size());
    assertEquals("The navigation target route doesn't match", "file:inbox", firstGutterTargets.get(0).getElement().getText());
    assertEquals("The navigation target tag name doesn't match", "to",
            GutterTestUtil.getGuttersWithXMLTarget(firstGutterTargets).get(0).getLocalName());

    LineMarkerInfo.LineMarkerGutterIconRenderer secondGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) gutters.get(2);

    assertTrue(secondGutter.getLineMarkerInfo().getElement() instanceof XmlToken);
    assertEquals("The navigation start element doesn't match", "file:outbox",
            PsiTreeUtil.getParentOfType(secondGutter.getLineMarkerInfo().getElement(), XmlTag.class).getAttribute("uri").getValue());

    List<GotoRelatedItem> secondGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(secondGutter);
    assertEquals("Navigation should have one target", 1, secondGutterTargets.size());
    assertEquals("The navigation target route doesn't match", "file:outbox", secondGutterTargets.get(0).getElement().getText());
    assertEquals("The navigation target tag name doesn't match", "to",
            GutterTestUtil.getGuttersWithXMLTarget(secondGutterTargets).get(0).getLocalName());
}
 
Example #30
Source File: TwigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
private LineMarkerInfo attachBlockImplements(@NotNull PsiElement psiElement, @NotNull FileImplementsLazyLoader implementsLazyLoader) {
    if(!TwigBlockUtil.hasBlockImplementations(psiElement, implementsLazyLoader)) {
        return null;
    }

    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(PhpIcons.IMPLEMENTED)
        .setTargets(new BlockImplementationLazyValue(psiElement))
        .setTooltipText("Implementations")
        .setCellRenderer(new MyBlockListCellRenderer());

    return builder.createLineMarkerInfo(psiElement);
}