@Override public int getSelectionLength() { return originalContext.getSelectionLength(); }
@Override public int getSelectionLength() { return originalContext.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) { 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 static boolean getRemoveExtraParenthesisProposals(IInvocationContext context, ASTNode covering, ArrayList coveredNodes, Collection resultingCollections) { ArrayList nodes; if ((context.getSelectionLength() == 0) && (covering instanceof ParenthesizedExpression)) { nodes = new ArrayList(); nodes.add(covering); } else { nodes= coveredNodes; } if (nodes.isEmpty()) return false; IFix fix= ExpressionsFix.createRemoveUnnecessaryParenthesisFix(context.getASTRoot(), (ASTNode[])nodes.toArray(new ASTNode[nodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_REMOVE); Map options= new Hashtable(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpConstants.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpConstants.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), 1, image, context); resultingCollections.add(proposal); return true; } private static int getExpressionPrecedence(Expression expression) {
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(); } }