本文整理匯總了Java中com.intellij.openapi.editor.Document類的典型用法代碼示例。如果您正苦於以下問題:Java Document類的具體用法?Java Document怎麽用?Java Document使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Document類屬於com.intellij.openapi.editor包,在下文中一共展示了Document類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildLookup
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
@NotNull
private LookupElementBuilder buildLookup(PhpClassMember field, PhpExpression position, boolean autoValue) {
String lookupString = field instanceof Method ? ClassUtils.getAsPropertyName((Method) field) : field.getName();
LookupElementBuilder builder = LookupElementBuilder.create(field, lookupString).withIcon(field.getIcon());
if (autoValue) {
builder = builder.withInsertHandler((insertionContext, lookupElement) -> {
Document document = insertionContext.getDocument();
int insertPosition = insertionContext.getSelectionEndOffset();
if (position.getParent().getParent() instanceof ArrayCreationExpression) {
document.insertString(insertPosition + 1, " => ");
insertPosition += 5;
insertionContext.getEditor().getCaretModel().getCurrentCaret().moveToOffset(insertPosition);
}
});
}
if (field instanceof Field) {
builder = builder.withTypeText(field.getType().toString());
}
return builder;
}
示例2: buildLookup
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
@NotNull
private LookupElementBuilder buildLookup(PhpClassMember field, PhpExpression position) {
String lookupString = field instanceof Method ? ClassUtils.getAsPropertyName((Method) field) : field.getName();
LookupElementBuilder builder = LookupElementBuilder.create(field, lookupString).withIcon(field.getIcon())
.withInsertHandler((insertionContext, lookupElement) -> {
Document document = insertionContext.getDocument();
int insertPosition = insertionContext.getSelectionEndOffset();
if (position.getParent().getParent() instanceof ArrayCreationExpression) {
document.insertString(insertPosition + 1, " => ");
insertPosition += 5;
insertionContext.getEditor().getCaretModel().getCurrentCaret().moveToOffset(insertPosition);
}
});
if (field instanceof Field) {
builder = builder.withTypeText(field.getType().toString());
}
return builder;
}
示例3: unquoteAll
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
public static void unquoteAll(@NotNull Project project, @NotNull PsiFile psiFile) {
try {
Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
List<Integer> quotePositions = new ArrayList<>();
Collection<PsiElement> fields = getAllFields(psiFile);
for (PsiElement field : fields) {
if (getChildren(field).stream().anyMatch(element -> getElementType(element) == CsvTypes.ESCAPED_TEXT)) {
continue;
}
if (getElementType(field.getFirstChild()) == CsvTypes.QUOTE) {
quotePositions.add(field.getFirstChild().getTextOffset());
}
if (getElementType(field.getLastChild()) == CsvTypes.QUOTE) {
quotePositions.add(field.getLastChild().getTextOffset());
}
}
String text = removeQuotes(document.getText(), quotePositions);
document.setText(text);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
示例4: buildFoldRegions
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
List<FoldingDescriptor> descriptors = new ArrayList<>();
PsiTreeUtil.processElements(root, element -> {
IElementType elementType = element.getNode().getElementType();
MlTypes types = elementType.getLanguage() == RmlLanguage.INSTANCE ? RmlTypes.INSTANCE : OclTypes.INSTANCE;
if (types.COMMENT == elementType) {
FoldingDescriptor fold = fold(element);
if (fold != null) {
descriptors.add(fold);
}
} else if (types.TYPE_EXPRESSION == elementType) {
foldType(descriptors, (PsiType) element);
} else if (types.LET_EXPRESSION == elementType) {
foldLet(descriptors, (PsiLet) element);
} else if (types.MODULE_EXPRESSION == elementType) {
foldModule(descriptors, (PsiModule) element);
}
return true;
});
return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
示例5: buildFoldRegions
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
FoldingGroup group = FoldingGroup.newGroup("TYPO3Route");
List<FoldingDescriptor> descriptors = new ArrayList<>();
Collection<StringLiteralExpression> literalExpressions = PsiTreeUtil.findChildrenOfType(root, StringLiteralExpression.class);
for (final StringLiteralExpression literalExpression : literalExpressions) {
for (PsiReference reference : literalExpression.getReferences()) {
if (reference instanceof RouteReference) {
String value = literalExpression.getContents();
FoldingDescriptor descriptor = foldRouteReferenceString(reference, value, group);
if (descriptor != null) {
descriptors.add(descriptor);
}
}
}
}
return descriptors.toArray(new FoldingDescriptor[descriptors.size()]);
}
示例6: buildFoldRegions
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(
@NotNull final PsiElement root,
@NotNull final Document document,
final boolean quick
) {
if (!(root instanceof BladeFileImpl)) {
return FoldingDescriptor.EMPTY.clone();
}
final Queue<BladePsiDirective> directives = new LinkedBlockingQueue(Arrays.asList(((BladeFileImpl) root).getDirectives()));
final List<FoldingDescriptor> foldingDescriptors = new ArrayList<>();
processDirectives(null, directives, foldingDescriptors, document);
return foldingDescriptors.toArray(new FoldingDescriptor[foldingDescriptors.size()]);
}
示例7: unquoteValue
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
public static void unquoteValue(@NotNull Project project, @NotNull PsiElement element) {
try {
Document document = PsiDocumentManager.getInstance(project).getDocument(element.getContainingFile());
List<Integer> quotePositions = new ArrayList<>();
element = getParentFieldElement(element);
if (getElementType(element.getFirstChild()) == CsvTypes.QUOTE) {
quotePositions.add(element.getFirstChild().getTextOffset());
}
if (getElementType(element.getLastChild()) == CsvTypes.QUOTE) {
quotePositions.add(element.getLastChild().getTextOffset());
}
String text = removeQuotes(document.getText(), quotePositions);
document.setText(text);
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
示例8: generateGherkinRunIcons
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
public void generateGherkinRunIcons(Document rootDocument, Editor rootEditor) {
for (int i = 0; i < rootDocument.getLineCount(); i++) {
int startOffset = rootDocument.getLineStartOffset(i);
int endOffset = rootDocument.getLineEndOffset(i);
String lineText = rootDocument.getText(new TextRange(startOffset, endOffset)).trim();
Icon icon;
if (lineText.matches(SCENARIO_REGEX)) {
icon = GherkinIconRenderer.SCENARIO_ICON;
} else if (lineText.matches(FEATURE_REGEX)) {
icon = GherkinIconRenderer.FEATURE_ICON;
} else {
// System.out.println();
continue;
}
GherkinIconRenderer gherkinIconRenderer = new GherkinIconRenderer(rootEditor.getProject(), fileName);
gherkinIconRenderer.setLine(i);
gherkinIconRenderer.setIcon(icon);
RangeHighlighter rangeHighlighter = createRangeHighlighter(rootDocument, rootEditor, i, i, new TextAttributes());
rangeHighlighter.setGutterIconRenderer(gherkinIconRenderer);
}
}
示例9: getQuickNavigateInfo
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
@Nullable
@Override
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
Document document =
FileDocumentManager.getInstance().getDocument(element.getContainingFile().getVirtualFile());
if (document == null) return "";
int lineNum = document.getLineNumber(element.getTextOffset()) + 1 /* count starts at zero */;
String path = element.getContainingFile().getVirtualFile().getName();
StringBuilder navigateInfo = new StringBuilder("Defined at ");
navigateInfo.append(path);
navigateInfo.append(":");
navigateInfo.append(lineNum);
String optDoc = getDocCommentForEnclosingTag(element);
if (optDoc != null) {
navigateInfo.append("\n");
navigateInfo.append(produceCommentPreview(optDoc));
}
return navigateInfo.toString();
}
示例10: insertClosingTag
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
private static void insertClosingTag(@NotNull Editor editor, int offset, String tag) {
Document document = editor.getDocument();
CharSequence charSequence = document.getImmutableCharSequence();
int startPosition = offset - 2;
// Consume second left brace if present.
if (offset > 0 && charSequence.charAt(startPosition - 1) == '{') {
startPosition--;
}
int endPosition = offset;
// Consume at most 2 right braces if present.
while (endPosition < charSequence.length()
&& charSequence.charAt(endPosition) == '}'
&& endPosition < offset + 2) {
endPosition++;
}
editor.getDocument().replaceString(startPosition, endPosition, tag);
editor.getCaretModel().moveToOffset(startPosition + tag.length());
}
示例11: handleEnterInComment
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
private static void handleEnterInComment(
PsiElement element, @NotNull PsiFile file, @NotNull Editor editor) {
if (element.getText().startsWith("/*")) {
Document document = editor.getDocument();
int caretOffset = editor.getCaretModel().getOffset();
int lineNumber = document.getLineNumber(caretOffset);
String lineTextBeforeCaret =
document.getText(new TextRange(document.getLineStartOffset(lineNumber), caretOffset));
String lineTextAfterCaret =
document.getText(new TextRange(caretOffset, document.getLineEndOffset(lineNumber)));
if (lineTextAfterCaret.equals("*/")) {
return;
}
String toInsert = lineTextBeforeCaret.equals("") ? " * " : "* ";
insertText(file, editor, toInsert, toInsert.length());
}
}
示例12: postProcessEnter
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
@Override
public Result postProcessEnter(
@NotNull PsiFile file, @NotNull Editor editor, @NotNull DataContext dataContext) {
if (file.getFileType() != SoyFileType.INSTANCE) {
return Result.Continue;
}
int caretOffset = editor.getCaretModel().getOffset();
PsiElement element = file.findElementAt(caretOffset);
Document document = editor.getDocument();
int lineNumber = document.getLineNumber(caretOffset) - 1;
int lineStartOffset = document.getLineStartOffset(lineNumber);
String lineTextBeforeCaret = document.getText(new TextRange(lineStartOffset, caretOffset));
if (element instanceof PsiComment && element.getTextOffset() < caretOffset) {
handleEnterInComment(element, file, editor);
} else if (lineTextBeforeCaret.startsWith("/*")) {
insertText(file, editor, " * \n ", 3);
}
return Result.Continue;
}
示例13: actionPerformed
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
dialog.show();
int exitCode = dialog.getExitCode();
if (exitCode != CANCEL_EXIT_CODE) {
String key = dialog.getKeyText();
String value = dialog.getValueText();
currentLang = dialog.getSelectedLangauge();
if (currentLang != null && !currentLang.isEmpty()) {
Editor ieditor = editorMap.get(currentLang);
Document document = ieditor.getDocument();
WriteCommandAction.runWriteCommandAction(fileEditor.getProject(), () -> updateDocumentHook(document, ieditor.getProject(), currentLang, key, value, model));
} else {
NotificationHelper.showBaloon("No language file available", MessageType.WARNING, fileEditor.getProject());
}
}
}
示例14: findDocument
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
private Document findDocument()
{
Editor editor = ResourceToManifoldUtil.getActiveEditor( getProject() );
if( editor instanceof EditorImpl )
{
EditorImpl editorImpl = (EditorImpl)editor;
if( editorImpl.getVirtualFile().getPath().equals( _file.getVirtualFile().getPath() ) )
{
// get document from current editor
return editorImpl.getDocument();
}
}
// get document from file
return _file.getViewProvider().getDocument();
}
示例15: actionPerformed
import com.intellij.openapi.editor.Document; //導入依賴的package包/類
/**
* Inserts the string generated by {@link #generateString()} at the caret(s) in the editor.
*
* @param event the performed action
*/
@Override
public final void actionPerformed(final AnActionEvent event) {
final Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor == null) {
return;
}
final Project project = event.getData(CommonDataKeys.PROJECT);
final Document document = editor.getDocument();
final CaretModel caretModel = editor.getCaretModel();
final Runnable replaceCaretSelections = () -> caretModel.getAllCarets().forEach(caret -> {
final int start = caret.getSelectionStart();
final int end = caret.getSelectionEnd();
final String string = generateString();
final int newEnd = start + string.length();
document.replaceString(start, end, string);
caret.setSelection(start, newEnd);
});
WriteCommandAction.runWriteCommandAction(project, replaceCaretSelections);
}