@Override public int getSelectionOffset() { return originalContext.getSelectionOffset(); }
@Override public int getSelectionOffset() { return originalContext.getSelectionOffset(); }
public final Point getSelection(final IDocument document) { return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength()); } }
public final Point getSelection(final IDocument document) { return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength()); } }
public final Point getSelection(final IDocument document) { return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength()); } }
public final Point getSelection(final IDocument document) { int offset= fContext.getSelectionOffset(); int length= fContext.getSelectionLength(); final int delta= fWord.length() - fLength; if (offset <= fOffset && offset + length >= fOffset) length += delta; else if (offset > fOffset && offset + length > fOffset + fLength) { offset += delta; length -= delta; } else length += delta; return new Point(offset, length); } }
private void forceReconcile(IDocument document) { try { // force a reconcile int offset = invocationContext.getSelectionOffset(); int length = invocationContext.getSelectionLength(); String s = document.get(offset, length); document.replace(offset, length, s); } catch (BadLocationException e) { // ignore } }
private void calculateLightBulb(IAnnotationModel model, IInvocationContext context) { boolean needsAnnotation= JavaCorrectionProcessor.hasAssists(context); if (fIsAnnotationShown) { model.removeAnnotation(fAnnotation); } if (needsAnnotation) { model.addAnnotation(fAnnotation, new Position(context.getSelectionOffset(), context.getSelectionLength())); } fIsAnnotationShown= needsAnnotation; }
private void calculateLightBulb(IAnnotationModel model, IInvocationContext context) { boolean needsAnnotation= JavaCorrectionProcessor.hasAssists(context); if (fIsAnnotationShown) { model.removeAnnotation(fAnnotation); } if (needsAnnotation) { model.addAnnotation(fAnnotation, new Position(context.getSelectionOffset(), context.getSelectionLength())); } fIsAnnotationShown= needsAnnotation; }
private void calculateLightBulb(IAnnotationModel model, IInvocationContext context) { boolean needsAnnotation= JavaCorrectionProcessor.hasAssists(context); if (fIsAnnotationShown) { model.removeAnnotation(fAnnotation); } if (needsAnnotation) { model.addAnnotation(fAnnotation, new Position(context.getSelectionOffset(), context.getSelectionLength())); } fIsAnnotationShown= needsAnnotation; }
@Override public boolean hasAssists(IInvocationContext context) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); IDocument document= getDocument(cu); int offset= context.getSelectionOffset(); int length= context.getSelectionLength(); if (length == 0) { return false; } try { int startLine= document.getLineOfOffset(offset); int endLine= document.getLineOfOffset(offset + length); IRegion region= document.getLineInformation(endLine); return startLine < endLine || length > 0 && offset == region.getOffset() && length == region.getLength(); } catch (BadLocationException e) { return false; } }
@Override public boolean hasAssists(IInvocationContext context) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); IDocument document= getDocument(cu); int offset= context.getSelectionOffset(); int length= context.getSelectionLength(); if (length == 0) { return false; } try { int startLine= document.getLineOfOffset(offset); int endLine= document.getLineOfOffset(offset + length); IRegion region= document.getLineInformation(endLine); return startLine < endLine || length > 0 && offset == region.getOffset() && length == region.getLength(); } catch (BadLocationException e) { return false; } }
public boolean hasAssists(IInvocationContext context) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); IDocument document= getDocument(cu); int offset= context.getSelectionOffset(); int length= context.getSelectionLength(); if (length == 0) { return false; } try { int startLine= document.getLineOfOffset(offset); int endLine= document.getLineOfOffset(offset + length); IRegion region= document.getLineInformation(endLine); return startLine < endLine || length > 0 && offset == region.getOffset() && length == region.getLength(); } catch (BadLocationException e) { return false; } }
public static boolean isApplicable(IInvocationContext context) throws CoreException { ICompilationUnit unit= context.getCompilationUnit(); CompilationUnit ast= SharedASTProvider.getAST(unit, SharedASTProvider.WAIT_NO, null); if (ast == null) return true; Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(unit, selection, false); context.getASTRoot().accept(analyzer); return analyzer.getStatus().isOK() && analyzer.hasSelectedNodes(); }
public static boolean isApplicable(IInvocationContext context) throws CoreException { ICompilationUnit unit= context.getCompilationUnit(); CompilationUnit ast= SharedASTProviderCore.getAST(unit, SharedASTProviderCore.WAIT_NO, null); if (ast == null) return true; Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(unit, selection, false); context.getASTRoot().accept(analyzer); return analyzer.getStatus().isOK() && analyzer.hasSelectedNodes(); }
public static boolean isApplicable(IInvocationContext context) throws JavaModelException { ICompilationUnit unit= context.getCompilationUnit(); CompilationUnit ast= ASTProvider.getASTProvider().getAST(unit, ASTProvider.WAIT_NO, null); if (ast == null) return true; Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(unit, selection); context.getASTRoot().accept(analyzer); return analyzer.getStatus().isOK() && analyzer.hasSelectedNodes(); }
/** * Selected nodes in <code>context</code> under <code>selection</code> or null if no valid selection. * @param context The context in which the proposal is applyed. * @return Selected nodes or null if no valid selection. * @throws JavaModelException */ public static Statement[] getSelectedStatements(IInvocationContext context) throws JavaModelException { Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(context.getCompilationUnit(), selection); context.getASTRoot().accept(analyzer); if (!analyzer.getStatus().isOK() || !analyzer.hasSelectedNodes()) { return null; } else { return analyzer.getSelectedStatements(); } }
/** * Selected nodes in <code>context</code> under <code>selection</code> or null if no valid * selection. * * @param context The context in which the proposal is applied. * @return Selected nodes or null if no valid selection. * @throws CoreException if the analyzer cannot be created */ public static ASTNode[] getValidSelectedNodes(IInvocationContext context) throws CoreException { Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(context.getCompilationUnit(), selection, false); context.getASTRoot().accept(analyzer); if (!analyzer.getStatus().isOK() || !analyzer.hasSelectedNodes()) { return null; } else { return analyzer.getValidSelectedNodes(); } }
/** * Selected nodes in <code>context</code> under <code>selection</code> or null if no valid * selection. * * @param context The context in which the proposal is applied. * @return Selected nodes or null if no valid selection. * @throws CoreException if the analyzer cannot be created */ public static ASTNode[] getValidSelectedNodes(IInvocationContext context) throws CoreException { Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(context.getCompilationUnit(), selection, false); context.getASTRoot().accept(analyzer); if (!analyzer.getStatus().isOK() || !analyzer.hasSelectedNodes()) { return null; } else { return analyzer.getValidSelectedNodes(); } }
private static IAction[] getTemplateActions(JavaEditor editor) { ITextSelection textSelection= getTextSelection(editor); if (textSelection == null || textSelection.getLength() == 0) return null; ICompilationUnit cu= JavaUI.getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()); if (cu == null) return null; QuickTemplateProcessor quickTemplateProcessor= new QuickTemplateProcessor(); IInvocationContext context= new AssistContext(cu, textSelection.getOffset(), textSelection.getLength()); try { IJavaCompletionProposal[] proposals= quickTemplateProcessor.getAssists(context, null); if (proposals == null || proposals.length == 0) return null; return getActionsFromProposals(proposals, context.getSelectionOffset(), editor.getViewer()); } catch (CoreException e) { JavaPlugin.log(e); } return null; }