com.intellij.psi.PsiJavaToken Java Examples

The following examples show how to use com.intellij.psi.PsiJavaToken. 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: CamelJavaReferenceContributor.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public CamelJavaReferenceContributor() {
    addCompletionExtension(new BeanReferenceCompletionExtension());
    addCompletionExtension(new CamelEndpointNameCompletionExtension());
    addCompletionExtension(new CamelEndpointSmartCompletionExtension(false));
    extend(CompletionType.BASIC, psiElement().and(psiElement().inside(PsiFile.class).inFile(matchFileType("java"))),
            new EndpointCompletion(getCamelCompletionExtensions())
    );
    extend(CompletionType.BASIC, psiElement(PsiJavaToken.class).with(new PatternCondition<PsiJavaToken>("CamelJavaBeanReferenceSmartCompletion") {
        @Override
        public boolean accepts(@NotNull PsiJavaToken psiJavaToken, ProcessingContext processingContext) {
            return getCamelIdeaUtils().getBeanPsiElement(psiJavaToken) != null;
        }
    }), new CamelJavaBeanReferenceSmartCompletion());
}
 
Example #2
Source File: CamelAddEndpointIntention.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
    if (ServiceManager.getService(project, CamelService.class).isCamelPresent()) {
        // special for xml
        XmlTag xml = PsiTreeUtil.getParentOfType(element, XmlTag.class);
        if (xml != null) {
            // special check for poll enrich where we add the endpoint on a child node (camel expression)
            XmlTag parent = xml.getParentTag();
            if (parent != null && parent.getLocalName().equals("pollEnrich")) {
                return true;
            }
        }

        String text = null;

        // special for java token
        if (element instanceof PsiJavaToken) {
            // if its a string literal
            PsiJavaToken token = (PsiJavaToken) element;
            if (token.getTokenType() == JavaTokenType.STRING_LITERAL) {
                text = getIdeaUtils().getInnerText(token.getText());
            }
        } else {
            // should be a literal element and therefore dont fallback to generic
            text = getIdeaUtils().extractTextFromElement(element, false, false, true);
        }

        return text != null && text.trim().isEmpty();
    }

    return false;
}
 
Example #3
Source File: CamelRouteLineMarkerProvider.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Camel route from a PsiElement
 *
 * @param element the element
 * @return the String route or null if there nothing can be found
 */
private String findRouteFromElement(PsiElement element) {
    XmlTag xml = PsiTreeUtil.getParentOfType(element, XmlTag.class);
    if (xml != null) {
        return ((XmlTagImpl) element.getParent()).getAttributeValue("uri");
    }


    if (element instanceof PsiIdentifier) {
        PsiIdentifier id = (PsiIdentifier) element;
        String text = id.getText();
        if (text != null) {
            return text;
        }
    }

    if (element instanceof PsiJavaToken) {
        return element.getText();
    }

    // Only variables can be resolved?
    Optional<PsiVariable> variable = resolvedIdentifier(element)
        .filter(PsiVariable.class::isInstance)
        .map(PsiVariable.class::cast);
    if (variable.isPresent()) {
        // Try to resolve variable and recursive search route
        return variable.map(PsiVariable::getInitializer)
            .map(this::findRouteFromElement)
            .orElse(null);
    }

    return null;
}
 
Example #4
Source File: GutterTestUtil.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * For the given gutters return all the gutter navigation targets that are {@link PsiMethodCallExpressionImpl} elements.
 */
static List<PsiMethodCallExpression> getGuttersWithJavaTarget(List<GotoRelatedItem> gutterList) {
    return gutterList
        .stream()
        .filter(gotoRelatedItem -> gotoRelatedItem.getElement() instanceof PsiJavaToken)
        .map(gotoRelatedItem -> PsiTreeUtil.getParentOfType(gotoRelatedItem.getElement(), PsiMethodCallExpression.class))
        .collect(Collectors.toList());
}
 
