com.intellij.util.ConstantFunction Java Examples

The following examples show how to use com.intellij.util.ConstantFunction. 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: TemplateLineMarker.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
@NotNull
private LineMarkerInfo getRelatedPopover(@NotNull String singleItemTitle, @NotNull String singleItemTooltipPrefix, @NotNull PsiElement lineMarkerTarget, @NotNull Collection<GotoRelatedItem> gotoRelatedItems, @NotNull Icon icon) {
    // single item has no popup
    String title = singleItemTitle;
    if(gotoRelatedItems.size() == 1) {
        String customName = gotoRelatedItems.iterator().next().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 #2
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 #3
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 #4
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 #5
Source File: NavigationGutterIconBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public RelatedItemLineMarkerInfo<PsiElement> createLineMarkerInfo(@Nonnull PsiElement element) {
  final MyNavigationGutterIconRenderer renderer = createGutterIconRenderer(element.getProject());
  final String tooltip = renderer.getTooltipText();
  NotNullLazyValue<Collection<? extends GotoRelatedItem>> gotoTargets = new NotNullLazyValue<Collection<? extends GotoRelatedItem>>() {
    @Nonnull
    @Override
    protected Collection<? extends GotoRelatedItem> compute() {
      if (myGotoRelatedItemProvider != null) {
        return ContainerUtil.concat(myTargets.getValue(), myGotoRelatedItemProvider);
      }
      return Collections.emptyList();
    }
  };
  return new RelatedItemLineMarkerInfo<PsiElement>(element, element.getTextRange(), renderer.getIcon(), Pass.LINE_MARKERS,
                                                   tooltip == null ? null : new ConstantFunction<PsiElement, String>(tooltip),
                                                   renderer.isNavigateAction() ? renderer : null, renderer.getAlignment(),
                                                   gotoTargets);
}
 
Example #6
Source File: UnityScriptEventFunctionLineMarkerProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@Nonnull PsiElement element)
{
	if(element.getNode().getElementType() == JSTokenTypes.IDENTIFIER && element.getParent() instanceof JSReferenceExpression && element.getParent().getParent() instanceof JSFunction)
	{
		UnityFunctionManager functionManager = UnityFunctionManager.getInstance();
		Map<String, UnityFunctionManager.FunctionInfo> map = functionManager.getFunctionsByType().get(Unity3dTypes.UnityEngine.MonoBehaviour);
		if(map == null)
		{
			return null;
		}
		UnityFunctionManager.FunctionInfo functionInfo = map.get(element.getText());
		if(functionInfo == null)
		{
			return null;
		}
		Unity3dModuleExtension extension = ModuleUtilCore.getExtension(element, Unity3dModuleExtension.class);
		if(extension == null)
		{
			return null;
		}
		JSFunction jsFunction = (JSFunction) element.getParent().getParent();
		if(jsFunction.getParent() instanceof JSFile)
		{
			if(!isEqualParameters(functionInfo.getParameters(), jsFunction))
			{
				return null;
			}

			return new LineMarkerInfo<>(element, element.getTextRange(), Unity3dIcons.EventMethod, Pass.LINE_MARKERS, new ConstantFunction<>(functionInfo.getDescription()), null,
					GutterIconRenderer.Alignment.LEFT);
		}
	}
	return null;
}
 
Example #7
Source File: FragmentRelatedFileLineMarker.java    From idea-android-studio-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {

    for(PsiElement psiElement : elements) {

        List<GotoRelatedItem> gotoRelatedItems = new ArrayList<GotoRelatedItem>();
        List<PsiFile> psiFiles = new ArrayList<PsiFile>();

        // android studio provide line marker with xml targets only on root classes not on class inside classes like fragments
        // we support all of them :)
        if(psiElement instanceof PsiIdentifier && psiElement.getParent() instanceof PsiClass && !(psiElement.getParent().getParent() instanceof PsiFile)) {

            // simple hack activity provide this on core
            if(isFragmentClass((PsiClass) psiElement.getParent())) {
                Collection<PsiMethodCallExpression> PsiMethodCallExpressions = PsiTreeUtil.collectElementsOfType(psiElement.getParent(), PsiMethodCallExpression.class);
                for(PsiMethodCallExpression methodCallExpression: PsiMethodCallExpressions) {
                    PsiMethod psiMethod = methodCallExpression.resolveMethod();
                    if(psiMethod != null && psiMethod.getName().equals("inflate")) {
                        PsiExpression[] expressions = methodCallExpression.getArgumentList().getExpressions();
                        if(expressions.length > 0 && expressions[0] instanceof PsiReferenceExpression) {
                            PsiFile xmlFile = AndroidUtils.findXmlResource((PsiReferenceExpression) expressions[0]);
                            if(xmlFile != null && !psiFiles.contains(xmlFile)) {
                                psiFiles.add(xmlFile);
                                gotoRelatedItems.add(new GotoRelatedItem(xmlFile));
                            }
                        }
                    }
                }
            }

        }

        if(gotoRelatedItems.size() > 0) {
            result.add(new LineMarkerInfo<PsiElement>(psiElement, psiElement.getTextOffset(), AndroidIcons.AndroidToolWindow, 6, new ConstantFunction<PsiElement, String>("Related Files"), new RelatedPopupGotoLineMarker.NavigationHandler(gotoRelatedItems)));
        }

    }

}
 
Example #8
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 #9
Source File: LambdaLineMarkerCollector.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Function<? super PsiElement, String> getCommonTooltip(@Nonnull List<MergeableLineMarkerInfo> infos)
{
	return new ConstantFunction<>("Navigate to lambda delegate");
}
 
Example #10
Source File: LambdaLineMarkerCollector.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
public void collect(PsiElement psiElement, @Nonnull Consumer<LineMarkerInfo> lineMarkerInfos)
{
	IElementType elementType = PsiUtilCore.getElementType(psiElement);
	if(elementType == CSharpTokens.DARROW)
	{
		PsiElement parent = psiElement.getParent();
		if(!(parent instanceof CSharpLambdaExpressionImpl))
		{
			return;
		}

		MarkerInfo markerInfo = new MarkerInfo(parent, psiElement.getTextRange(), AllIcons.Gutter.ImplementingFunctional, Pass.UPDATE_ALL, new ConstantFunction<>("Navigate to lambda delegate"),
				new GutterIconNavigationHandler<PsiElement>()
		{
			@Override
			@RequiredUIAccess
			public void navigate(MouseEvent e, PsiElement elt)
			{
				if(!(elt instanceof CSharpLambdaExpressionImpl))
				{
					return;
				}
				CSharpLambdaResolveResult lambdaResolveResult = CSharpLambdaExpressionImplUtil.resolveLeftLambdaTypeRef(elt);
				if(lambdaResolveResult == null)
				{
					return;
				}

				PsiElement element = lambdaResolveResult.getElement();
				if(element instanceof Navigatable)
				{
					((Navigatable) element).navigate(true);
				}
			}
		}, GutterIconRenderer.Alignment.RIGHT);
		NavigateAction.setNavigateAction(markerInfo, "Navigate to lambda delegate", IdeActions.ACTION_GOTO_SUPER);
		lineMarkerInfos.consume(markerInfo);
	}
}
 
Example #11
Source File: HidingOrOverridingElementCollector.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
public void collect(PsiElement psiElement, @Nonnull Consumer<LineMarkerInfo> consumer)
{
	DotNetVirtualImplementOwner virtualImplementOwner = CSharpLineMarkerUtil.findElementForLineMarker(psiElement);
	if(virtualImplementOwner != null)
	{
		PsiElement parentParent = virtualImplementOwner.getParent();
		if(!(parentParent instanceof DotNetTypeDeclaration))
		{
			return;
		}

		Collection<DotNetVirtualImplementOwner> overrideElements = OverrideUtil.collectOverridingMembers(virtualImplementOwner);

		if(overrideElements.isEmpty())
		{
			return;
		}

		Image icon = null;
		if(virtualImplementOwner.getTypeForImplement() != null)
		{
			icon = CSharpIcons.Gutter.HidingMethod;
		}
		else
		{
			icon = AllIcons.Gutter.ImplementingMethod;
			for(DotNetVirtualImplementOwner overrideElement : overrideElements)
			{
				if(!((DotNetModifierListOwner) overrideElement).hasModifier(DotNetModifier.ABSTRACT))
				{
					icon = AllIcons.Gutter.OverridingMethod;
					break;
				}
			}
		}

		LineMarkerInfo<PsiElement> lineMarkerInfo = new LineMarkerInfo<>(psiElement, psiElement.getTextRange(), icon, Pass.LINE_MARKERS, new ConstantFunction<>("Searching for overriding"),
				OurHandler.INSTANCE, GutterIconRenderer.Alignment.RIGHT);

		consumer.consume(lineMarkerInfo);
	}
}
 
Example #12
Source File: ControllerMethodLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Nullable
public LineMarkerInfo collect(PsiElement psiElement) {
    if(!Symfony2ProjectComponent.isEnabled(psiElement) || psiElement.getNode().getElementType() != PhpTokenTypes.IDENTIFIER) {
        return null;
    }

    PsiElement method = psiElement.getParent();
    if(!(method instanceof Method) || !((Method) method).getAccess().isPublic()) {
        return null;
    }

    List<GotoRelatedItem> gotoRelatedItems = getGotoRelatedItems((Method) method);

    if(gotoRelatedItems.size() == 0) {
        return null;
    }

    // only one item dont need popover
    if(gotoRelatedItems.size() == 1) {

        GotoRelatedItem gotoRelatedItem = gotoRelatedItems.get(0);

        // hell: find any possible small icon
        Icon icon = null;
        if(gotoRelatedItem instanceof RelatedPopupGotoLineMarker.PopupGotoRelatedItem) {
            icon = ((RelatedPopupGotoLineMarker.PopupGotoRelatedItem) gotoRelatedItem).getSmallIcon();
        }

        if(icon == null) {
           icon = Symfony2Icons.SYMFONY_LINE_MARKER;
        }

        NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(icon).
            setTargets(gotoRelatedItems.get(0).getElement());

        String customName = gotoRelatedItems.get(0).getCustomName();
        if(customName != null) {
            builder.setTooltipText(customName);
        }

        return builder.createLineMarkerInfo(psiElement);
    }

    return new LineMarkerInfo<>(
        psiElement,
        psiElement.getTextRange(),
        Symfony2Icons.SYMFONY_LINE_MARKER,
        6,
        new ConstantFunction<>("Related Files"),
        new RelatedPopupGotoLineMarker.NavigationHandler(gotoRelatedItems),
        GutterIconRenderer.Alignment.RIGHT
    );
}