Java 类com.intellij.psi.PsiWhiteSpace 实例源码

项目:yii2support    文件:PsiUtil.java   
public static void deleteFunctionParam(PsiElement element) {
    PsiElement next = element.getNextSibling();
    if (next != null && next.getText().equals(",")) {
        next.delete();
    } else {
        PsiElement prev = element.getPrevSibling();
        if (prev != null && prev instanceof PsiWhiteSpace) {
            prev.delete();
            prev = element.getPrevSibling();
        }
        if (prev != null && prev.getText().equals(",")) {
            prev.delete();
        }
    }
    element.delete();
}
项目:yii2inspections    文件:UnusedTranslationsInspector.java   
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement expression = descriptor.getPsiElement();
    if (expression instanceof ArrayHashElement) {
        PsiElement next = expression.getNextSibling();
        if (next instanceof PsiWhiteSpace) {
            next.delete();
        }
        next = expression.getNextSibling();
        if (null != next && PhpTokenTypes.opCOMMA == next.getNode().getElementType()) {
            next.delete();
        }
        next = expression.getNextSibling();
        if (next instanceof PsiWhiteSpace) {
            next.delete();
        }

        expression.delete();
    }
}
项目:hybris-integration-intellij-idea-plugin    文件:ValidateContextImpl.java   
@Nullable
private static PsiElement findByLineAndColumn(
    @NotNull final PsiElement file,
    @Nullable final Point columnAndLine
) {
    if (columnAndLine == null) {
        return file;
    }
    final int line = columnAndLine.y - 1;
    final int column = columnAndLine.x - 1;

    PsiElement leaf = findByLineAndColumn(file, line, column);

    if (leaf instanceof PsiWhiteSpace) {
        leaf = PsiTreeUtil.prevVisibleLeaf(leaf);
    }

    final PsiElement tag = leaf instanceof XmlTag ? leaf : PsiTreeUtil.getParentOfType(leaf, XmlTag.class);
    return tag == null ? leaf : tag;
}
项目:hybris-integration-intellij-idea-plugin    文件:ImpexPsiUtils.java   
@Nullable
@Contract(pure = true)
public static boolean prevElementIsUserRightsMacros(@NotNull final PsiElement element) {
    Validate.notNull(element);

    final Class[] skipClasses = {ImpexValueLine.class, PsiComment.class, PsiWhiteSpace.class};
    PsiElement prevElement = PsiTreeUtil.skipSiblingsBackward(element, skipClasses);

    while (null != prevElement) {
        if (isHeaderLine(prevElement)) {
            return false;
        }
        if (isUserRightsMacros(prevElement)) {
            return true;
        }
        prevElement = PsiTreeUtil.skipSiblingsBackward(prevElement, skipClasses);
    }

    return false;
}
项目:MultiHighlight    文件:MultiHighlightHandler.java   
/**
     * {@link com.intellij.codeInsight.highlighting.HighlightUsagesHandler#handleNoUsageTargets(PsiFile,
     * Editor, SelectionModel, Project)}
     */
    private static void handleNoUsageTargets(PsiFile file, @NotNull Editor editor,
            @NotNull Project project) {
        if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) {
            return;
        }
        final SelectionModel selectionModel = editor.getSelectionModel();
        selectionModel.selectWordAtCaret(false);
        String selection = selectionModel.getSelectedText();
//        LOG.assertTrue(selection != null);
        if (selection != null) {
            for (int i = 0; i < selection.length(); i++) {
                if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
                    selectionModel.removeSelection();
                }
            }

            searchSelection(editor, project);
            selectionModel.removeSelection();
        }
    }
