Package com.intellij.openapi.util

Examples of com.intellij.openapi.util.TextRange


* @author patrick (11/11/13)
*/
public class ShowFormattingBlocks extends AnAction {
  private static String printBlock(AbstractBlock block, String text) {
    String result = "";
    final TextRange range = block.getTextRange();
    result += block.getNode() + "(" + text.substring(range.getStartOffset(), Math.min(range.getStartOffset() + 3, range.getEndOffset())) +
        "..." + text.substring(Math.max(range.getEndOffset() - 3, range.getStartOffset()), range.getEndOffset()) + range +
        ")" + printIndent(block.getIndent()) + " " + block.getAlignment() + "\n";
    final List<Block> subBlocks = block.getSubBlocks();
    for (Block subBlock : subBlocks) {
      result += printBlock((AbstractMathematicaBlock) subBlock, text);
    }
View Full Code Here


    if (offset == 0 || offset > editor.getDocument().getTextLength()) {
      return Result.CONTINUE;
    }

    String previousChar = editor.getDocument().getText(new TextRange(offset - 1, offset));

    if (file.getViewProvider() instanceof HbFileViewProvider) {
      PsiDocumentManager.getInstance(project).commitAllDocuments();

      // we suppress the built-in "}" auto-complete when we see "{{"
View Full Code Here

    if (offset < 2 || offset > editor.getDocument().getTextLength()) {
      return Result.CONTINUE;
    }

    String previousChar = editor.getDocument().getText(new TextRange(offset - 2, offset - 1));
    boolean closeBraceCompleted = false;

    if (provider instanceof HbFileViewProvider) {
      if (HbConfig.isAutocompleteMustachesEnabled() && c == '}' && !previousChar.equals("}")) {
        // we may be able to complete the second brace
View Full Code Here

      Runnable createFormatRunnable(final PsiFile file) {
        return new Runnable() {
          @Override
          public void run() {
            try {
              TextRange rangeToUse = file.getTextRange();
              CodeStyleManager styleManager = CodeStyleManager.getInstance(getProject());
              styleManager.reformatText(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset());
            }
            catch (IncorrectOperationException e) {
              assertTrue(e.getLocalizedMessage(), false);
            }
          }
View Full Code Here

        File mainFile = new File(path);
        Map<String, SortedSet<String>> userImports = null;
        for (GHCMessage ghcMessage : ghcMessages) {
            if (FileUtil.filesEqual(new File(ghcMessage.getFileName()), mainFile)) {
                LineColRange lcRange = ghcMessage.getRange();
                TextRange range = lcRange.getRange(psiFile);
                String message = ghcMessage.getErrorMessage();
                CompilerMessageCategory category = ghcMessage.getCategory();

                Annotation out = null;
                switch (category) {
                case ERROR:
                    out = annotationHolder.createErrorAnnotation(range, message);
                    break;
                case WARNING:
                    out = annotationHolder.createWarningAnnotation(range, message);
                    break;
                case INFORMATION:
                    out = annotationHolder.createInfoAnnotation(range, message);
                    break;
                case STATISTICS:
                    break;
                }
                if (out != null) {
                    if (message.startsWith("Not in scope")) {
                        Module module = DeclarationPosition.getDeclModule(psiFile);
                        String symbol = psiFile.getText().substring(range.getStartOffset(), range.getEndOffset());
                        int dotIndex = symbol.lastIndexOf('.');
                        String unqualifiedSymbol = dotIndex >= 0 ? symbol.substring(dotIndex + 1) : symbol;
                        if (userImports == null) {
                            userImports = listUserImports(module, Paths.get(path));
                        }
View Full Code Here

    MyLocation(int offset) {
        this.offset = offset;
    }

    static MyRange create(MyLocation start, MyLocation end) {
        return new MyRange(new TextRange(start.offset, end.offset));
    }
View Full Code Here

        while (true) {
            IElementType type = lexer.getTokenType();
            if (type == null)
                break;
            if (!HaskellTokenTypes.WHITESPACES.contains(type)) {
                TextRange textRange = new TextRange(lexer.getTokenStart(), lexer.getTokenEnd());
                IRange range = new MyRange(textRange);
                ranges.put(range.getStart(), new Filler(range, type, lexer.getTokenText()));
            }
            lexer.advance();
        }
View Full Code Here

    private void execute(LanguageConsoleImpl languageConsole,
                         ConsoleHistoryModel consoleHistoryModel) {
        // Process input and add to history
        Document document = languageConsole.getCurrentEditor().getDocument();
        String text = document.getText();
        TextRange range = new TextRange(0, document.getTextLength());

        languageConsole.getCurrentEditor().getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
        languageConsole.addCurrentToHistory(range, false, preserveMarkup);
        languageConsole.setInputText("");
        if (!StringUtil.isEmptyOrSpaces(text)) {
            consoleHistoryModel.addToHistory(text);
        }
View Full Code Here

    public String generateDoc(PsiElement element, PsiElement originalElement) {
        if (!(element instanceof HPAbstractIdent))
            return null;
        HPAbstractIdent ident = (HPAbstractIdent) element;
        TextRange range = ident.getTextRange();
        PsiFile psiFile = element.getContainingFile();
        VirtualFile file = psiFile.getVirtualFile();
        if (file == null)
            return null;
        // todo: run in event-dispatch thread
        //fdm.saveAllDocuments();
        // try this: PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
        int offset = range.getStartOffset();
        LineCol coord = LineCol.fromOffset(psiFile, offset);
        Module module = DeclarationPosition.getDeclModule(psiFile);
        if (module == null)
            return null;
        CompilerLocation compiler = CompilerLocation.get(module);
View Full Code Here

        this.start = LineCol.parse(start);
        this.end = LineCol.parse(end);
    }

    public TextRange getRange(PsiFile file) {
        return new TextRange(start.getOffset(file), end.getOffset(file));
    }
View Full Code Here

TOP

Related Classes of com.intellij.openapi.util.TextRange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.