Search in sources :

Example 1 with LinkedDataImpl

use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl in project che by eclipse.

the class LinkedCorrectionProposal method performChange.

/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.ui.text.correction.ChangeCorrectionProposal#performChange(org.eclipse.jface.text.IDocument, org.eclipse.ui.IEditorPart)
	 */
@Override
protected void performChange(/*IEditorPart part,*/
IDocument document) throws CoreException {
    //		try {
    super.performChange(/*part,*/
    document);
    //
    if (fLinkedProposalModel != null) {
        if (fLinkedProposalModel.hasLinkedPositions()) {
            // enter linked mode
            //					ITextViewer viewer= ((JavaEditor) part).getViewer();
            //					new LinkedProposalModelPresenter().enterLinkedMode(viewer, part, didOpenEditor(), fLinkedProposalModel);
            boolean added = false;
            LinkedModeModelImpl model = new LinkedModeModelImpl();
            Iterator<LinkedProposalPositionGroup> iterator = fLinkedProposalModel.getPositionGroupIterator();
            while (iterator.hasNext()) {
                LinkedProposalPositionGroup curr = iterator.next();
                LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
                LinkedProposalPositionGroup.PositionInformation[] positions = curr.getPositions();
                if (positions.length > 0) {
                    LinkedProposalPositionGroup.Proposal[] linkedModeProposals = curr.getProposals();
                    if (linkedModeProposals.length <= 1) {
                        for (int i = 0; i < positions.length; i++) {
                            LinkedProposalPositionGroup.PositionInformation pos = positions[i];
                            if (pos.getOffset() != -1) {
                                RegionImpl position = new RegionImpl();
                                position.setOffset(pos.getOffset());
                                position.setLength(pos.getLength());
                                //                                        group.addPositions(
                                //                                                new LinkedPosition(document, pos.getOffset(), pos.getLength(), pos.getSequenceRank()));
                                group.addPositions(position);
                            }
                        }
                    } else {
                        //                                LinkedPositionProposalImpl[] proposalImpls= new LinkedPositionProposalImpl[linkedModeProposals.length];
                        LinkedDataImpl data = new LinkedDataImpl();
                        for (int i = 0; i < linkedModeProposals.length; i++) {
                            //                                    proposalImpls[i] = new LinkedPositionProposalImpl(linkedModeProposals[i], model);
                            data.addValues(linkedModeProposals[i].getDisplayString());
                        }
                        group.setData(data);
                        for (int i = 0; i < positions.length; i++) {
                            LinkedProposalPositionGroup.PositionInformation pos = positions[i];
                            if (pos.getOffset() != -1) {
                                //                                        group.addPosition(
                                //                                                new ProposalPosition(document, pos.getOffset(), pos.getLength(), pos.getSequenceRank(),
                                //                                                                     proposalImpls));
                                RegionImpl position = new RegionImpl();
                                position.setOffset(pos.getOffset());
                                position.setLength(pos.getLength());
                                group.addPositions(position);
                            }
                        }
                    }
                    model.addGroups(group);
                    added = true;
                }
            }
            if (added) {
                LinkedProposalPositionGroup.PositionInformation endPosition = fLinkedProposalModel.getEndPosition();
                if (endPosition != null && endPosition.getOffset() != -1) {
                    model.setEscapePosition(endPosition.getOffset() + endPosition.getLength());
                }
                this.linkedModel = model;
            }
        }
    //				else if (part instanceof ITextEditor) {
    //					LinkedProposalPositionGroup.PositionInformation endPosition= fLinkedProposalModel.getEndPosition();
    //					if (endPosition != null) {
    //						// select a result
    //						int pos= endPosition.getOffset() + endPosition.getLength();
    //						((ITextEditor) part).selectAndReveal(pos, 0);
    //					}
    //				}
    }
//		} catch (BadLocationException e) {
//			throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
//		}
}
Also used : LinkedPositionGroupImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedPositionGroupImpl) LinkedModeModelImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl) LinkedDataImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl) RegionImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.RegionImpl) LinkedProposalPositionGroup(org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroup) ASTRewriteCorrectionProposal(org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)

Example 2 with LinkedDataImpl

use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl in project che by eclipse.

the class TemplateProposal method apply.

