use of org.eclipse.jface.text.BadLocationException in project che by eclipse.
the class UndoTextFileChange method performEdits.
private UndoEdit performEdits(ITextFileBuffer buffer, final IDocument document, final boolean[] setContentStampSuccess) throws MalformedTreeException, BadLocationException, CoreException {
if (!buffer.isSynchronizationContextRequested()) {
return doPerformEdits(document, setContentStampSuccess);
}
ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
/** The lock for waiting for computation in the UI thread to complete. */
final Lock completionLock = new Lock();
final UndoEdit[] result = new UndoEdit[1];
final BadLocationException[] badLocationException = new BadLocationException[1];
final MalformedTreeException[] malformedTreeException = new MalformedTreeException[1];
final CoreException[] coreException = new CoreException[1];
Runnable runnable = new Runnable() {
public void run() {
synchronized (completionLock) {
try {
result[0] = doPerformEdits(document, setContentStampSuccess);
} catch (BadLocationException e) {
badLocationException[0] = e;
} catch (MalformedTreeException e) {
malformedTreeException[0] = e;
} catch (CoreException e) {
coreException[0] = e;
} finally {
completionLock.fDone = true;
completionLock.notifyAll();
}
}
}
};
synchronized (completionLock) {
fileBufferManager.execute(runnable);
while (!completionLock.fDone) {
try {
completionLock.wait(500);
} catch (InterruptedException x) {
}
}
}
if (badLocationException[0] != null) {
throw badLocationException[0];
} else if (malformedTreeException[0] != null) {
throw malformedTreeException[0];
} else if (coreException[0] != null) {
throw coreException[0];
}
return result[0];
}
use of org.eclipse.jface.text.BadLocationException in project tdi-studio-se by Talend.
the class TalendCompletionProposalComputer method computeCompletionProposals.
@Override
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
//$NON-NLS-1$
String prefix = "";
try {
if (context != null) {
prefix = context.computeIdentifierPrefix().toString();
//$NON-NLS-1$
String tmpPrefix = "";
IDocument doc = context.getDocument();
if ((!prefix.equals("")) || (doc.get().length() == 0)) {
//$NON-NLS-1$
tmpPrefix = prefix;
} else {
int offset = context.getInvocationOffset();
if (doc.getChar(offset - 1) == '.') {
// set by default to avoid other completions
//$NON-NLS-1$
tmpPrefix = ".";
if (offset >= CONTEXT_PREFIX.length() && doc.get(offset - CONTEXT_PREFIX.length(), CONTEXT_PREFIX.length()).equals(CONTEXT_PREFIX)) {
tmpPrefix = CONTEXT_PREFIX;
} else if (offset >= PERL_GLOBAL_PREFIX.length() & doc.get(offset - PERL_GLOBAL_PREFIX.length(), PERL_GLOBAL_PREFIX.length()).equals(PERL_GLOBAL_PREFIX)) {
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
// do nothing
break;
case PERL:
default:
tmpPrefix = PERL_GLOBAL_PREFIX;
}
} else {
// test each component label.
IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
IProcess process = service.getCurrentProcess();
if (process == null) {
return Collections.EMPTY_LIST;
}
List<? extends INode> nodes = process.getGraphicalNodes();
for (INode node : nodes) {
//$NON-NLS-1$
String toTest = node.getLabel() + ".";
if (offset >= toTest.length() && doc.get(offset - toTest.length(), toTest.length()).equals(toTest)) {
tmpPrefix = toTest;
break;
}
}
}
}
}
prefix = tmpPrefix;
if (".".equals(prefix) && LanguageManager.getCurrentLanguage().equals(ECodeLanguage.PERL)) {
//$NON-NLS-1$
//$NON-NLS-1$
prefix = "";
}
}
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
return computeCompletionProposals(context.getViewer(), prefix, context.getInvocationOffset(), monitor);
}
use of org.eclipse.jface.text.BadLocationException in project tdi-studio-se by Talend.
the class ExpressionComposite method setExpression.
/*
* (non-Javadoc)
*
* @see
* org.talend.expressionbuilder.ui.ExpressionController#setExpression(org.talend.designer.rowgenerator.data.Function
* )
*/
public void setExpression(Function f) {
String newValue = PERL_FUN_PREFIX;
if (f != null) {
final List<Parameter> parameters = f.getParameters();
if (FunctionManager.isJavaProject()) {
String fullName = f.getName();
//$NON-NLS-1$
newValue = fullName + "(";
for (Parameter pa : parameters) {
newValue += pa.getValue() + FUN_PARAM_SEPARATED;
}
if (!parameters.isEmpty()) {
newValue = newValue.substring(0, newValue.length() - 1);
}
//$NON-NLS-1$
newValue += ")";
} else {
//$NON-NLS-1$
newValue += f.getName() + "(";
for (Parameter pa : parameters) {
newValue += pa.getValue() + FUN_PARAM_SEPARATED;
}
newValue = newValue.substring(0, newValue.length() - 1);
newValue += PERL_FUN_SUFFIX;
}
}
IRegion region = viewer.getViewerRegion();
try {
document.replace(region.getOffset(), region.getLength(), newValue);
} catch (BadLocationException e) {
MessageBoxExceptionHandler.process(e);
}
}
use of org.eclipse.jface.text.BadLocationException 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.BadLocationException in project KaiZen-OpenAPI-Editor by RepreZen.
the class JsonContentAssistProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
if (!(viewer.getDocument() instanceof JsonDocument)) {
return super.computeCompletionProposals(viewer, documentOffset);
}
maybeSwitchScope(documentOffset);
final JsonDocument document = (JsonDocument) viewer.getDocument();
final ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
int line = 0, lineOffset = 0, column = 0;
try {
line = document.getLineOfOffset(documentOffset);
lineOffset = document.getLineOffset(line);
column = selection.getOffset() - lineOffset;
} catch (BadLocationException e) {
}
final String prefix = extractPrefix(viewer, documentOffset);
// column to resolve the path
if (!prefix.isEmpty()) {
column -= prefix.length();
}
Model model = document.getModel(documentOffset - prefix.length());
currentPath = model.getPath(line, column);
isRefCompletion = referenceProposalProvider.canProvideProposal(currentPath);
Collection<Proposal> p;
if (isRefCompletion) {
updateStatus();
p = referenceProposalProvider.getProposals(currentPath, document, currentScope);
} else {
clearStatus();
p = proposalProvider.getProposals(currentPath, model, prefix);
}
final Collection<ICompletionProposal> proposals = getCompletionProposals(p, prefix, documentOffset);
// compute template proposals
if (!isRefCompletion) {
final ICompletionProposal[] templateProposals = super.computeCompletionProposals(viewer, documentOffset);
if (templateProposals != null && templateProposals.length > 0) {
proposals.addAll(Lists.newArrayList(templateProposals));
}
}
return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
Aggregations