Java 类com.intellij.openapi.editor.RawText 实例源码

项目:intellij-ce-playground    文件:TextBlockTransferable.java   
public TextBlockTransferable(@NotNull String text, @NotNull Collection<TextBlockTransferableData> extraData, @Nullable RawText rawText) {
  myText = cleanFromNullsIfNeeded(text);
  myExtraData = extraData;
  myRawText = rawText;

  List<DataFlavor> dataFlavors = new ArrayList<DataFlavor>();
  Collections.addAll(dataFlavors, DataFlavor.stringFlavor, DataFlavor.plainTextFlavor);
  final DataFlavor flavor = RawText.getDataFlavor();
  if (myRawText != null && flavor != null) {
    dataFlavors.add(flavor);
  }
  for(TextBlockTransferableData data: extraData) {
    final DataFlavor blockFlavor = data.getFlavor();
    if (blockFlavor != null) {
      dataFlavors.add(blockFlavor);
    }
  }
  myTransferDataFlavors = dataFlavors.toArray(new DataFlavor[dataFlavors.size()]);
}
项目:intellij-ce-playground    文件:TextBlockTransferable.java   
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
  try {
    for(TextBlockTransferableData data: myExtraData) {
      if (Comparing.equal(data.getFlavor(), flavor)) {
        return data;
      }
    }
    if (myRawText != null && Comparing.equal(RawText.getDataFlavor(), flavor)) {
      return myRawText;
    }
    else if (DataFlavor.stringFlavor.equals(flavor)) {
      return myText;
    }
    else if (DataFlavor.plainTextFlavor.equals(flavor)) {
      return new StringReader(myText);
    }
  }
  catch(NoClassDefFoundError e) {
    // ignore
  }
  throw new UnsupportedFlavorException(flavor);
}
项目:tools-idea    文件:TextBlockTransferable.java   
public TextBlockTransferable(String text, Collection<TextBlockTransferableData> extraData, RawText rawText) {
  myText = text;
  myExtraData = extraData;
  myRawText = rawText;

  List<DataFlavor> dataFlavors = new ArrayList<DataFlavor>();
  Collections.addAll(dataFlavors, DataFlavor.stringFlavor, DataFlavor.plainTextFlavor);
  final DataFlavor flavor = RawText.getDataFlavor();
  if (myRawText != null && flavor != null) {
    dataFlavors.add(flavor);
  }
  for(TextBlockTransferableData data: extraData) {
    final DataFlavor blockFlavor = data.getFlavor();
    if (blockFlavor != null) {
      dataFlavors.add(blockFlavor);
    }
  }
  myTransferDataFlavors = dataFlavors.toArray(new DataFlavor[dataFlavors.size()]);
}
项目:tools-idea    文件:TextBlockTransferable.java   
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
  try {
    for(TextBlockTransferableData data: myExtraData) {
      if (Comparing.equal(data.getFlavor(), flavor)) {
        return data;
      }
    }
    if (myRawText != null && Comparing.equal(RawText.getDataFlavor(), flavor)) {
      return myRawText;
    }
    else if (DataFlavor.stringFlavor.equals(flavor)) {
      return myText;
    }
    else if (DataFlavor.plainTextFlavor.equals(flavor)) {
      return new StringReader(myText);
    }
  }
  catch(NoClassDefFoundError e) {
    // ignore
  }
  throw new UnsupportedFlavorException(flavor);
}
项目:consulo    文件:TextBlockTransferable.java   
public TextBlockTransferable(@Nonnull String text, @Nonnull Collection<TextBlockTransferableData> extraData, @Nullable RawText rawText) {
  myText = cleanFromNullsIfNeeded(text);
  myExtraData = extraData;
  myRawText = rawText;

  List<DataFlavor> dataFlavors = new ArrayList<DataFlavor>();
  Collections.addAll(dataFlavors, DataFlavor.stringFlavor, DataFlavor.plainTextFlavor);
  final DataFlavor flavor = RawText.getDataFlavor();
  if (myRawText != null && flavor != null) {
    dataFlavors.add(flavor);
  }
  for(TextBlockTransferableData data: extraData) {
    final DataFlavor blockFlavor = data.getFlavor();
    if (blockFlavor != null) {
      dataFlavors.add(blockFlavor);
    }
  }
  myTransferDataFlavors = dataFlavors.toArray(new DataFlavor[dataFlavors.size()]);
}
项目:consulo    文件:TextBlockTransferable.java   
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
  try {
    for(TextBlockTransferableData data: myExtraData) {
      if (Comparing.equal(data.getFlavor(), flavor)) {
        return data;
      }
    }
    if (myRawText != null && Comparing.equal(RawText.getDataFlavor(), flavor)) {
      return myRawText;
    }
    else if (DataFlavor.stringFlavor.equals(flavor)) {
      return myText;
    }
    else if (DataFlavor.plainTextFlavor.equals(flavor)) {
      return new StringReader(myText);
    }
  }
  catch(NoClassDefFoundError e) {
    // ignore
  }
  throw new UnsupportedFlavorException(flavor);
}
项目:intellij-ce-playground    文件:StringLiteralCopyPasteProcessor.java   
@NotNull
@Override
public String preprocessOnPaste(final Project project, final PsiFile file, final Editor editor, String text, final RawText rawText) {
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor
  final int selectionStart = selectionModel.getSelectionStart();
  final int selectionEnd = selectionModel.getSelectionEnd();
  PsiElement token = findLiteralTokenType(file, selectionStart, selectionEnd);
  if (token == null) {
    return text;
  }

  if (isStringLiteral(token)) {
    StringBuilder buffer = new StringBuilder(text.length());
    @NonNls String breaker = getLineBreaker(token);
    final String[] lines = LineTokenizer.tokenize(text.toCharArray(), false, true);
    for (int i = 0; i < lines.length; i++) {
      buffer.append(escapeCharCharacters(lines[i], token));
      if (i != lines.length - 1) {
        buffer.append(breaker);
      }
      else if (text.endsWith("\n")) {
        buffer.append("\\n");
      }
    }
    text = buffer.toString();
  }
  else if (isCharLiteral(token)) {
    return escapeCharCharacters(text, token);
  }
  return text;
}
项目:intellij-ce-playground    文件:DebuggerCopyPastePreprocessor.java   
@NotNull
@Override
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
  if (editor.getUserData(REMOVE_NEWLINES_ON_PASTE) != null) {
    return StringUtil.convertLineSeparators(text, " ");
  }
  return text;
}
项目:intellij-ce-playground    文件:XmlCopyPastePreProcessor.java   
@Override
@NotNull
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  int caretOffset = editor.getCaretModel().getOffset();
  PsiElement element = PsiUtilCore.getElementAtOffset(file, caretOffset);

  ASTNode node = element.getNode();
  if (node != null) {
    boolean hasMarkup = text.indexOf('>') >= 0 || text.indexOf('<') >= 0;
    if (element.getTextOffset() == caretOffset &&
        node.getElementType() == XmlTokenType.XML_END_TAG_START &&
        node.getTreePrev().getElementType() == XmlTokenType.XML_TAG_END) {

       return hasMarkup ? text : encode(text, element);
    } else {
      XmlElement parent = PsiTreeUtil.getParentOfType(element, XmlText.class, XmlAttributeValue.class);
      if (parent != null) {
        if (parent instanceof XmlText && hasMarkup) {
          return text;
        }

        if (TreeUtil.findParent(node, XmlElementType.XML_CDATA) == null &&
            TreeUtil.findParent(node, XmlElementType.XML_COMMENT) == null) {
          return encode(text, element);
        }
      }
    }
  }
  return text;
}
项目:intellij-ce-playground    文件:GroovyLiteralCopyPasteProcessor.java   
@NotNull
@Override
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor
  final int selectionStart = selectionModel.getSelectionStart();
  final int selectionEnd = selectionModel.getSelectionEnd();
  PsiElement token = findLiteralTokenType(file, selectionStart, selectionEnd);
  if (token == null) {
    return text;
  }

  if (isStringLiteral(token)) {
    StringBuilder buffer = new StringBuilder(text.length());
    @NonNls String breaker = getLineBreaker(token);
    final String[] lines = LineTokenizer.tokenize(text.toCharArray(), false, true);
    for (int i = 0; i < lines.length; i++) {
      buffer.append(escapeCharCharacters(lines[i], token));
      if (i != lines.length - 1 || "\n".equals(breaker) && text.endsWith("\n")) {
        buffer.append(breaker);
      }
    }
    text = buffer.toString();
  }
  return text;
}
项目:idea-gradle-dependencies-formatter    文件:MavenToGradleDependenciesCopyPasteProcessor.java   
@NotNull
@Override
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
    if (!canPasteForFile(file)) {
        return text;
    }
    return preprocessedText(text);
}
项目:Buck-IntelliJ-Plugin    文件:BuckCopyPasteProcessor.java   
@NotNull
@Override
public String preprocessOnPaste(
    Project project, PsiFile psiFile, Editor editor, String text, RawText rawText) {
  if (!(psiFile instanceof BuckFile)) {
    return text;
  }
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // Pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor.
  final int selectionStart = selectionModel.getSelectionStart();
  final PsiElement element = psiFile.findElementAt(selectionStart);
  if (element == null) {
    return text;
  }

  if (BuckPsiUtils.hasElementType(
      element.getNode(),
      TokenType.WHITE_SPACE,
      BuckTypes.SINGLE_QUOTED_STRING,
      BuckTypes.DOUBLE_QUOTED_STRING)) {
    PsiElement property = BuckPsiUtils.findAncestorWithType(element, BuckTypes.PROPERTY);
    if (checkPropertyName(property)) {
      text = buildBuckDependencyPath(element, project, text);
    }
  }
  return text;
}
项目:tools-idea    文件:StringLiteralCopyPasteProcessor.java   
@Override
public String preprocessOnPaste(final Project project, final PsiFile file, final Editor editor, String text, final RawText rawText) {
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor
  final int selectionStart = selectionModel.getSelectionStart();
  final int selectionEnd = selectionModel.getSelectionEnd();
  PsiElement token = findLiteralTokenType(file, selectionStart, selectionEnd);
  if (token == null) {
    return text;
  }

  if (isStringLiteral(token)) {
    StringBuilder buffer = new StringBuilder(text.length());
    @NonNls String breaker = getLineBreaker(token);
    final String[] lines = LineTokenizer.tokenize(text.toCharArray(), false, true);
    for (int i = 0; i < lines.length; i++) {
      buffer.append(escapeCharCharacters(lines[i], token));
      if (i != lines.length - 1) {
        buffer.append(breaker);
      }
      else if (text.endsWith("\n")) {
        buffer.append("\\n");
      }
    }
    text = buffer.toString();
  }
  else if (isCharLiteral(token)) {
    return escapeCharCharacters(text, token);
  }
  return text;
}
项目:tools-idea    文件:XmlCopyPastePreProcessor.java   
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  int caretOffset = editor.getCaretModel().getOffset();
  PsiElement element = PsiUtilCore.getElementAtOffset(file, caretOffset);

  ASTNode node = element.getNode();
  if (node != null) {
    boolean hasMarkup = text.indexOf('>') >= 0 || text.indexOf('<') >= 0;
    if (element.getTextOffset() == caretOffset &&
        node.getElementType() == XmlElementType.XML_END_TAG_START &&
        node.getTreePrev().getElementType() == XmlElementType.XML_TAG_END) {

       return hasMarkup ? text : encode(text, element);
    } else {
      XmlElement parent = PsiTreeUtil.getParentOfType(element, XmlText.class, XmlAttributeValue.class);
      if (parent != null) {
        if (parent instanceof XmlText && hasMarkup) {
          return text;
        }

        if (TreeUtil.findParent(node, XmlElementType.XML_CDATA) == null &&
            TreeUtil.findParent(node, XmlElementType.XML_COMMENT) == null) {
          return encode(text, element);
        }
      }
    }
  }
  return text;
}
项目:tools-idea    文件:GroovyLiteralCopyPasteProcessor.java   
@Override
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor
  final int selectionStart = selectionModel.getSelectionStart();
  final int selectionEnd = selectionModel.getSelectionEnd();
  PsiElement token = findLiteralTokenType(file, selectionStart, selectionEnd);
  if (token == null) {
    return text;
  }

  if (isStringLiteral(token)) {
    StringBuilder buffer = new StringBuilder(text.length());
    @NonNls String breaker = getLineBreaker(token);
    final String[] lines = LineTokenizer.tokenize(text.toCharArray(), false, true);
    for (int i = 0; i < lines.length; i++) {
      buffer.append(escapeCharCharacters(lines[i], token));
      if (i != lines.length - 1 || "\n".equals(breaker) && text.endsWith("\n")) {
        buffer.append(breaker);
      }
    }
    text = buffer.toString();
  }
  return text;
}
项目:consulo    文件:DebuggerCopyPastePreprocessor.java   
@Nonnull
@Override
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
  if (editor.getUserData(REMOVE_NEWLINES_ON_PASTE) != null) {
    return StringUtil.convertLineSeparators(text, " ");
  }
  return text;
}
项目:consulo-xml    文件:XmlCopyPastePreProcessor.java   
public String preprocessOnPaste(Project project, PsiFile file, Editor editor, String text, RawText rawText) {
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  int caretOffset = editor.getCaretModel().getOffset();
  PsiElement element = PsiUtilCore.getElementAtOffset(file, caretOffset);

  ASTNode node = element.getNode();
  if (node != null) {
    boolean hasMarkup = text.indexOf('>') >= 0 || text.indexOf('<') >= 0;
    if (element.getTextOffset() == caretOffset &&
        node.getElementType() == XmlElementType.XML_END_TAG_START &&
        node.getTreePrev().getElementType() == XmlElementType.XML_TAG_END) {

       return hasMarkup ? text : encode(text, element);
    } else {
      XmlElement parent = PsiTreeUtil.getParentOfType(element, XmlText.class, XmlAttributeValue.class);
      if (parent != null) {
        if (parent instanceof XmlText && hasMarkup) {
          return text;
        }

        if (TreeUtil.findParent(node, XmlElementType.XML_CDATA) == null &&
            TreeUtil.findParent(node, XmlElementType.XML_COMMENT) == null) {
          return encode(text, element);
        }
      }
    }
  }
  return text;
}
项目:consulo-java    文件:StringLiteralCopyPasteProcessor.java   
@Override
public String preprocessOnPaste(final Project project, final PsiFile file, final Editor editor, String text, final RawText rawText) {
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor
  final int selectionStart = selectionModel.getSelectionStart();
  final int selectionEnd = selectionModel.getSelectionEnd();
  PsiElement token = findLiteralTokenType(file, selectionStart, selectionEnd);
  if (token == null) {
    return text;
  }

  if (isStringLiteral(token)) {
    StringBuilder buffer = new StringBuilder(text.length());
    @NonNls String breaker = getLineBreaker(token);
    final String[] lines = LineTokenizer.tokenize(text.toCharArray(), false, true);
    for (int i = 0; i < lines.length; i++) {
      buffer.append(escapeCharCharacters(lines[i], token));
      if (i != lines.length - 1) {
        buffer.append(breaker);
      }
      else if (text.endsWith("\n")) {
        buffer.append("\\n");
      }
    }
    text = buffer.toString();
  }
  else if (isCharLiteral(token)) {
    return escapeCharCharacters(text, token);
  }
  return text;
}
项目:buck    文件:BuckCopyPasteProcessor.java   
@Override
public String preprocessOnPaste(
    Project project, PsiFile psiFile, Editor editor, String text, RawText rawText) {
  if (!(psiFile instanceof BuckFile)) {
    return text;
  }
  final Document document = editor.getDocument();
  PsiDocumentManager.getInstance(project).commitDocument(document);
  final SelectionModel selectionModel = editor.getSelectionModel();

  // Pastes in block selection mode (column mode) are not handled by a CopyPasteProcessor.
  final int selectionStart = selectionModel.getSelectionStart();
  final PsiElement element = psiFile.findElementAt(selectionStart);
  if (element == null) {
    return text;
  }

  ASTNode elementNode = element.getNode();
  // A simple test of the element type
  boolean isQuotedString =
      BuckPsiUtils.hasElementType(
          elementNode, BuckTypes.SINGLE_QUOTED_STRING, BuckTypes.DOUBLE_QUOTED_STRING);
  // isQuotedString will be true if the caret is under the left quote, the right quote,
  // or anywhere in between. But pasting with caret under the left quote acts differently than
  // pasting in other isQuotedString positions: Text will be inserted before the quotes, not
  // inside them
  boolean inQuotedString = false;
  if (isQuotedString) {
    inQuotedString =
        element instanceof TreeElement
            && ((TreeElement) element).getStartOffset() < selectionStart;
  }
  if (isQuotedString || BuckPsiUtils.hasElementType(elementNode, TokenType.WHITE_SPACE)) {
    if (inQuotedString) {
      // We want to impose the additional requirement that the string is currently empty. That is,
      // if you are pasting into an existing target, we don't want to process the paste text.
      String elementText = elementNode.getText().trim();
      if (!(elementText.equals("''") || elementText.equals("\"\""))) {
        return text;
      }
    }

    PsiElement property = BuckPsiUtils.findAncestorWithType(element, BuckTypes.PROPERTY);
    if (checkPropertyName(property)) {
      return formatPasteText(text, element, project, inQuotedString);
    }
  }
  return text;
}
项目:intellij-ce-playground    文件:CopyPastePreProcessor.java   
/**
 * Replaces pasted text. <code>text</code> value should be returned if no processing is required.
 */
@NotNull
String preprocessOnPaste(final Project project, final PsiFile file, final Editor editor, String text, final RawText rawText);
项目:tools-idea    文件:CopyPastePreProcessor.java   
String preprocessOnPaste(final Project project, final PsiFile file, final Editor editor, String text, final RawText rawText);
项目:consulo    文件:CopyPastePreProcessor.java   
String preprocessOnPaste(final Project project, final PsiFile file, final Editor editor, String text, final RawText rawText);