use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class ShowQuickOutlineActionHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final XtextEditor xtextEditor = EditorUtils.getActiveXtextEditor(event);
if (xtextEditor != null) {
final IXtextDocument document = xtextEditor.getDocument();
document.priorityReadOnly(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);
if (event.getTrigger() != null) {
quickOutlinePopup.setEvent((Event) event.getTrigger());
}
quickOutlinePopup.open();
}
});
}
return null;
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class OrganizeImportsHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
XtextEditor editor = EditorUtils.getActiveXtextEditor(event);
if (editor != null) {
final IXtextDocument document = editor.getDocument();
doOrganizeImports(document);
}
return null;
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class JavaTypeQuickfixes method createConstructorProposals.
@SuppressWarnings("restriction")
protected boolean createConstructorProposals(final JvmDeclaredType contextType, final Issue issue, String typeName, IJavaSearchScope searchScope, final IssueResolutionAcceptor acceptor) throws JavaModelException {
final boolean[] result = new boolean[] { false };
if (contextType != null) {
final IVisibilityHelper visibilityHelper = getVisibilityHelper(contextType);
final Pair<String, String> packageAndType = typeNameGuesser.guessPackageAndTypeName(contextType, typeName);
final String wantedPackageName = packageAndType.getFirst();
final String wantedTypeName = packageAndType.getSecond();
if (typeName.endsWith(wantedTypeName)) {
return false;
}
org.eclipse.jdt.internal.core.search.BasicSearchEngine searchEngine = new org.eclipse.jdt.internal.core.search.BasicSearchEngine();
final char[] wantedPackageChars = (isEmpty(wantedPackageName)) ? null : wantedPackageName.toCharArray();
searchEngine.searchAllTypeNames(wantedPackageChars, SearchPattern.R_EXACT_MATCH, wantedTypeName.toCharArray(), SearchPattern.R_EXACT_MATCH, IJavaSearchConstants.TYPE, searchScope, new org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor() {
@Override
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, org.eclipse.jdt.internal.compiler.env.AccessRestriction access) {
final String qualifiedTypeName = getQualifiedTypeName(packageName, enclosingTypeNames, simpleTypeName);
if (access == null || (access.getProblemId() != IProblem.ForbiddenReference && !access.ignoreIfBetter())) {
JvmType importType = services.getTypeReferences().findDeclaredType(qualifiedTypeName, contextType);
if (importType instanceof JvmDeclaredType && visibilityHelper.isVisible((JvmDeclaredType) importType)) {
result[0] = true;
StringBuilder label = new StringBuilder("Change to constructor call 'new ");
label.append(simpleTypeName);
label.append("()'");
if (!equal(wantedPackageName, new String(packageName))) {
label.append(" (");
label.append(packageName);
if (enclosingTypeNames.length > 0) {
for (char[] enclosingTypeName : enclosingTypeNames) {
label.append(".");
label.append(enclosingTypeName);
}
}
label.append(")");
}
acceptor.accept(issue, label.toString(), label.toString(), "impc_obj.gif", new ISemanticModification() {
@Override
public void apply(EObject element, IModificationContext context) throws Exception {
IXtextDocument document = context.getXtextDocument();
DocumentRewriter rewriter = rewriterFactory.create(document, (XtextResource) element.eResource());
final int typeEndOffset = document.get().indexOf(wantedTypeName, issue.getOffset() + wantedPackageName.length()) + wantedTypeName.length();
final Section section = rewriter.newSection(issue.getOffset(), typeEndOffset - issue.getOffset());
section.append(services.getTypeReferences().findDeclaredType(qualifiedTypeName, element));
section.append("()");
final TextEdit textEdit = replaceConverter.convertToTextEdit(rewriter.getChanges());
textEdit.apply(document);
}
}, jdtTypeRelevance.getRelevance(qualifiedTypeName, wantedTypeName) + 100);
}
}
}
}, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
}
return result[0];
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-eclipse by eclipse.
the class XbaseDispatchingEObjectTextHover method getHoverRegion.
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
IXtextDocument xtextDocument = xtextDocumentUtil.getXtextDocument(textViewer);
if (xtextDocument == null || offset < 0 || xtextDocument.getLength() < offset)
return null;
@SuppressWarnings("restriction") IRegion word = org.eclipse.jdt.internal.ui.text.JavaWordFinder.findWord(xtextDocument, offset);
if (word != null)
return word;
// TODO return null for non-operators.
return new Region(offset, 0);
}
use of org.eclipse.xtext.ui.editor.model.IXtextDocument in project xtext-xtend by eclipse.
the class XtendFoldingRegionProviderTest method openFileAndReturnDocument.
protected IXtextDocument openFileAndReturnDocument(IFile iFile) throws Exception {
XtextEditor editor = testHelper.openEditor(iFile);
IXtextDocument document = editor.getDocument();
return document;
}
Aggregations