Example #5
Source File: JavaCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testCamelGutter() {
    myFixture.configureByFiles("JavaCamelRouteLineMarkerProviderTestData.java");
    List<GutterMark> gutters = myFixture.findAllGutters();
    assertNotNull(gutters);

    //remove first element since it is navigate to super implementation gutter icon
    gutters.remove(0);

    assertEquals("Should contain 3 Camel gutters", 3, gutters.size());

    assertGuttersHasCamelIcon(gutters);

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

    assertTrue(firstGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:inbox\"",
        firstGutter.getLineMarkerInfo().getElement().getText());


    List<GotoRelatedItem> firstGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstGutter);
    assertEquals("Navigation should have one target", 1, firstGutterTargets.size());
    assertEquals("The navigation target element doesn't match", "from(\"file:outbox\")",
        GutterTestUtil.getGuttersWithJavaTarget(firstGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());


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

    assertTrue(secondGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:outbox\"",
        secondGutter.getLineMarkerInfo().getElement().getText());

    List<GotoRelatedItem> secondGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(secondGutter);
    assertEquals("Navigation should have one target", 1, secondGutterTargets.size());
    assertEquals("The navigation target element doesn't match", "from(\"file:inbox\")",
        GutterTestUtil.getGuttersWithJavaTarget(secondGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());
}
 
Example #6
Source File: JavaCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testCamelGutterForToDAndToF() {
    myFixture.configureByFiles("JavaCamelRouteLineMarkerProviderAlternateToTestData.java");
    List<GutterMark> gutters = myFixture.findAllGutters();
    assertNotNull(gutters);

    //remove first element since it is navigate to super implementation gutter icon
    gutters.remove(0);

    assertEquals("Should contain 2 Camel gutters", 2, gutters.size());

    assertGuttersHasCamelIcon(gutters);

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

    assertTrue(firstGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:test\"",
        firstGutter.getLineMarkerInfo().getElement().getText());


    List<GotoRelatedItem> firstGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstGutter);
    assertEquals("Navigation should have one target", 1, firstGutterTargets.size());
    assertEquals("The navigation target element doesn't match", "from(\"file:test\")",
        GutterTestUtil.getGuttersWithJavaTarget(firstGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());


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

    assertTrue(secondGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:test\"",
        secondGutter.getLineMarkerInfo().getElement().getText());

    List<GotoRelatedItem> secondGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(secondGutter);
    assertEquals("Navigation should have one target", 1, secondGutterTargets.size());
    assertEquals("The navigation target element doesn't match", "from(\"file:test\")",
        GutterTestUtil.getGuttersWithJavaTarget(secondGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());
}
 
Example #7
Source File: MultiLanguageCamelRouteLineMarkerProviderTestIT.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
public void testCamelGutterForJavaAndXMLRoutes() {
    myFixture.configureByFiles("XmlCamelRouteLineMarkerProviderTestData.xml", "JavaCamelRouteLineMarkerProviderTestData.java");
    List<GutterMark> javaGutters = myFixture.findAllGutters("JavaCamelRouteLineMarkerProviderTestData.java");
    assertNotNull(javaGutters);

    List<GutterMark> xmlGutters = myFixture.findAllGutters("XmlCamelRouteLineMarkerProviderTestData.xml");
    assertNotNull(xmlGutters);

    //remove first element since it is navigate to super implementation gutter icon
    javaGutters.remove(0);

    assertEquals("Should contain 3 Java Camel gutters", 3, javaGutters.size());
    assertEquals("Should contain 2 XML Camel gutters", 3, xmlGutters.size());

    //from Java to XML
    LineMarkerInfo.LineMarkerGutterIconRenderer firstJavaGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) javaGutters.get(1);
    assertTrue(firstJavaGutter.getLineMarkerInfo().getElement() instanceof PsiJavaToken);
    assertEquals("The navigation start element doesn't match", "\"file:inbox\"",
        firstJavaGutter.getLineMarkerInfo().getElement().getText());


    List<GotoRelatedItem> firstJavaGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstJavaGutter);
    assertEquals("Navigation should have two targets", 2, firstJavaGutterTargets.size());
    assertEquals("The navigation target XML tag name doesn't match", "to", getGuttersWithXMLTarget(firstJavaGutterTargets).get(0).getLocalName());
    assertEquals("The navigation Java target element doesn't match", "from(\"file:outbox\")",
            getGuttersWithJavaTarget(firstJavaGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());

    //from XML to Java
    LineMarkerInfo.LineMarkerGutterIconRenderer firstXmlGutter = (LineMarkerInfo.LineMarkerGutterIconRenderer) xmlGutters.get(1);
    assertTrue(firstXmlGutter.getLineMarkerInfo().getElement() instanceof XmlToken);
    assertEquals("The navigation start element doesn't match", "\"file:inbox\"",
            (firstJavaGutter.getLineMarkerInfo().getElement()).getText());


    List<GotoRelatedItem> firstXmlGutterTargets = GutterTestUtil.getGutterNavigationDestinationElements(firstXmlGutter);
    assertEquals("Navigation should have two targets", 2, firstXmlGutterTargets.size());
    assertEquals("The navigation target XML tag name doesn't match", "to", getGuttersWithXMLTarget(firstXmlGutterTargets).get(0).getLocalName());
    assertEquals("The navigation Java target element doesn't match", "from(\"file:outbox\")",
            getGuttersWithJavaTarget(firstXmlGutterTargets).get(0).getMethodExpression().getQualifierExpression().getText());
}
 
Example #8
Source File: PolyadicExpressionTranslator.java    From java2typescript with Apache License 2.0 5 votes vote down vote up
public static void translate(PsiPolyadicExpression element, TranslationContext ctx) {
    for (PsiExpression expression : element.getOperands()) {
        PsiJavaToken token = element.getTokenBeforeOperand(expression);
        if (token != null) {
            ctx.append(' ');
            JavaTokenTranslator.translate(token, ctx);
            ctx.append(' ');
        }
        ExpressionTranslator.translate(expression, ctx);
    }
}
 
Example #9
Source File: CamelRouteLineMarkerProvider.java    From camel-idea-plugin with Apache License 2.0 4 votes vote down vote up
private boolean isJavaTokenLiteralExpression(@NotNull PsiElement element) {
    return element instanceof PsiJavaToken && (element.getParent() instanceof PsiLiteralExpression);
}
 
Example #10
Source File: JavaTokenTranslator.java    From java2typescript with Apache License 2.0 4 votes vote down vote up
public static void translate(PsiJavaToken element, TranslationContext ctx) {
  if (ElementType.OPERATION_BIT_SET.contains(element.getTokenType())) {
    ctx.append(element.getText());
  }
}
 
Example #11
Source File: HaxeBlockStatementPsiMixinImpl.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public PsiJavaToken getLBrace() {
  // TODO: Implement
  return null;
}
 
Example #12
Source File: HaxeBlockStatementPsiMixinImpl.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public PsiJavaToken getRBrace() {
  // TODO: Implement
  return null;
}