use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class TextChange method getCurrentDocument.
//---- Method to access the current content of the text change ---------
/**
* Returns the document this text change is associated to. The
* document returned is computed at the point in time when this
* method is called. So calling this method multiple times may
* return different document instances.
* <p>
* The returned document must not be modified by the client. Doing
* so will result in an unexpected behavior when the change is
* performed.
* </p>
*
* @param pm a progress monitor to report progress or <code>null</code>
* if no progress reporting is desired
* @return the document this change is working on
*
* @throws CoreException if the document can't be acquired
*/
public IDocument getCurrentDocument(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
IDocument result = null;
//$NON-NLS-1$
pm.beginTask("", 2);
try {
result = acquireDocument(new SubProgressMonitor(pm, 1));
} finally {
if (result != null)
releaseDocument(result, new SubProgressMonitor(pm, 1));
}
pm.done();
return result;
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class SearchManager method performFindUsageSearch.
private FindUsagesResponse performFindUsageSearch(IJavaElement element) throws JavaModelException, BadLocationException {
JavaSearchScopeFactory factory = JavaSearchScopeFactory.getInstance();
boolean isInsideJRE = factory.isInsideJRE(element);
JavaSearchQuery query = new JavaSearchQuery(new ElementQuerySpecification(element, IJavaSearchConstants.REFERENCES, factory.createWorkspaceScope(isInsideJRE), "workspace scope"));
NewSearchUI.runQueryInForeground(null, query);
ISearchResult result = query.getSearchResult();
JavaSearchResult javaResult = ((JavaSearchResult) result);
FindUsagesResponse response = DtoFactory.newDto(FindUsagesResponse.class);
Map<String, List<org.eclipse.che.ide.ext.java.shared.dto.search.Match>> mapMaches = new HashMap<>();
JavaElementToDtoConverter converter = new JavaElementToDtoConverter(javaResult);
for (Object o : javaResult.getElements()) {
IJavaElement javaElement = (IJavaElement) o;
IDocument document = null;
if (javaElement instanceof IMember) {
IMember member = ((IMember) javaElement);
if (member.isBinary()) {
if (member.getClassFile().getSource() != null) {
document = new Document(member.getClassFile().getSource());
}
} else {
document = getDocument(member.getCompilationUnit());
}
} else if (javaElement instanceof IPackageDeclaration) {
ICompilationUnit ancestor = (ICompilationUnit) (javaElement).getAncestor(IJavaElement.COMPILATION_UNIT);
document = getDocument(ancestor);
}
converter.addElementToProjectHierarchy(javaElement);
Match[] matches = javaResult.getMatches(o);
List<org.eclipse.che.ide.ext.java.shared.dto.search.Match> matchList = new ArrayList<>();
for (Match match : matches) {
org.eclipse.che.ide.ext.java.shared.dto.search.Match dtoMatch = DtoFactory.newDto(org.eclipse.che.ide.ext.java.shared.dto.search.Match.class);
if (document != null) {
IRegion lineInformation = document.getLineInformationOfOffset(match.getOffset());
int offsetInLine = match.getOffset() - lineInformation.getOffset();
Region matchInLine = DtoFactory.newDto(Region.class).withOffset(offsetInLine).withLength(match.getLength());
dtoMatch.setMatchInLine(matchInLine);
dtoMatch.setMatchLineNumber(document.getLineOfOffset(match.getOffset()));
dtoMatch.setMatchedLine(document.get(lineInformation.getOffset(), lineInformation.getLength()));
}
dtoMatch.setFileMatchRegion(DtoFactory.newDto(Region.class).withOffset(match.getOffset()).withLength(match.getLength()));
matchList.add(dtoMatch);
}
mapMaches.put(javaElement.getHandleIdentifier(), matchList);
}
List<JavaProject> projects = converter.getProjects();
response.setProjects(projects);
response.setMatches(mapMaches);
response.setSearchElementLabel(JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT));
return response;
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class SearchManager method getDocument.
private IDocument getDocument(ICompilationUnit ancestor) throws JavaModelException {
IDocument document;
IBuffer buffer = ancestor.getBuffer();
if (buffer instanceof org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) {
document = ((org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) buffer).getDocument();
} else {
document = new DocumentAdapter(buffer);
}
return document;
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class CompletionJavadocTest method computeProposals.
private static List<ICompletionProposal> computeProposals(ICompilationUnit compilationUnit, int offset) throws JavaModelException {
IBuffer buffer = compilationUnit.getBuffer();
IDocument document;
if (buffer instanceof org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) {
document = ((org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter) buffer).getDocument();
} else {
document = new DocumentAdapter(buffer);
}
TextViewer viewer = new TextViewer(document, new Point(offset, 0));
JavaContentAssistInvocationContext context = new JavaContentAssistInvocationContext(viewer, offset, compilationUnit);
List<ICompletionProposal> proposals = new ArrayList<>();
proposals.addAll(new JavaAllCompletionProposalComputer().computeCompletionProposals(context, null));
// proposals.addAll(new TemplateCompletionProposalComputer().computeCompletionProposals(context, null));
Collections.sort(proposals, new RelevanceSorter());
return proposals;
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class FileStoreTextFileBuffer method revert.
/*
* @see org.eclipse.core.filebuffers.IFileBuffer#revert(org.eclipse.core.runtime.IProgressMonitor)
*/
public void revert(IProgressMonitor monitor) throws CoreException {
if (isDisconnected())
return;
IDocument original = null;
fStatus = null;
try {
original = fManager.createEmptyDocument(getLocationOrName(), LocationKind.LOCATION);
cacheEncodingState();
setDocumentContent(original, fFileStore, fEncoding, fHasBOM, monitor);
} catch (CoreException x) {
fStatus = x.getStatus();
}
if (original == null)
return;
String originalContents = original.get();
boolean replaceContents = !originalContents.equals(fDocument.get());
if (!replaceContents && !fCanBeSaved)
return;
fManager.fireStateChanging(this);
try {
if (replaceContents) {
fManager.fireBufferContentAboutToBeReplaced(this);
fDocument.set(original.get());
}
boolean fireDirtyStateChanged = fCanBeSaved;
if (fCanBeSaved) {
fCanBeSaved = false;
addFileBufferContentListeners();
}
if (replaceContents)
fManager.fireBufferContentReplaced(this);
IFileInfo info = fFileStore.fetchInfo();
if (info.exists())
fSynchronizationStamp = fFileStore.fetchInfo().getLastModified();
if (fireDirtyStateChanged)
fManager.fireDirtyStateChanged(this, fCanBeSaved);
} catch (RuntimeException x) {
fManager.fireStateChangeFailed(this);
throw x;
}
}
Aggregations