Search in sources :

Example 51 with BadLocationException

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];
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) UndoEdit(org.eclipse.text.edits.UndoEdit) BadLocationException(org.eclipse.jface.text.BadLocationException) Lock(org.eclipse.ltk.internal.core.refactoring.Lock)

Example 52 with BadLocationException

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);
}
Also used : INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) List(java.util.List) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 53 with BadLocationException

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);
    }
}
Also used : Parameter(org.talend.designer.rowgenerator.data.Parameter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 54 with BadLocationException

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;
}
Also used : ProjectionAnnotation(org.eclipse.jface.text.source.projection.ProjectionAnnotation) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IDocument(org.eclipse.jface.text.IDocument) FindReplaceDocumentAdapter(org.eclipse.jface.text.FindReplaceDocumentAdapter) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 55 with BadLocationException

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()]);
}
Also used : ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Model(com.reprezen.swagedit.core.model.Model) StyledString(org.eclipse.jface.viewers.StyledString) JsonDocument(com.reprezen.swagedit.core.editor.JsonDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal)

Aggregations

BadLocationException (org.eclipse.jface.text.BadLocationException)455 IDocument (org.eclipse.jface.text.IDocument)196 IRegion (org.eclipse.jface.text.IRegion)161 Test (org.junit.Test)102 Position (org.eclipse.jface.text.Position)101 Region (org.eclipse.jface.text.Region)68 Point (org.eclipse.swt.graphics.Point)61 Document (org.eclipse.jface.text.Document)47 CoreException (org.eclipse.core.runtime.CoreException)34 ArrayList (java.util.ArrayList)27 ITypedRegion (org.eclipse.jface.text.ITypedRegion)27 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)22 DocumentEvent (org.eclipse.jface.text.DocumentEvent)21 ITextSelection (org.eclipse.jface.text.ITextSelection)21 StyledText (org.eclipse.swt.custom.StyledText)18 StyledString (org.eclipse.jface.viewers.StyledString)17 IStatus (org.eclipse.core.runtime.IStatus)16 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)15 FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)15 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)15