本文整理汇总了Java中org.eclipse.xtext.ui.editor.XtextEditor.getDocument方法的典型用法代码示例。如果您正苦于以下问题:Java XtextEditor.getDocument方法的具体用法?Java XtextEditor.getDocument怎么用?Java XtextEditor.getDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.ui.editor.XtextEditor
的用法示例。
在下文中一共展示了XtextEditor.getDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newValidationJob
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
private ValidationJob newValidationJob(final XtextEditor editor) {
final IXtextDocument document = editor.getDocument();
final IAnnotationModel annotationModel = editor.getInternalSourceViewer().getAnnotationModel();
final IssueResolutionProvider issueResolutionProvider = getService(editor, IssueResolutionProvider.class);
final MarkerTypeProvider markerTypeProvider = getService(editor, MarkerTypeProvider.class);
final MarkerCreator markerCreator = getService(editor, MarkerCreator.class);
final IValidationIssueProcessor issueProcessor = new CompositeValidationIssueProcessor(
new AnnotationIssueProcessor(document, annotationModel, issueResolutionProvider),
new MarkerIssueProcessor(editor.getResource(), markerCreator, markerTypeProvider));
return editor.getDocument().modify(resource -> {
final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
return new ValidationJob(resourceValidator, editor.getDocument(), issueProcessor, ALL);
});
}
示例2: install
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
/**
* Install this reconciler on the given editor and presenter.
*
* @param editor
* the editor
* @param sourceViewer
* the source viewer
* @param presenter
* the highlighting presenter
*/
@Override
public void install(final XtextEditor editor, final XtextSourceViewer sourceViewer, final HighlightingPresenter presenter) {
synchronized (fReconcileLock) {
cleanUpAfterReconciliation = false; // prevents a potentially already running reconciliation process to clean up after itself
}
this.presenter = presenter;
this.editor = editor;
this.sourceViewer = sourceViewer;
if (calculator != null) {
if (editor == null) {
((IXtextDocument) sourceViewer.getDocument()).addModelListener(this);
} else if (editor.getDocument() != null) {
editor.getDocument().addModelListener(this);
}
sourceViewer.addTextInputListener(this);
}
refresh();
}
示例3: execute
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
public Object execute(final ExecutionEvent event) throws ExecutionException {
final XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
if (xtextEditor != null) {
final IXtextDocument document = xtextEditor.getDocument();
document.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
final QuickOutlinePopup quickOutlinePopup = createPopup(xtextEditor.getEditorSite().getShell());
quickOutlinePopup.setEditor(xtextEditor);
quickOutlinePopup.setInput(document);
quickOutlinePopup.setEvent((Event) event.getTrigger());
quickOutlinePopup.open();
}
});
}
return null;
}
示例4: selectionChanged
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (part instanceof XtextEditor && !selection.isEmpty()) {
final XtextEditor editor = (XtextEditor) part;
final IXtextDocument document = editor.getDocument();
document.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource resource) throws Exception {
IParseResult parseResult = resource.getParseResult();
if (parseResult != null) {
ICompositeNode root = parseResult.getRootNode();
EObject taxonomy = NodeModelUtils.findActualSemanticObjectFor(root);
if (taxonomy instanceof Model) {
ModelRegistryPlugin.getModelRegistry().setActiveTaxonomy((Model) taxonomy);
}
}
}
});
}
}
示例5: partActivated
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
@Override
public void partActivated(final IWorkbenchPart part) {
if (part instanceof XtextEditor) {
XtextEditor xtextEditor = (XtextEditor) part;
IXtextDocument xtextDocument = xtextEditor.getDocument();
if (xtextDocument != lastActiveDocument) {
selectionLinker.setXtextEditor(xtextEditor);
final IFigure contents = xtextDocument.readOnly(new IUnitOfWork<IFigure, XtextResource>() {
@Override
public IFigure exec(final XtextResource resource) throws Exception {
return createFigure(resource);
}
});
if (contents != null) {
view.setContents(contents);
if (lastActiveDocument != null) {
lastActiveDocument.removeModelListener(this);
}
lastActiveDocument = xtextDocument;
lastActiveDocument.addModelListener(this);
}
}
}
}
示例6: getXtextDocument
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
public ICoreXtextDocument getXtextDocument(final URI uri) {
// On UI threads make use of the editor
if (Display.getCurrent() != null) {
IEditorPart editor = editorOpener.open(uri, false);
if (editor instanceof XtextEditor) {
XtextEditor xtextEditor = (XtextEditor) editor;
return new XtextDocumentAdapter(xtextEditor.getDocument());
}
return null;
}
// Otherwise load the resource and create a new document for it
return modificationContext.getXtextDocument(uri);
}
示例7: getXtextDocument
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
public IXtextDocument getXtextDocument(URI uri) {
IEditorPart editor = editorOpener.open(uri, false);
if (editor instanceof XtextEditor) {
XtextEditor xtextEditor = (XtextEditor) editor;
return xtextEditor.getDocument();
}
return null;
}
示例8: getEntry
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
protected Pair<URI, IXtextDocument> getEntry(IWorkbenchPartReference partRef) {
IWorkbenchPart part = partRef.getPart(false);
if (part instanceof XtextEditor) {
XtextEditor xtextEditor = (XtextEditor) part;
URI resourceURI = getResourceURI(xtextEditor);
IXtextDocument document = xtextEditor.getDocument();
if (resourceURI != null && document != null)
return Tuples.create(resourceURI, document);
}
return null;
}
示例9: install
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
/**
* Install this reconciler on the given editor and presenter.
*
* @param editor
* the editor
* @param sourceViewer
* the source viewer
* @param presenter
* the highlighting presenter
*/
public void install(XtextEditor editor, XtextSourceViewer sourceViewer, HighlightingPresenter presenter) {
this.presenter = presenter;
this.editor = editor;
this.sourceViewer = sourceViewer;
if (calculator != null) {
if(editor == null){
((IXtextDocument) sourceViewer.getDocument()).addModelListener(this);
} else if (editor.getDocument() != null)
editor.getDocument().addModelListener(this);
sourceViewer.addTextInputListener(this);
}
refresh();
}
示例10: createLinkedGroupFromReplaceEdits
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
protected LinkedPositionGroup createLinkedGroupFromReplaceEdits(List<ReplaceEdit> edits, XtextEditor xtextEditor,
final String originalName, SubMonitor progress) {
if (edits == null)
return null;
final IXtextDocument document = xtextEditor.getDocument();
LinkedPositionGroup group = new LinkedPositionGroup();
Iterable<LinkedPosition> linkedPositions = filter(
Iterables.transform(edits, new Function<ReplaceEdit, LinkedPosition>() {
public LinkedPosition apply(ReplaceEdit edit) {
try {
String textToReplace = document.get(edit.getOffset(), edit.getLength());
int indexOf = textToReplace.indexOf(originalName);
if (indexOf != -1) {
int calculatedOffset = edit.getOffset() + indexOf;
return new LinkedPosition(document, calculatedOffset, originalName.length());
}
} catch (BadLocationException exc) {
LOG.error("Skipping invalid text edit " + notNull(edit), exc);
}
return null;
}
}), Predicates.notNull());
progress.worked(10);
final int invocationOffset = xtextEditor.getInternalSourceViewer().getSelectedRange().x;
int i = 0;
for (LinkedPosition position : sortPositions(linkedPositions, invocationOffset)) {
try {
position.setSequenceNumber(i);
i++;
group.addPosition(position);
} catch (BadLocationException e) {
LOG.error(e.getMessage(), e);
return null;
}
}
return group;
}
示例11: afterCreatePartControl
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
@Override
public void afterCreatePartControl(XtextEditor editor) {
super.afterCreatePartControl(editor);
addKeyListener(editor);
xtextEditor = (CommonXtextEditor) editor;
editorDocument = editor.getDocument();
}
示例12: run
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
public void run(IAction action) {
IEditorPart editor = window.getActivePage().getActiveEditor();
if (!(editor instanceof XtextEditor)) {
MessageDialog.openError(window.getShell(), "Error",
"This command is only valid for spear files");
}
XtextEditor xtextEditor = (XtextEditor) editor;
IXtextDocument document = xtextEditor.getDocument();
document.readOnly(new IUnitOfWork<Void, XtextResource>() {
public java.lang.Void exec(XtextResource state) throws Exception {
if(!(state.getContents().get(0) instanceof Procedure)) {
MessageDialog.openError(window.getShell(), "Error",
"Translation can only be done on procedures.");
return null;
}
Procedure file = (Procedure) state.getContents().get(0);
if(hasErrors(file.eResource()))
{
MessageDialog.openError(window.getShell(), "Error",
"Translation can only be done on well-formed specifications.");
return null;
}
String string = Operations.translate(file);
URI uri = file.eResource().getURI();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile ofile = root.getFile(new Path(uri.appendFileExtension("lus").toPlatformString(true)));
FileOutputStream fout = new FileOutputStream(ofile.getLocation().toOSString());
fout.write(string.getBytes());
ofile.refreshLocal(IResource.DEPTH_INFINITE, null);
fout.close();
return null;
}
});
}
示例13: run
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
@Override
public void run(IAction action) {
IEditorPart editor = window.getActivePage().getActiveEditor();
if (!(editor instanceof XtextEditor)) {
MessageDialog.openError(window.getShell(), "Error",
"This command is only valid for spear files");
return;
}
XtextEditor xtextEditor = (XtextEditor) editor;
IXtextDocument document = xtextEditor.getDocument();
document.readOnly(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(XtextResource state) throws Exception {
if(!(state.getContents().get(0) instanceof Procedure)) {
MessageDialog.openError(window.getShell(), "Error",
"Reasoning can only be done on procedures.");
return null;
}
Procedure file = (Procedure) state.getContents().get(0);
if (hasErrors(file.eResource())) {
MessageDialog.openError(window.getShell(), "Error",
"Reasoning can only be done on well-formed specifications.");
return null;
}
Layout spearLayout = new SpearLayout(file);
//page showview has to be set before setting the layout, else NPE
JKindResultsView page = (JKindResultsView) window.getActivePage().showView(JKindResultsView.ID);
page.setLayout(spearLayout);
Operations.reason(file, page);
return null;
}
});
}
示例14: testEntitiesEditorContents
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
@Test
public void testEntitiesEditorContents() {
try {
IFile _createTestFile = this.createTestFile("entity E {}");
XtextEditor _openEditor = this.openEditor(_createTestFile);
IXtextDocument _document = _openEditor.getDocument();
String _get = _document.get();
Assert.assertEquals("entity E {}", _get);
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
示例15: updateMelange
import org.eclipse.xtext.ui.editor.XtextEditor; //导入方法依赖的package包/类
protected void updateMelange(ExecutionEvent event, Language language, String xtextPath){
// Compute offset & new string
int startOffset = -1;
int length = -1;
String newRegion = null;
EStructuralFeature xtext = language.eClass().getEStructuralFeature("xtext");
List<INode> nodesXtext = NodeModelUtils.findNodesForFeature(language, xtext);
if(!nodesXtext.isEmpty()){
INode nodeXtext = nodesXtext.get(0);
startOffset = nodeXtext.getOffset();
length = nodeXtext.getLength();
newRegion = "\""+xtextPath+"\"";
}
else{//insert after operators
EStructuralFeature operators = language.eClass().getEStructuralFeature("operators");
List<INode> nodesOp = NodeModelUtils.findNodesForFeature(language, operators);
int lastOffset = -1;
for(INode node : nodesOp){
if(node.getEndOffset() > lastOffset) lastOffset = node.getEndOffset();
}
if(lastOffset != -1){
startOffset = lastOffset;
length = 0;
newRegion = "\n\n\txtext \""+xtextPath+"\"";
}
}
// Replace in document or Melange file
if(startOffset != -1 && length != -1 && newRegion != null){
int _startOffset = startOffset;
int _length = length;
String _newRegion = newRegion;
XtextEditor editor = EditorUtils.getActiveXtextEditor();
if (editor != null && editor.getLanguageName().equals(MELANGE_EDITOR)) { //Update the editor content
IXtextDocument document = editor.getDocument();
document.modify((XtextResource it) -> {
document.replace(_startOffset,_length, _newRegion);
return null; // no computed value
});
}
else{ //Update the Melange file content
try {
//Load Melange file
String melangeWSLocation = language.eResource().getURI().toPlatformString(true);
URI uri = language.eResource().getURI();
String melangeLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()+melangeWSLocation;
List<String> lines = Files.readAllLines(Paths.get(melangeLocation));
StringBuffer newContent = new StringBuffer();
lines.forEach(
line -> newContent.append(line+"\n")
);
newContent.replace(startOffset,startOffset+length, newRegion);
//Write new content
Files.write(Paths.get(melangeLocation), newContent.toString().getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}
}