@Nullable
 private String evaluate(PsiExpression expression, Map<String, Computable<String>> arguments) {
   if (expression instanceof PsiPolyadicExpression) {
     PsiPolyadicExpression binaryExpression = (PsiPolyadicExpression) expression;
     if (binaryExpression.getOperationTokenType() == JavaTokenType.PLUS) {
       String r = "";
       for (PsiExpression op : binaryExpression.getOperands()) {
         String lhs = evaluate(op, arguments);
         if (lhs == null) return null;
         r += lhs;
       }
       return r;
     }
   } else if (expression instanceof PsiLiteralExpression) {
     final Object value = ((PsiLiteralExpression) expression).getValue();
     if (value instanceof String) {
       return (String) value;
     }
   } else if (expression instanceof PsiReferenceExpression) {
     final PsiElement result = ((PsiReferenceExpression) expression).resolve();
     if (result instanceof PsiParameter) {
       final String name = ((PsiParameter) result).getName();
       final Computable<String> arg = arguments.get(name);
       return arg == null ? null : arg.compute();
     }
     if (result instanceof PsiVariable) {
       final PsiExpression initializer = ((PsiVariable) result).getInitializer();
       if (initializer != null) {
         return evaluate(initializer, arguments);
       }
     }
   } else if (expression instanceof PsiMethodCallExpression) {
     final PsiMethodCallExpression methodCall = (PsiMethodCallExpression) expression;
     final String callText = methodCall.getMethodExpression().getText();
     if (callText.equals("getTestName")) {
       final PsiExpression[] psiExpressions = methodCall.getArgumentList().getExpressions();
       if (psiExpressions.length == 1) {
         if ("true".equals(psiExpressions[0].getText()) && !StringUtil.isEmpty(myTestName)) {
           return UsefulTestCase.lowercaseFirstLetter(myTestName, true);
         }
         return myTestName;
       }
     }
   }
   if (expression != null) {
     myLogMessages.add("Failed to evaluate " + expression.getText());
   }
   return null;
 }
예제 #2
0
  @NotNull
  public List<String> createConversions(
      @NotNull PsiPolyadicExpression expression, PsiType expectedType) {
    PsiExpression[] arguments = expression.getOperands();
    int length = arguments.length;
    List<String> conversions = new LinkedList<String>();

    List<PsiType> expectedTypes = Collections.nCopies(length, expectedType);
    List<PsiType> actualTypes = new LinkedList<PsiType>();

    for (PsiExpression e : arguments) actualTypes.add(e.getType());

    assert actualTypes.size() == expectedTypes.size() : "The type list must have the same length";

    for (int i = 0; i < actualTypes.size(); i++)
      conversions.add(i, createConversionForExpression(arguments[i], expectedTypes.get(i)));

    return conversions;
  }