@Override
  public String getIncludeText() {
    final JSIncludeDirectiveStub stub = getStub();
    if (stub != null) {
      return stub.getIncludeText();
    }
    final ASTNode astNode = getIncludedFileNode();

    return astNode != null ? StringUtil.stripQuotesAroundValue(astNode.getText()) : null;
  }
  @Override
  @NotNull
  public PsiReference[] getReferences() {
    ASTNode node = getIncludedFileNode();

    if (node != null) {
      return new FileReferenceSet(
              StringUtil.stripQuotesAroundValue(node.getText()),
              this,
              node.getPsi().getStartOffsetInParent() + 1,
              null,
              SystemInfo.isFileSystemCaseSensitive)
          .getAllReferences();
    }
    return PsiReference.EMPTY_ARRAY;
  }
    protected void applyFix(
        final Project project,
        final PsiElement psiElement,
        final PsiFile file,
        final Editor editor) {
      final ASTNode oldValueNode = ((JSAttributeNameValuePair) psiElement).getValueNode();
      final String oldText = oldValueNode.getText();
      char quoteChar = oldText.length() > 0 ? oldText.charAt(0) : '"';
      if (quoteChar != '\'' && quoteChar != '"') {
        quoteChar = '"';
      }

      final String newText =
          quoteChar + "/" + StringUtil.stripQuotesAroundValue(oldText) + quoteChar;
      final ASTNode newNode = JSChangeUtil.createExpressionFromText(project, newText);
      psiElement.getNode().replaceChild(oldValueNode, newNode.getFirstChildNode());
    }
Пример #4
0
  private NamesByExprInfo suggestVariableNameByExpressionOnly(
      PsiExpression expr,
      final VariableKind variableKind,
      boolean correctKeywords,
      boolean useAllMethodNames) {
    if (expr instanceof PsiMethodCallExpression) {
      PsiReferenceExpression methodExpr = ((PsiMethodCallExpression) expr).getMethodExpression();
      String methodName = methodExpr.getReferenceName();
      if (methodName != null) {
        if ("of".equals(methodName) || "ofNullable".equals(methodName)) {
          if (isJavaUtilMethodCall((PsiMethodCallExpression) expr)) {
            PsiExpression[] expressions =
                ((PsiMethodCallExpression) expr).getArgumentList().getExpressions();
            if (expressions.length > 0) {
              return suggestVariableNameByExpressionOnly(
                  expressions[0], variableKind, correctKeywords, useAllMethodNames);
            }
          }
        }
        if ("map".equals(methodName)
            || "flatMap".equals(methodName)
            || "filter".equals(methodName)) {
          if (isJavaUtilMethodCall((PsiMethodCallExpression) expr)) {
            return new NamesByExprInfo(null);
          }
        }

        String[] words = NameUtil.nameToWords(methodName);
        if (words.length > 0) {
          final String firstWord = words[0];
          if (GET_PREFIX.equals(firstWord)
              || IS_PREFIX.equals(firstWord)
              || FIND_PREFIX.equals(firstWord)
              || CREATE_PREFIX.equals(firstWord)) {
            if (words.length > 1) {
              final String propertyName = methodName.substring(firstWord.length());
              String[] names =
                  getSuggestionsByName(propertyName, variableKind, false, correctKeywords);
              final PsiExpression qualifierExpression = methodExpr.getQualifierExpression();
              if (qualifierExpression instanceof PsiReferenceExpression
                  && ((PsiReferenceExpression) qualifierExpression).resolve()
                      instanceof PsiVariable) {
                names =
                    ArrayUtil.append(
                        names,
                        StringUtil.sanitizeJavaIdentifier(
                            changeIfNotIdentifier(
                                qualifierExpression.getText()
                                    + StringUtil.capitalize(propertyName))));
              }
              return new NamesByExprInfo(propertyName, names);
            }
          } else if (words.length == 1 || useAllMethodNames) {
            return new NamesByExprInfo(
                methodName, getSuggestionsByName(methodName, variableKind, false, correctKeywords));
          }
        }
      }
    } else if (expr instanceof PsiReferenceExpression) {
      String propertyName = ((PsiReferenceExpression) expr).getReferenceName();
      PsiElement refElement = ((PsiReferenceExpression) expr).resolve();
      if (refElement instanceof PsiVariable) {
        VariableKind refVariableKind = getVariableKind((PsiVariable) refElement);
        propertyName = variableNameToPropertyName(propertyName, refVariableKind);
      }
      if (refElement != null && propertyName != null) {
        String[] names = getSuggestionsByName(propertyName, variableKind, false, correctKeywords);
        return new NamesByExprInfo(propertyName, names);
      }
    } else if (expr instanceof PsiArrayAccessExpression) {
      PsiExpression arrayExpr = ((PsiArrayAccessExpression) expr).getArrayExpression();
      if (arrayExpr instanceof PsiReferenceExpression) {
        String arrayName = ((PsiReferenceExpression) arrayExpr).getReferenceName();
        PsiElement refElement = ((PsiReferenceExpression) arrayExpr).resolve();
        if (refElement instanceof PsiVariable) {
          VariableKind refVariableKind = getVariableKind((PsiVariable) refElement);
          arrayName = variableNameToPropertyName(arrayName, refVariableKind);
        }

        if (arrayName != null) {
          String name = StringUtil.unpluralize(arrayName);
          if (name != null) {
            String[] names = getSuggestionsByName(name, variableKind, false, correctKeywords);
            return new NamesByExprInfo(name, names);
          }
        }
      }
    } else if (expr instanceof PsiLiteralExpression
        && variableKind == VariableKind.STATIC_FINAL_FIELD) {
      final PsiLiteralExpression literalExpression = (PsiLiteralExpression) expr;
      final Object value = literalExpression.getValue();
      if (value instanceof String) {
        final String stringValue = (String) value;
        String[] names = getSuggestionsByValue(stringValue);
        if (names.length > 0) {
          return new NamesByExprInfo(null, constantValueToConstantName(names));
        }
      }
    } else if (expr instanceof PsiParenthesizedExpression) {
      return suggestVariableNameByExpressionOnly(
          ((PsiParenthesizedExpression) expr).getExpression(),
          variableKind,
          correctKeywords,
          useAllMethodNames);
    } else if (expr instanceof PsiTypeCastExpression) {
      return suggestVariableNameByExpressionOnly(
          ((PsiTypeCastExpression) expr).getOperand(),
          variableKind,
          correctKeywords,
          useAllMethodNames);
    } else if (expr instanceof PsiLiteralExpression) {
      final String text = StringUtil.stripQuotesAroundValue(expr.getText());
      if (isIdentifier(text)) {
        return new NamesByExprInfo(
            text, getSuggestionsByName(text, variableKind, false, correctKeywords));
      }
    }

    return new NamesByExprInfo(null, ArrayUtil.EMPTY_STRING_ARRAY);
  }
Пример #5
0
 private static String getSqlRefKey(PsiElement element) {
   if (element.getText().contains("1.0") || element.getText().contains("UTF-8")) {
     return null;
   }
   return StringUtil.stripQuotesAroundValue(element.getText());
 }