/*
     * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int)
     */
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
    IDocument document = viewer.getDocument();
    try {
        fContext.setReadOnly(false);
        int start;
        TemplateBuffer templateBuffer;
        try {
            beginCompoundChange(viewer);
            int oldReplaceOffset = getReplaceOffset();
            try {
                // this may already modify the document (e.g. add imports)
                templateBuffer = fContext.evaluate(fTemplate);
            } catch (TemplateException e1) {
                fSelectedRegion = fRegion;
                return;
            }
            start = getReplaceOffset();
            int shift = start - oldReplaceOffset;
            int end = Math.max(getReplaceEndOffset(), offset + shift);
            // insert template string
            if (end > document.getLength())
                end = offset;
            String templateString = templateBuffer.getString();
            document.replace(start, end - start, templateString);
        } finally {
            endCompoundChange(viewer);
        }
        // translate positions
        LinkedModeModelImpl model = new LinkedModeModelImpl();
        TemplateVariable[] variables = templateBuffer.getVariables();
        MultiVariableGuess guess = fContext instanceof CompilationUnitContext ? ((CompilationUnitContext) fContext).getMultiVariableGuess() : null;
        boolean hasPositions = false;
        for (int i = 0; i != variables.length; i++) {
            TemplateVariable variable = variables[i];
            if (variable.isUnambiguous())
                continue;
            LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
            int[] offsets = variable.getOffsets();
            int length = variable.getLength();
            LinkedPosition first;
            if (guess != null && variable instanceof MultiVariable) {
                first = new VariablePosition(document, offsets[0] + start, length, guess, (MultiVariable) variable);
                guess.addSlave((VariablePosition) first);
            } else {
                String[] values = variable.getValues();
                ICompletionProposal[] proposals = new ICompletionProposal[values.length];
                for (int j = 0; j < values.length; j++) {
                    //						ensurePositionCategoryInstalled(document, model);
                    Position pos = new Position(offsets[0] + start, length);
                    //						document.addPosition(getCategory(), pos);
                    proposals[j] = new PositionBasedCompletionProposal(values[j], pos, length);
                }
                if (proposals.length > 1)
                    first = new ProposalPosition(document, offsets[0] + start, length, proposals);
                else
                    first = new LinkedPosition(document, offsets[0] + start, length);
            }
            for (int j = 0; j != offsets.length; j++) if (j == 0) {
                if (first instanceof ProposalPosition) {
                    RegionImpl region = new RegionImpl();
                    region.setLength(first.getLength());
                    region.setOffset(first.getOffset());
                    LinkedDataImpl data = new LinkedDataImpl();
                    ICompletionProposal[] choices = ((ProposalPosition) first).getChoices();
                    if (choices != null) {
                        for (ICompletionProposal choice : choices) {
                            data.addValues(choice.getDisplayString());
                        }
                        group.setData(data);
                    }
                    group.addPositions(region);
                } else {
                    RegionImpl region = new RegionImpl();
                    region.setLength(first.getLength());
                    region.setOffset(first.getOffset());
                    group.addPositions(region);
                }
            } else {
                RegionImpl region = new RegionImpl();
                region.setLength(length);
                region.setOffset(offsets[j] + start);
                group.addPositions(region);
            }
            model.addGroups(group);
            hasPositions = true;
        }
        if (hasPositions) {
            model.setEscapePosition(getCaretOffset(templateBuffer) + start);
            this.linkedModeModel = model;
            //				model.forceInstall();
            //				JavaEditor editor= getJavaEditor();
            //				if (editor != null) {
            //					model.addLinkingListener(new EditorHighlightingSynchronizer(editor));
            //				}
            //
            //				LinkedModeUI ui= new EditorLinkedModeUI(model, viewer);
            //				ui.setExitPosition(viewer, getCaretOffset(templateBuffer) + start, 0, Integer.MAX_VALUE);
            //				ui.enter();
            //ui.getSelectedRegion();
            fSelectedRegion = fRegion;
        } else {
            fSelectedRegion = new Region(getCaretOffset(templateBuffer) + start, 0);
        }
    } catch (BadLocationException e) {
        JavaPlugin.log(e);
        //			openErrorDialog(viewer.getTextWidget().getShell(), e);
        fSelectedRegion = fRegion;
    }
}
Also used : TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) StyledString(org.eclipse.jface.viewers.StyledString) ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal) TemplateVariable(org.eclipse.jface.text.templates.TemplateVariable) LinkedPosition(org.eclipse.jface.text.link.LinkedPosition) LinkedPositionGroupImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedPositionGroupImpl) TemplateException(org.eclipse.jface.text.templates.TemplateException) LinkedPosition(org.eclipse.jface.text.link.LinkedPosition) ProposalPosition(org.eclipse.che.jface.text.link.ProposalPosition) Position(org.eclipse.jface.text.Position) LinkedModeModelImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl) LinkedDataImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl) Point(org.eclipse.swt.graphics.Point) ProposalPosition(org.eclipse.che.jface.text.link.ProposalPosition) CompilationUnitContext(org.eclipse.jdt.internal.corext.template.java.CompilationUnitContext) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) RegionImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.RegionImpl) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with LinkedDataImpl

use of org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl in project che by eclipse.

the class ParameterGuessingProposal method apply.

/*
     * @see ICompletionProposalExtension#apply(IDocument, char)
     */
