use of org.eclipse.jface.text.IDocument in project KaiZen-OpenAPI-Editor by RepreZen.
the class TextDocumentMarkerResolution method run.
public void run(IMarker marker) {
try {
IResource resource = marker.getResource();
if (resource.getType() != IResource.FILE) {
throw new CoreException(createStatus(null, "The editor is not a File: " + resource.getName()));
}
IFile file = (IFile) resource;
ITextEditor editor = openTextEditor(file);
IDocument document = editor.getDocumentProvider().getDocument(new FileEditorInput(file));
if (document == null) {
throw new CoreException(createStatus(null, "The document is null"));
}
IRegion region = processFix(document, marker);
if (region != null) {
editor.selectAndReveal(region.getOffset(), region.getLength());
}
} catch (CoreException e) {
Activator.getDefault().getLog().log(e.getStatus());
}
}
use of org.eclipse.jface.text.IDocument in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonDocumentProvider method createDocument.
@Override
protected IDocument createDocument(Object element) throws CoreException {
IDocument document = super.createDocument(element);
if (document != null) {
JsonScanner scanner = new JsonScanner(new ColorManager(), store);
Set<String> tokens = YAMLToken.VALID_TOKENS.keySet();
FastPartitioner partitioner = new FastPartitioner(scanner, tokens.toArray(new String[tokens.size()]));
document.setDocumentPartitioner(partitioner);
partitioner.connect(document);
}
return document;
}
use of org.eclipse.jface.text.IDocument in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonEditor method validate.
private void validate(boolean onOpen) {
IEditorInput editorInput = getEditorInput();
final IDocument document = getDocumentProvider().getDocument(getEditorInput());
// such files.
if (!(editorInput instanceof IFileEditorInput)) {
YEditLog.logError("Marking errors not supported for files outside of a project.");
YEditLog.logger.info("editorInput is not a part of a project.");
return;
}
if (document instanceof JsonDocument) {
final IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
final IFile file = fileEditorInput.getFile();
if (onOpen) {
// force parsing of yaml to init parsing errors
((JsonDocument) document).onChange();
}
clearMarkers(file);
validateYaml(file, (JsonDocument) document);
validateSwagger(file, (JsonDocument) document, fileEditorInput);
}
}
use of org.eclipse.jface.text.IDocument in project tdi-studio-se by Talend.
the class ReconcilerViewer method getAllSnippetsAnnotations.
private Map<ProjectionAnnotation, Position> getAllSnippetsAnnotations() {
Map<ProjectionAnnotation, Position> annotations = new HashMap<ProjectionAnnotation, Position>();
IDocument document = getDocument();
int curOffset = 0;
FindReplaceDocumentAdapter frda = new FindReplaceDocumentAdapter(document);
try {
//$NON-NLS-1$
IRegion startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
while (startRegion != null && startRegion.getOffset() >= curOffset) {
int startLine = document.getLineOfOffset(startRegion.getOffset());
int startOffset = document.getLineOffset(startLine);
curOffset = startOffset + document.getLineLength(startLine);
//$NON-NLS-1$
IRegion endRegion = frda.find(startRegion.getOffset(), "SNIPPET_END", true, false, false, false);
if (endRegion != null) {
int endLine = document.getLineOfOffset(endRegion.getOffset());
int endOffset = document.getLineOffset(endLine);
endOffset += document.getLineLength(endLine);
curOffset = endOffset;
String text = document.get(startOffset, endOffset - startOffset);
ProjectionAnnotation annotation = new ProjectionAnnotation(true);
annotation.setText(text);
annotation.setRangeIndication(true);
annotations.put(annotation, new Position(startOffset, endOffset - startOffset));
}
if (curOffset < document.getLength()) {
//$NON-NLS-1$
startRegion = frda.find(curOffset, "SNIPPET_START", true, false, false, false);
}
}
} catch (BadLocationException e) {
ExceptionHandler.process(e);
}
return annotations;
}
use of org.eclipse.jface.text.IDocument in project tdi-studio-se by Talend.
the class JavaProcessor method formatCode.
/**
* DOC nrousseau Comment method "formatCode".
*
* from SourceViewer.doOperation for FORMAT.
*
* @param processCode
* @return
*/
@SuppressWarnings({ "unchecked" })
private String formatCode(String processCode) {
// we cannot make calls to Ui in headless mode
if (ProcessorUtilities.isExportConfig() || CommonsPlugin.isHeadless()) {
// nothing to do
return processCode;
}
final IDocument document = new Document(processCode);
JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools();
tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING);
IFormattingContext context = null;
DocumentRewriteSession rewriteSession = null;
if (document instanceof IDocumentExtension4) {
rewriteSession = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL);
}
try {
final String rememberedContents = document.get();
try {
final MultiPassContentFormatter formatter = new MultiPassContentFormatter(IJavaPartitions.JAVA_PARTITIONING, IDocument.DEFAULT_CONTENT_TYPE);
formatter.setMasterStrategy(new JavaFormattingStrategy());
// formatter.setSlaveStrategy(new CommentFormattingStrategy(),
// IJavaPartitions.JAVA_DOC);
// formatter.setSlaveStrategy(new CommentFormattingStrategy(),
// IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
// formatter.setSlaveStrategy(new CommentFormattingStrategy(),
// IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
context = new FormattingContext();
context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
Map<String, String> preferences;
if (this.getTalendJavaProject() == null) {
preferences = new HashMap<String, String>(JavaCore.getOptions());
} else {
// use project options
preferences = new HashMap<String, String>(this.getTalendJavaProject().getJavaProject().getOptions(true));
}
context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, preferences);
formatter.format(document, context);
} catch (RuntimeException x) {
// fire wall for
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
// if something went wrong we undo the changes we just did
// TODO to be removed after 3.0 M8
document.set(rememberedContents);
throw x;
}
} finally {
if (rewriteSession != null && document instanceof IDocumentExtension4) {
((IDocumentExtension4) document).stopRewriteSession(rewriteSession);
}
if (context != null) {
context.dispose();
}
}
return document.get();
}
Aggregations