Java Code Examples for com.intellij.psi.PsiExpressionList#getExpressions()

The following examples show how to use com.intellij.psi.PsiExpressionList#getExpressions() . 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: RequiredPropAnnotator.java    From litho with Apache License 2.0 5 votes vote down vote up
private static void handleMethodCall(
    PsiMethodCallExpression currentMethodCall,
    Set<String> methodNamesCalled,
    BiConsumer<Collection<String>, PsiReferenceExpression> errorHandler,
    Function<PsiMethodCallExpression, PsiClass> generatedClassResolver) {
  PsiReferenceExpression methodExpression = currentMethodCall.getMethodExpression();
  methodNamesCalled.add(methodExpression.getReferenceName());

  // Assumption to find next method in a call chain
  PsiMethodCallExpression nextMethodCall =
      PsiTreeUtil.getChildOfType(methodExpression, PsiMethodCallExpression.class);
  if (nextMethodCall != null) {
    handleMethodCall(nextMethodCall, methodNamesCalled, errorHandler, generatedClassResolver);
  } else if ("create".equals(methodExpression.getReferenceName())) {
    // Finish call chain
    // TODO T47712852: allow setting required prop in another statement
    Optional.ofNullable(generatedClassResolver.apply(currentMethodCall))
        .map(generatedCls -> collectMissingRequiredProps(generatedCls, methodNamesCalled))
        .filter(result -> !result.isEmpty())
        .ifPresent(
            missingRequiredProps -> errorHandler.accept(missingRequiredProps, methodExpression));
  }

  PsiExpressionList argumentList = currentMethodCall.getArgumentList();
  for (PsiExpression argument : argumentList.getExpressions()) {
    handleIfMethodCall(argument, errorHandler, generatedClassResolver);
  }
}
 
Example 2
Source File: CamelDocumentationProvider.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
    if (ServiceManager.getService(element.getProject(), CamelService.class).isCamelPresent()) {
        PsiExpressionList exps = PsiTreeUtil.getNextSiblingOfType(originalElement, PsiExpressionList.class);
        if (exps != null) {
            if (exps.getExpressions().length >= 1) {
                // grab first string parameter (as the string would contain the camel endpoint uri
                final PsiClassType stringType = PsiType.getJavaLangString(element.getManager(), element.getResolveScope());
                PsiExpression exp = Arrays.stream(exps.getExpressions()).filter(
                    e -> e.getType() != null && stringType.isAssignableFrom(e.getType()))
                    .findFirst().orElse(null);
                if (exp instanceof PsiLiteralExpression) {
                    Object o = ((PsiLiteralExpression) exp).getValue();
                    String val = o != null ? o.toString() : null;
                    // okay only allow this popup to work when its from a RouteBuilder class
                    PsiClass clazz = PsiTreeUtil.getParentOfType(originalElement, PsiClass.class);
                    if (clazz != null) {
                        PsiClassType[] types = clazz.getExtendsListTypes();
                        boolean found = Arrays.stream(types).anyMatch(p -> p.getClassName().equals("RouteBuilder"));
                        if (found) {
                            String componentName = asComponentName(val);
                            if (componentName != null) {
                                // the quick info cannot be so wide so wrap at 120 chars
                                return generateCamelComponentDocumentation(componentName, val, 120, element.getProject());
                            }
                        }
                    }
                }
            }
        }
    }

    return null;
}
 
Example 3
Source File: ExpressionListTranslator.java    From java2typescript with Apache License 2.0 5 votes vote down vote up
public static void translate(PsiExpressionList element, TranslationContext ctx) {
    PsiExpression[] arguments = element.getExpressions();
    for (int i = 0; i < arguments.length; i++) {
        ExpressionTranslator.translate(arguments[i], ctx);
        if (i != arguments.length - 1) {
            ctx.append(", ");
        }
    }
}