@Test public void createMethodChain() { testHelper.runInReadAction( project -> { List<String> names = new ArrayList<>(2); names.add("methodName1"); names.add("otherName"); PsiExpression methodChain = MethodChainLookupElement.createMethodChain(project, "methodNameBase", names); assertEquals( "methodNameBase(insert_placeholder_c)\n" + ".methodName1(insert_placeholder)\n" + ".otherName(insert_placeholder)", methodChain.getText()); }); }
@VisibleForTesting static PsiExpression createMethodChain( Project project, String firstName, List<? extends String> methodNames) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); StringBuilder expressionText = new StringBuilder(firstName + "(" + TEMPLATE_INSERT_PLACEHOLDER_C + ")"); methodNames.forEach( methodName -> expressionText .append("\n.") .append(methodName) .append("(") .append(TEMPLATE_INSERT_PLACEHOLDER) .append(")")); return factory.createExpressionFromText(expressionText.toString(), null); }
MethodChainLookupElement extends LookupElementDecorator<LookupElement> { @VisibleForTesting static PsiExpression createMethodChain( Project project, String firstName, List<? extends String> methodNames) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); StringBuilder expressionText = new StringBuilder(firstName + "(" + TEMPLATE_INSERT_PLACEHOLDER_C + ")"); methodNames.forEach( methodName -> expressionText .append("\n.") .append(methodName) .append("(") .append(TEMPLATE_INSERT_PLACEHOLDER) .append(")")); return factory.createExpressionFromText(expressionText.toString(), null); } }
MethodChainLookupElement extends LookupElementDecorator<LookupElement> { @VisibleForTesting static PsiExpression createMethodChain( Project project, String firstName, List<? extends String> methodNames) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); StringBuilder expressionText = new StringBuilder(firstName + "(" + TEMPLATE_INSERT_PLACEHOLDER_C + ")"); methodNames.forEach( methodName -> expressionText .append("\n.") .append(methodName) .append("(") .append(TEMPLATE_INSERT_PLACEHOLDER) .append(")")); return factory.createExpressionFromText(expressionText.toString(), null); } @VisibleForTesting  MethodChainLookupElement(LookupElement delegate, Template fromTemplate); }
MethodChainLookupElement extends LookupElementDecorator<LookupElement> { @VisibleForTesting static PsiExpression createMethodChain( Project project, String firstName, List<? extends String> methodNames) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); StringBuilder expressionText = new StringBuilder(firstName + "(" + TEMPLATE_INSERT_PLACEHOLDER_C + ")"); methodNames.forEach( methodName -> expressionText .append("\n.") .append(methodName) .append("(") .append(TEMPLATE_INSERT_PLACEHOLDER) .append(")")); return factory.createExpressionFromText(expressionText.toString(), null); } @VisibleForTesting  MethodChainLookupElement(LookupElement delegate, Template fromTemplate); static LookupElement create(
      LookupElement lookupPresentation,
      String firstMethodName,
      List<? extends String> otherMethodNames,
      PsiElement placeholder,
      Project project); @Override void handleInsert(InsertionContext context); @Override void renderElement(LookupElementPresentation presentation); }
MethodChainLookupElement extends LookupElementDecorator<LookupElement> { @VisibleForTesting static PsiExpression createMethodChain( Project project, String firstName, List<? extends String> methodNames) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); StringBuilder expressionText = new StringBuilder(firstName + "(" + TEMPLATE_INSERT_PLACEHOLDER_C + ")"); methodNames.forEach( methodName -> expressionText .append("\n.") .append(methodName) .append("(") .append(TEMPLATE_INSERT_PLACEHOLDER) .append(")")); return factory.createExpressionFromText(expressionText.toString(), null); } @VisibleForTesting  MethodChainLookupElement(LookupElement delegate, Template fromTemplate); static LookupElement create(
      LookupElement lookupPresentation,
      String firstMethodName,
      List<? extends String> otherMethodNames,
      PsiElement placeholder,
      Project project); @Override void handleInsert(InsertionContext context); @Override void renderElement(LookupElementPresentation presentation);  }