@Override
public void apply(final IDocument document, char trigger, int offset) {
    super.apply(document, trigger, offset);
    int baseOffset = getReplacementOffset();
    String replacement = getReplacementString();
    if (fPositions != null && getTextViewer() != null) {
        LinkedModeModelImpl model = new LinkedModeModelImpl();
        for (int i = 0; i < fPositions.length; i++) {
            LinkedPositionGroupImpl group = new LinkedPositionGroupImpl();
            int positionOffset = fPositions[i].getOffset();
            int positionLength = fPositions[i].getLength();
            if (fChoices[i].length < 2) {
                RegionImpl region = new RegionImpl();
                region.setOffset(positionOffset);
                region.setLength(positionLength);
                //                        group.addPositions(new LinkedPosition(document, positionOffset, positionLength, LinkedPositionGroup.NO_STOP));
                group.addPositions(region);
            } else {
                //                        ensurePositionCategoryInstalled(document, model);
                //                        document.addPosition(getCategory(), fPositions[i]);
                RegionImpl region = new RegionImpl();
                region.setOffset(positionOffset);
                region.setLength(positionLength);
                //                        group.addPositions(
                //                                new ProposalPosition(document, positionOffset, positionLength, LinkedPositionGroup.NO_STOP, fChoices[i]));
                group.addPositions(region);
                LinkedDataImpl data = new LinkedDataImpl();
                for (ICompletionProposal proposal : fChoices[i]) {
                    data.addValues(proposal.getDisplayString());
                }
                group.setData(data);
            }
            model.addGroups(group);
        }
        model.setEscapePosition(baseOffset + replacement.length());
        this.linkedModel = model;
        //                model.forceInstall();
        //                JavaEditor editor = getJavaEditor();
        //                if (editor != null) {
        //                    model.addLinkingListener(new EditorHighlightingSynchronizer(editor));
        //                }
        //                LinkedModeUI ui = new EditorLinkedModeUI(model, getTextViewer());
        //                ui.setExitPosition(getTextViewer(), baseOffset + replacement.length(), 0, Integer.MAX_VALUE);
        //                // exit character can be either ')' or ';'
        //                final char exitChar = replacement.charAt(replacement.length() - 1);
        //                ui.setExitPolicy(new ExitPolicy(exitChar, document) {
        //                    @Override
        //                    public ExitFlags doExit(LinkedModeModel model2, VerifyEvent event, int offset2, int length) {
        //                        if (event.character == ',') {
        //                            for (int i = 0; i < fPositions.length - 1; i++) { // not for the last one
        //                                Position position = fPositions[i];
        //                                if (position.offset <= offset2 && offset2 + length <= position.offset + position.length) {
        //                                    try {
        //                                        ITypedRegion partition = TextUtilities
        //                                                .getPartition(document, IJavaPartitions.JAVA_PARTITIONING, offset2 + length, false);
        //                                        if (IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())
        //                                            || offset2 + length == partition.getOffset() + partition.getLength()) {
        //                                            event.character = '\t';
        //                                            event.keyCode = SWT.TAB;
        //                                            return null;
        //                                        }
        //                                    } catch (BadLocationException e) {
        //                                        // continue; not serious enough to log
        //                                    }
        //                                }
        //                            }
        //                        } else if (event.character == ')' && exitChar != ')') {
        //                            // exit from link mode when user is in the last ')' position.
        //                            Position position = fPositions[fPositions.length - 1];
        //                            if (position.offset <= offset2 && offset2 + length <= position.offset + position.length) {
        //								return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
        //							}
        //						}
        //						return super.doExit(model2, event, offset2, length);
        //					}
        //				});
        //				ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
        //				ui.setDoContextInfo(true);
        //				ui.enter();
        fSelectedRegion = new Region(baseOffset + replacement.length(), 0);
    } else {
        fSelectedRegion = new Region(baseOffset + replacement.length(), 0);
    }
}
Also used : LinkedPositionGroupImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedPositionGroupImpl) ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) LinkedModeModelImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl) RegionImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.RegionImpl) LinkedDataImpl(org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl) Point(org.eclipse.swt.graphics.Point)

Aggregations

LinkedDataImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedDataImpl)3 LinkedModeModelImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedModeModelImpl)3 LinkedPositionGroupImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.LinkedPositionGroupImpl)3 RegionImpl (org.eclipse.che.plugin.java.server.dto.DtoServerImpls.RegionImpl)3 ICompletionProposal (org.eclipse.che.jface.text.contentassist.ICompletionProposal)2 IRegion (org.eclipse.jface.text.IRegion)2 Region (org.eclipse.jface.text.Region)2 Point (org.eclipse.swt.graphics.Point)2 ProposalPosition (org.eclipse.che.jface.text.link.ProposalPosition)1 LinkedProposalPositionGroup (org.eclipse.jdt.internal.corext.fix.LinkedProposalPositionGroup)1 CompilationUnitContext (org.eclipse.jdt.internal.corext.template.java.CompilationUnitContext)1 ASTRewriteCorrectionProposal (org.eclipse.jdt.ui.text.java.correction.ASTRewriteCorrectionProposal)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IDocument (org.eclipse.jface.text.IDocument)1 Position (org.eclipse.jface.text.Position)1 LinkedPosition (org.eclipse.jface.text.link.LinkedPosition)1 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)1 TemplateException (org.eclipse.jface.text.templates.TemplateException)1 TemplateVariable (org.eclipse.jface.text.templates.TemplateVariable)1 StyledString (org.eclipse.jface.viewers.StyledString)1