예제 #1
0
 public static void deleteStatementTail(PsiElement container, @NotNull PsiElement statement) {
   PsiElement next = statement.getNextSibling();
   while (next != null) {
     final ASTNode node = next.getNode();
     final IElementType type = node.getElementType();
     if (type == mSEMI) {
       final PsiElement nnext = next.getNextSibling();
       container.deleteChildRange(next, next);
       next = nnext;
     } else if (type == mNLS || type == TokenType.WHITE_SPACE && next.getText().contains("\n")) {
       final String text = next.getText();
       final int first = text.indexOf("\n");
       final int second = text.indexOf("\n", first + 1);
       if (second < 0) {
         container.deleteChildRange(next, next);
         return;
       }
       final String substring = text.substring(second);
       container
           .getNode()
           .replaceChild(
               node,
               createSingleLeafElement(
                   type, substring, 0, substring.length(), null, container.getManager()));
       return;
     } else {
       break;
     }
   }
 }
예제 #2
0
  @NotNull
  public static String getName(@NotNull GrNamedElement namedElement) {
    PsiElement nameElement = namedElement.getNameIdentifierGroovy();
    ASTNode node = nameElement.getNode();
    LOG.assertTrue(node != null);

    if (node.getElementType() == mIDENT) {
      return nameElement.getText();
    }

    if (node.getElementType() == mSTRING_LITERAL || node.getElementType() == mGSTRING_LITERAL) {
      final Object value = GrLiteralImpl.getLiteralValue(nameElement);
      if (value instanceof String) {
        return (String) value;
      } else {
        return GrStringUtil.removeQuotes(nameElement.getText());
      }
    }

    throw new IncorrectOperationException(
        "incorrect name element: " + node.getElementType() + ", named element: " + namedElement);
  }