项目:lua-for-idea    文件:LuaParameterInfoHandler.java   
public static LuaPsiElement findCall(PsiFile file, int offset) {
    PsiElement func;
    int delta = 0;

    try {
        do {
            func = file.findElementAt(offset - delta++);
        } while (func instanceof PsiWhiteSpace);

        // System.out.println("Element at pos:" + func);

        do {
            if (func instanceof LuaFunctionCallExpression)
                return (LuaPsiElement) func;

            func = func.getContext();
        } while (func != null);

    } catch (Throwable ignored) {
    }

    return null;
}
项目:lua-for-idea    文件:LuaDocCommentImpl.java   
@NotNull
public PsiElement[] getDescriptionElements() {
  ArrayList<PsiElement> array = new ArrayList<PsiElement>();
  for (PsiElement child = getFirstChild(); child != null; child = child.getNextSibling()) {

    if (child instanceof PsiWhiteSpace)
        continue;
    final ASTNode node = child.getNode();
    if (node == null) continue;
    final IElementType i = node.getElementType();
    if (i == LDOC_TAG) break;
    if (i == LDOC_COMMENT_DATA ) {
      array.add(child);
    }
  }
  return LuaPsiUtils.toPsiElementArray(array);
}
项目:yii2inspections    文件:UnusedTranslationsInspector.java   
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement expression = descriptor.getPsiElement();
    if (expression instanceof ArrayHashElement) {
        PsiElement next = expression.getNextSibling();
        if (next instanceof PsiWhiteSpace) {
            next.delete();
        }
        next = expression.getNextSibling();
        if (null != next && PhpTokenTypes.opCOMMA == next.getNode().getElementType()) {
            next.delete();
        }
        next = expression.getNextSibling();
        if (next instanceof PsiWhiteSpace) {
            next.delete();
        }

        expression.delete();
    }
}
项目:MissingInActions    文件:EditHelpers.java   
@NotNull
public static ItemTextRange<Language> getLanguageRangeAtOffset(@NotNull PsiFile file, int offset) {
    final PsiElement elt = file.findElementAt(offset);
    if (elt == null) return new ItemTextRange<Language>(file.getLanguage(), 0, file.getTextLength());
    if (elt instanceof PsiWhiteSpace) {
        TextRange textRange = elt.getTextRange();
        if (!textRange.contains(offset)) {
            LOG.error("PSI corrupted: in file " + file + " (" + file.getViewProvider().getVirtualFile() + ") offset=" + offset + " returned element " + elt + " with text range " + textRange);
        }
        final int decremented = textRange.getStartOffset() - 1;
        if (decremented >= 0) {
            return getLanguageRangeAtOffset(file, decremented);
        }
    }
    return findLanguageRangeFromElement(elt);
}
项目:intellij-ce-playground    文件:GroovyTrivialIfInspection.java   
public static boolean isSimplifiableImplicitReturnNegated(GrIfStatement ifStatement) {
  if (ifStatement.getElseBranch() != null) {
    return false;
  }
  GrStatement thenBranch = ifStatement.getThenBranch();
  thenBranch = ConditionalUtils.stripBraces(thenBranch);

  final PsiElement nextStatement =
      PsiTreeUtil.skipSiblingsForward(ifStatement,
          PsiWhiteSpace.class);
  if (!(nextStatement instanceof GrStatement)) {
    return false;
  }
  final GrStatement elseBranch = (GrStatement) nextStatement;
  return ConditionalUtils.isReturn(thenBranch, "false")
      && ConditionalUtils.isReturn(elseBranch, "true");
}
项目:intellij-ce-playground    文件:ConvertAbsolutePathToRelativeIntentionAction.java   
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  final int offset = editor.getCaretModel().getOffset();
  final PsiElement element = file.findElementAt(offset);
  if (element == null ||
      element instanceof PsiWhiteSpace) {
    return false;
  }

  final PsiReference reference = file.findReferenceAt(offset);
  final FileReference fileReference = reference == null ? null : FileReference.findFileReference(reference);

  if (fileReference != null) {
    final FileReferenceSet set = fileReference.getFileReferenceSet();
    final FileReference lastReference = set.getLastReference();
    return set.couldBeConvertedTo(isConvertToRelative()) && lastReference != null &&
           (!isConvertToRelative() && !set.isAbsolutePathReference() || isConvertToRelative() && set.isAbsolutePathReference()) &&
           lastReference.resolve() != null;
  }

  return false;
}
项目:intellij-ce-playground    文件:SuppressionUtil.java   
@Nullable
public static PsiElement getStatementToolSuppressedIn(@NotNull PsiElement place,
                                                      @NotNull String toolId,
                                                      @NotNull Class<? extends PsiElement> statementClass,
                                                      @NotNull Pattern suppressInLineCommentPattern) {
  PsiElement statement = PsiTreeUtil.getNonStrictParentOfType(place, statementClass);
  if (statement != null) {
    PsiElement prev = PsiTreeUtil.skipSiblingsBackward(statement, PsiWhiteSpace.class);
    if (prev instanceof PsiComment) {
      String text = prev.getText();
      Matcher matcher = suppressInLineCommentPattern.matcher(text);
      if (matcher.matches() && isInspectionToolIdMentioned(matcher.group(1), toolId)) {
        return prev;
      }
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:SMTRunnerConsoleProperties.java   
@Nullable
protected Navigatable findSuitableNavigatableForLine(@NotNull Project project, @NotNull VirtualFile file, int line) {
  // lets find first non-ws psi element

  final Document doc = FileDocumentManager.getInstance().getDocument(file);
  final PsiFile psi = doc == null ? null : PsiDocumentManager.getInstance(project).getPsiFile(doc);
  if (psi == null) {
    return null;
  }

  int offset = doc.getLineStartOffset(line);
  int endOffset = doc.getLineEndOffset(line);
  for (int i = offset + 1; i < endOffset; i++) {
    PsiElement el = psi.findElementAt(i);
    if (el != null && !(el instanceof PsiWhiteSpace)) {
      offset = el.getTextOffset();
      break;
    }
  }

  return new OpenFileDescriptor(project, file, offset);
}
项目:intellij-ce-playground    文件:ReplacerUtil.java   
public static PsiElement copySpacesAndCommentsBefore(PsiElement elementToReplace,
                                                        PsiElement[] patternElements,
                                                        String replacementToMake,
                                                        PsiElement elementParent) {
  int i = 0;
  while (true) {    // if it goes out of bounds then deep error happens
    if (!(patternElements[i] instanceof PsiComment || patternElements[i] instanceof PsiWhiteSpace)) {
      break;
    }
    ++i;
    if (patternElements.length == i) {
      break;
    }
  }

  if (patternElements.length == i) {
    Logger logger = Logger.getInstance(StructuralSearchProfile.class.getName());
    logger.error("Unexpected replacement structure:" + replacementToMake);
  }

  if (i != 0) {
    elementParent.addRangeBefore(patternElements[0], patternElements[i - 1], elementToReplace);
  }
  return patternElements[i];
}
项目:intellij-ce-playground    文件:CodeInsightUtilCore.java   
public static <T extends PsiElement> T findElementInRange(@NotNull PsiFile file,
                                                           int startOffset,
                                                           int endOffset,
                                                           @NotNull Class<T> klass,
                                                           @NotNull Language language) {
  PsiElement element1 = file.getViewProvider().findElementAt(startOffset, language);
  PsiElement element2 = file.getViewProvider().findElementAt(endOffset - 1, language);
  if (element1 instanceof PsiWhiteSpace) {
    startOffset = element1.getTextRange().getEndOffset();
    element1 = file.getViewProvider().findElementAt(startOffset, language);
  }
  if (element2 instanceof PsiWhiteSpace) {
    endOffset = element2.getTextRange().getStartOffset();
    element2 = file.getViewProvider().findElementAt(endOffset - 1, language);
  }
  if (element2 == null || element1 == null) return null;
  final PsiElement commonParent = PsiTreeUtil.findCommonParent(element1, element2);
  final T element =
    ReflectionUtil.isAssignable(klass, commonParent.getClass())
    ? (T)commonParent : PsiTreeUtil.getParentOfType(commonParent, klass);
  if (element == null || element.getTextRange().getStartOffset() != startOffset || element.getTextRange().getEndOffset() != endOffset) {
    return null;
  }
  return element;
}
项目:intellij-ce-playground    文件:SimpleDuplicatesFinder.java   
public SimpleDuplicatesFinder(@NotNull final PsiElement statement1,
                              @NotNull final PsiElement statement2,
                              AbstractVariableData[] variableData, Collection<String> variables) {
  myOutputVariables = variables;
  myParameters = new HashSet<String>();
  for (AbstractVariableData data : variableData) {
    myParameters.add(data.getOriginalName());
  }
  myPattern = new ArrayList<PsiElement>();
  PsiElement sibling = statement1;

  do {
    myPattern.add(sibling);
    if (sibling == statement2) break;
    sibling = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace.class, PsiComment.class);
  } while (sibling != null);
}
项目:intellij-ce-playground    文件:SimpleDuplicatesFinder.java   
@Nullable
protected SimpleMatch isDuplicateFragment(@NotNull final PsiElement candidate) {
  if (!canReplace(myReplacement, candidate)) return null;
  for (PsiElement pattern : myPattern) {
    if (PsiTreeUtil.isAncestor(pattern, candidate, false)) return null;
  }
  PsiElement sibling = candidate;
  final ArrayList<PsiElement> candidates = new ArrayList<PsiElement>();
  for (int i = 0; i != myPattern.size(); ++i) {
    if (sibling == null) return null;

    candidates.add(sibling);
    sibling = PsiTreeUtil.skipSiblingsForward(sibling, PsiWhiteSpace.class, PsiComment.class);
  }
  if (myPattern.size() != candidates.size()) return null;
  if (candidates.size() <= 0) return null;
  final SimpleMatch match = new SimpleMatch(candidates.get(0), candidates.get(candidates.size() - 1));
  for (int i = 0; i < myPattern.size(); i++) {
    if (!matchPattern(myPattern.get(i), candidates.get(i), match)) return null;
  }
  return match;
}
项目:intellij-ce-playground    文件:NodeSpecificHasherBase.java   
@Override
public int getNodeHash(PsiElement node) {
  if (node == null) {
    return 0;
  }
  if (node instanceof PsiWhiteSpace || node instanceof PsiErrorElement) {
    return 0;
  }
  else if (node instanceof LeafElement) {
    if (isToSkipAsLiteral(node)) {
      return 0;
    }
    return node.getText().hashCode();

  }
  return node.getClass().getName().hashCode();
}
项目:intellij-ce-playground    文件:DuplocatorUtil.java   
public static boolean isIgnoredNode(PsiElement element) {
  // ex. "var i = 0" in AS: empty JSAttributeList should be skipped
  /*if (element.getText().length() == 0) {
    return true;
  }*/

  if (element instanceof PsiWhiteSpace || element instanceof PsiErrorElement || element instanceof PsiComment) {
    return true;
  }

  if (!(element instanceof LeafElement)) {
    return false;
  }

  if (CharArrayUtil.containsOnlyWhiteSpaces(element.getText())) {
    return true;
  }

  EquivalenceDescriptorProvider descriptorProvider = EquivalenceDescriptorProvider.getInstance(element);
  if (descriptorProvider == null) {
    return false;
  }

  final IElementType elementType = ((LeafElement)element).getElementType();
  return descriptorProvider.getIgnoredTokens().contains(elementType);
}
项目:intellij-ce-playground    文件:PyCommentBreakerEnterProcessor.java   
public boolean doEnter(Editor editor, PsiElement psiElement, boolean isModified) {
  if (isModified) {
    return false;
  }
  final CaretModel caretModel = editor.getCaretModel();
  PsiElement atCaret = psiElement.getContainingFile().findElementAt(caretModel.getOffset());
  if (atCaret instanceof PsiWhiteSpace) {
    atCaret = atCaret.getPrevSibling();
  }
  final PsiElement comment = PsiTreeUtil.getParentOfType(atCaret, PsiComment.class, false);
  if (comment != null) {
    SmartEnterUtil.plainEnter(editor);
    editor.getDocument().insertString(caretModel.getOffset(), "# ");
    caretModel.moveToOffset(caretModel.getOffset() + 2);
    return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:PyOverrideImplementUtil.java   
@Nullable
public static PyClass getContextClass(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
  PsiDocumentManager.getInstance(project).commitAllDocuments();

  int offset = editor.getCaretModel().getOffset();
  PsiElement element = file.findElementAt(offset);
  if (element == null) {
    // are we in whitespace after last class? PY-440
    final PsiElement lastChild = file.getLastChild();
    if (lastChild != null &&
        offset >= lastChild.getTextRange().getStartOffset() &&
        offset <= lastChild.getTextRange().getEndOffset()) {
      element = lastChild;
    }
  }
  final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class, false);
  if (pyClass == null && element instanceof PsiWhiteSpace && element.getPrevSibling() instanceof PyClass) {
    return (PyClass)element.getPrevSibling();
  }
  return pyClass;
}
项目:intellij-ce-playground    文件:CStyleCommentPredicate.java   
public boolean satisfiedBy(PsiElement element) {
  if (!(element instanceof PsiComment)) {
    return false;
  }
  if (element instanceof PsiDocComment) {
    return false;
  }
  final PsiComment comment = (PsiComment)element;
  final IElementType type = comment.getTokenType();
  if (!JavaTokenType.C_STYLE_COMMENT.equals(type)) {
    return false;
  }
  final PsiElement sibling = PsiTreeUtil.nextLeaf(comment);
  if (!(sibling instanceof PsiWhiteSpace)) {
    return false;
  }
  final String whitespaceText = sibling.getText();
  return whitespaceText.indexOf((int)'\n') >= 0 ||
         whitespaceText.indexOf((int)'\r') >= 0;
}
项目:intellij-ce-playground    文件:UnsupportedFeaturesUtil.java   
public static boolean raiseHasMoreThenOneArg(PyRaiseStatement node, LanguageLevel versionToProcess) {
  final PyExpression[] expressions = node.getExpressions();
  if (expressions.length > 0) {
    if (expressions.length < 2) {
      return false;
    }
    if (versionToProcess.isPy3K()) {
      if (expressions.length == 3) {
        return true;
      }
      PsiElement element = expressions[0].getNextSibling();
      while (element instanceof PsiWhiteSpace) {
        element = element.getNextSibling();
      }
      if (element != null && ",".equals(element.getText())) {
        return true;
      }
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:UnsupportedFeaturesUtil.java   
public static boolean raiseHasFromKeyword(PyRaiseStatement node, LanguageLevel versionToProcess) {
  final PyExpression[] expressions = node.getExpressions();
  if (expressions.length > 0) {
    if (expressions.length < 2) {
      return false;
    }
    if (!versionToProcess.isPy3K()) {
      PsiElement element = expressions[0].getNextSibling();
      while (element instanceof PsiWhiteSpace) {
        element = element.getNextSibling();
      }
      if (element != null && element.getNode().getElementType() == PyTokenTypes.FROM_KEYWORD) {
        return true;
      }
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:PyLineBreakpointType.java   
@Override
public boolean canPutAt(@NotNull final VirtualFile file, final int line, @NotNull final Project project) {
  final Ref<Boolean> stoppable = Ref.create(false);
  final Document document = FileDocumentManager.getInstance().getDocument(file);
  if (document != null) {
    if (file.getFileType() == PythonFileType.INSTANCE || isPythonScratch(file)) {
      XDebuggerUtil.getInstance().iterateLine(project, document, line, new Processor<PsiElement>() {
        @Override
        public boolean process(PsiElement psiElement) {
          if (psiElement instanceof PsiWhiteSpace || psiElement instanceof PsiComment) return true;
          if (psiElement.getNode() != null && notStoppableElementType(psiElement.getNode().getElementType())) return true;

          // Python debugger seems to be able to stop on pretty much everything
          stoppable.set(true);
          return false;
        }
      });

      if (PyDebugSupportUtils.isContinuationLine(document, line - 1)) {
        stoppable.set(false);
      }
    }
  }

  return stoppable.get();
}
项目:intellij-ce-playground    文件:PyInspectionsSuppressor.java   
private static boolean isSuppressedForElement(@NotNull PyElement stmt, @NotNull String suppressId) {
  PsiElement prevSibling = stmt.getPrevSibling();
  if (prevSibling == null) {
    final PsiElement parent = stmt.getParent();
    if (parent != null) {
      prevSibling = parent.getPrevSibling();
    }
  }
  while (prevSibling instanceof PsiComment || prevSibling instanceof PsiWhiteSpace) {
    if (prevSibling instanceof PsiComment && isSuppressedInComment(prevSibling.getText().substring(1).trim(), suppressId)) {
      return true;
    }
    prevSibling = prevSibling.getPrevSibling();
  }
  return false;
}
项目:intellij-ce-playground    文件:StatementEffectFunctionCallQuickFix.java   
private static PsiElement getNextElement(@NotNull final PsiElement expression) {
  final PsiElement whiteSpace = expression.getContainingFile().findElementAt(expression.getTextOffset() + expression.getTextLength());
  PsiElement next = null;
  if (whiteSpace instanceof PsiWhiteSpace) {
    final String whiteSpaceText = whiteSpace.getText();
    if (!whiteSpaceText.contains("\n")) {
      next = whiteSpace.getNextSibling();
      while (next instanceof PsiWhiteSpace && whiteSpaceText.contains("\\")) {
        next = next.getNextSibling();
      }
    }
  }
  else
    next = whiteSpace;

  RemoveUnnecessaryBackslashQuickFix.removeBackSlash(next);
  if (whiteSpace != null) whiteSpace.delete();
  return next;
}
项目:intellij-ce-playground    文件:RemoveUnnecessaryBackslashQuickFix.java   
public static void removeBackSlash(PsiElement parent) {
  if (parent != null) {
    Stack<PsiElement> stack = new Stack<PsiElement>();
    if (parent instanceof PyParenthesizedExpression)
      stack.push(((PyParenthesizedExpression)parent).getContainedExpression());
    else
      stack.push(parent);
    while (!stack.isEmpty()) {
      PsiElement el = stack.pop();
      PsiWhiteSpace[] children = PsiTreeUtil.getChildrenOfType(el, PsiWhiteSpace.class);
      if (children != null) {
        for (PsiWhiteSpace ws : children) {
          if (ws.getText().contains("\\")) {
            ws.delete();
          }
        }
      }
      for (PsiElement psiElement : el.getChildren()) {
        stack.push(psiElement);
      }
    }
  }
}
项目:intellij-ce-playground    文件:PyIndentUtil.java   
@NotNull
public static String getElementIndent(@NotNull PsiElement anchor) {
  if (anchor instanceof PsiFile) {
    return "";
  }
  final PyStatementList statementList = PsiTreeUtil.getParentOfType(anchor, PyStatementList.class, false);
  if (statementList == null) {
    return "";
  }
  final PsiElement prevSibling = statementList.getPrevSibling();
  final String whitespace = prevSibling instanceof PsiWhiteSpace ? prevSibling.getText() : "";
  final int i = whitespace.lastIndexOf("\n");
  if (i >= 0 && statementList.getStatements().length != 0) {
    return whitespace.substring(i + 1);
  }
  else {
    return getExpectedElementIndent(anchor);
  }
}
项目:intellij-ce-playground    文件:PyListSelectionHandler.java   
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
  TextRange stringRange = e.getTextRange();
  PsiElement firstChild = e.getFirstChild().getNextSibling();
  if (firstChild instanceof PsiErrorElement) {
    return Collections.emptyList();
  }
  int startShift = 1;
  if (firstChild instanceof PsiWhiteSpace)
    startShift += firstChild.getTextLength();
  PsiElement lastChild = e.getLastChild().getPrevSibling();
  int endShift = 1;
  if (lastChild instanceof PsiWhiteSpace && lastChild != firstChild)
    endShift += lastChild.getTextLength();

  final TextRange offsetRange = new TextRange(stringRange.getStartOffset() + startShift, stringRange.getEndOffset() - endShift);
  if (offsetRange.contains(cursorOffset) && offsetRange.getLength() > 1) {
    return Collections.singletonList(offsetRange);
  }
  return Collections.emptyList();
}
项目:intellij-ce-playground    文件:PyStatementSelectionHandler.java   
public List<TextRange> select(final PsiElement e, final CharSequence editorText, final int cursorOffset, final Editor editor) {
  List<TextRange> result = new ArrayList<TextRange>();
  PsiElement endElement = e;
  while(endElement.getLastChild() != null) {
    endElement = endElement.getLastChild();
  }
  if (endElement instanceof PsiWhiteSpace) {
    final PsiElement prevSibling = endElement.getPrevSibling();
    if (prevSibling != null) {
      endElement = prevSibling;
    }
  }
  result.addAll(expandToWholeLine(editorText, new TextRange(e.getTextRange().getStartOffset(),
                                                            endElement.getTextRange().getEndOffset())));

  return result;
}
项目:intellij-ce-playground    文件:XmlContentParticleImpl.java   
public static Quantifier getQuantifierImpl(PsiElement element) {
  PsiElement nextSibling = element.getNextSibling();
  while (nextSibling instanceof PsiWhiteSpace) {
    nextSibling = nextSibling.getNextSibling();
  }

  if (nextSibling instanceof XmlToken) {
    IElementType tokenType = ((XmlToken)nextSibling).getTokenType();
    if (tokenType == XML_PLUS) {
      return Quantifier.ONE_OR_MORE;
    }
    else if (tokenType == XML_STAR) {
      return Quantifier.ZERO_OR_MORE;
    }
    else if (tokenType == XML_QUESTION) {
      return Quantifier.OPTIONAL;
    }
  }
  return Quantifier.REQUIRED;
}
项目:intellij-ce-playground    文件:XmlCharFilter.java   
public static boolean isInXmlContext(Lookup lookup) {
  if (!lookup.isCompletion()) return false;

  PsiElement psiElement = lookup.getPsiElement();
  PsiFile file = lookup.getPsiFile();
  if (!(file instanceof XmlFile) && psiElement != null) {
    file = psiElement.getContainingFile();
  }


  if (file instanceof XmlFile) {
    if (psiElement != null) {
      PsiElement elementToTest = psiElement;
      if (elementToTest instanceof PsiWhiteSpace) {
        elementToTest = elementToTest.getParent(); // JSPX has whitespace with language Java
      }

      final Language language = elementToTest.getLanguage();
      if (!(language instanceof XMLLanguage)) {
        return false;
      }
    }
    return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:XmlTagSelectioner.java   
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
  List<TextRange> result = super.select(e, editorText, cursorOffset, editor);
  PsiElement[] children = e.getChildren();

  addTagContentSelection(children, result, editorText);

  PsiElement prev = e.getPrevSibling();
  while (prev instanceof PsiWhiteSpace || prev instanceof XmlText || prev instanceof XmlComment) {
    if (prev instanceof XmlText && prev.getText().trim().length() > 0) break;
    if (prev instanceof XmlComment) {
      result.addAll(expandToWholeLine(editorText,
                                      new TextRange(prev.getTextRange().getStartOffset(),
                                                    e.getTextRange().getEndOffset()),
                                      false));
    }
    prev = prev.getPrevSibling();
  }

  return result;
}
项目:intellij-ce-playground    文件:XmlAutoPopupHandler.java   
private static boolean isLanguageRelevant(final PsiElement element,
                                          final PsiFile file,
                                          final Ref<Boolean> isRelevantLanguage,
                                          final Ref<Boolean> isAnt) {
  Boolean isAntFile = isAnt.get();
  if (isAntFile == null) {
    isAntFile = XmlUtil.isAntFile(file);
    isAnt.set(isAntFile);
  }
  Boolean result = isRelevantLanguage.get();
  if (result == null) {
    Language language = element.getLanguage();
    PsiElement parent = element.getParent();
    if (element instanceof PsiWhiteSpace && parent != null) {
      language = parent.getLanguage();
    }
    result = language instanceof XMLLanguage || HtmlUtil.supportsXmlTypedHandlers(file) || isAntFile.booleanValue();
    isRelevantLanguage.set(result);
  }
  return result.booleanValue();
}
项目:intellij-ce-playground    文件:XmlBlock.java   
private void createLeafBlocks(ASTNode node, List<Block> result) {
  if (node instanceof OuterLanguageElement) {
    processChild(result, node, null, null, null);
    return;
  }

  ASTNode child = node.getFirstChildNode();
  if (child == null && !(node instanceof PsiWhiteSpace) && node.getElementType() != TokenType.ERROR_ELEMENT && node.getTextLength() > 0) {
    result.add(new ReadOnlyBlock(node));
    return;
  }
  while (child != null) {
    createLeafBlocks(child, result);
    child = child.getTreeNext();
  }
}
项目:intellij-ce-playground    文件:RncCompletionData.java   
private String[] doGetKeywords(PsiElement context) {
  final PsiElement next = PsiTreeUtil.skipSiblingsForward(context, PsiWhiteSpace.class);
  if (next != null && EscapeUtil.unescapeText(next).equals("=")) {
      return new String[]{ "start" };
    }

  if (DEFAULT_PATTERN.accepts(context)) {
    return new String[]{ "namespace" };
  } else if (DECL_PATTERN.accepts(context)) {
    return ArrayUtil.EMPTY_STRING_ARRAY;
  } else if (context.getParent() instanceof RncDefine && context.getParent().getFirstChild() == context) {
    if (DEFINE_PATTERN.accepts(context)) {
      return ArrayUtil.EMPTY_STRING_ARRAY;
    }
    if (TOP_LEVEL.accepts(context)) {
      if (!afterPattern(context)) {
        return ArrayUtil.mergeArrays(DECL_KEYWORDS, ArrayUtil.mergeArrays(GRAMMAR_CONTENT_KEYWORDS, PATTERN_KEYWORDS));
      }
    }
    return GRAMMAR_CONTENT_KEYWORDS;
  }
  return PATTERN_KEYWORDS;
}
项目:intellij-ce-playground    文件:RncFoldingBuilder.java   
@Nullable
private static ASTNode checkNodeAndSiblings(@Nullable ASTNode node, TokenSet tokens, ArrayList<FoldingDescriptor> regions, Document document) {
  if (node != null && tokens.contains(node.getElementType())) {
    final ASTNode start = node;
    ASTNode end = start;

    node = node.getTreeNext();
    if (node != null) {
      do {
        end = node;
        node = node.getTreeNext();
      } while (node != null && tokens.contains(node.getElementType()));
    }
    if (end != start) {
      while (end.getPsi() instanceof PsiWhiteSpace) {
        end = end.getTreePrev();
      }
      if (isOnDifferentLine(start, end, document)) {
        regions.add(new FoldingDescriptor(start, new TextRange(start.getStartOffset(), end.getTextRange().getEndOffset())));
      }
    }
  }
  return node;
}
项目:intellij-ce-playground    文件:UpdatePropertiesFileCopyright.java   
protected void scanFile() {
  PsiElement first = getFile().getFirstChild(); // PropertiesList
  PsiElement last = first;
  PsiElement next = first;
  while (next != null) {
    if (next instanceof PsiComment || next instanceof PsiWhiteSpace) {
      next = getNextSibling(next);
    }
    else {
      break;
    }
    last = next;
  }

  if (first != null) {
    checkComments(first, last, true);
  }
}
项目:intellij-ce-playground    文件:GroovyTrivialIfInspection.java   
private static void replaceSimplifiableImplicitAssignment(GrIfStatement statement)
    throws IncorrectOperationException {
  final PsiElement prevStatement =
      PsiTreeUtil.skipSiblingsBackward(statement,
          PsiWhiteSpace.class);
  if (prevStatement == null) {
    return;
  }
  final GrCondition condition = statement.getCondition();
  final String conditionText = condition.getText();
  final GrStatement thenBranch = statement.getThenBranch();
  final GrAssignmentExpression assignmentExpression =
      (GrAssignmentExpression) ConditionalUtils.stripBraces(thenBranch);
  final IElementType operator =
      assignmentExpression.getOperationTokenType();
  final GrExpression lhs = assignmentExpression.getLValue();
  final String lhsText = lhs.getText();
  replaceStatement(statement,
      lhsText + operator + conditionText + ';');
  prevStatement.delete();
}