private ICompletionProposal findCorrection(String id, boolean isAssist, ITextSelection selection, ICompilationUnit cu, IAnnotationModel model) { AssistContext context= new AssistContext(cu, selection.getOffset(), selection.getLength()); Collection proposals= new ArrayList(10); if (isAssist) { if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) { return getLocalRenameProposal(context); // shortcut for local rename } JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals); } else { try { boolean goToClosest= selection.getLength() == 0; Annotation[] annotations= getAnnotations(selection.getOffset(), goToClosest); JavaCorrectionProcessor.collectProposals(context, model, annotations, true, false, proposals); } catch (BadLocationException e) { return null; } } for (Iterator iter= proposals.iterator(); iter.hasNext();) { Object curr= iter.next(); if (curr instanceof ICommandAccess) { if (id.equals(((ICommandAccess) curr).getCommandId())) { return (ICompletionProposal) curr; } } } return null; }
private ICompletionProposal findCorrection(String id, boolean isAssist, ITextSelection selection, ICompilationUnit cu, IAnnotationModel model) { AssistContext context= new AssistContext(cu, fEditor.getViewer(), fEditor, selection.getOffset(), selection.getLength()); Collection<IJavaCompletionProposal> proposals= new ArrayList<>(10); if (isAssist) { if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) { return getLocalRenameProposal(context); // shortcut for local rename } JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals); } else { try { boolean goToClosest= selection.getLength() == 0; Annotation[] annotations= getAnnotations(selection.getOffset(), goToClosest); JavaCorrectionProcessor.collectProposals(context, model, annotations, true, false, proposals); } catch (BadLocationException e) { return null; } } for (Iterator<IJavaCompletionProposal> iter= proposals.iterator(); iter.hasNext();) { Object curr= iter.next(); if (curr instanceof ICommandAccess) { if (id.equals(((ICommandAccess) curr).getCommandId())) { return (ICompletionProposal) curr; } } } return null; }
private ICompletionProposal findCorrection(String id, boolean isAssist, ITextSelection selection, ICompilationUnit cu, IAnnotationModel model) { AssistContext context= new AssistContext(cu, fEditor.getViewer(), fEditor, selection.getOffset(), selection.getLength()); Collection<IJavaCompletionProposal> proposals= new ArrayList<>(10); if (isAssist) { if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) { return getLocalRenameProposal(context); // shortcut for local rename } JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals); } else { try { boolean goToClosest= selection.getLength() == 0; Annotation[] annotations= getAnnotations(selection.getOffset(), goToClosest); JavaCorrectionProcessor.collectProposals(context, model, annotations, true, false, proposals); } catch (BadLocationException e) { return null; } } for (Iterator<IJavaCompletionProposal> iter= proposals.iterator(); iter.hasNext();) { Object curr= iter.next(); if (curr instanceof ICommandAccess) { if (id.equals(((ICommandAccess) curr).getCommandId())) { return (ICompletionProposal) curr; } } } return null; }
private ICompletionProposal[] getJavaAnnotationFixes(IJavaAnnotation javaAnnotation) { ProblemLocation location= new ProblemLocation(position.getOffset(), position.getLength(), javaAnnotation); ICompilationUnit cu= javaAnnotation.getCompilationUnit(); if (cu == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; IInvocationContext context= new AssistContext(cu, sourceViewer, location.getOffset(), location.getLength(), SharedASTProviderCore.WAIT_ACTIVE_ONLY); if (!SpellingAnnotation.TYPE.equals(javaAnnotation.getType()) && !hasProblem(context.getASTRoot().getProblems(), location)) return NO_PROPOSALS; ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals); Collections.sort(proposals, new CompletionProposalComparator()); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
private ICompletionProposal[] getJavaAnnotationFixes(IJavaAnnotation javaAnnotation) { ProblemLocation location= new ProblemLocation(position.getOffset(), position.getLength(), javaAnnotation); ICompilationUnit cu= javaAnnotation.getCompilationUnit(); if (cu == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; IInvocationContext context= new AssistContext(cu, sourceViewer, location.getOffset(), location.getLength(), SharedASTProvider.WAIT_ACTIVE_ONLY); if (!SpellingAnnotation.TYPE.equals(javaAnnotation.getType()) && !hasProblem(context.getASTRoot().getProblems(), location)) return NO_PROPOSALS; ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals); Collections.sort(proposals, new CompletionProposalComparator()); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
private ICompletionProposal[] getMarkerAnnotationFixes(MarkerAnnotation markerAnnotation) { if (markerAnnotation.isQuickFixableStateSet() && !markerAnnotation.isQuickFixable()) return NO_PROPOSALS; IMarker marker= markerAnnotation.getMarker(); ICompilationUnit cu= getCompilationUnit(marker); if (cu == null) return NO_PROPOSALS; IEditorInput input= EditorUtility.getEditorInput(cu); if (input == null) return NO_PROPOSALS; IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(input); if (model == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; AssistContext context= new AssistContext(cu, sourceViewer, position.getOffset(), position.getLength()); ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); Collections.sort(proposals, new CompletionProposalComparator()); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
private ICompletionProposal[] getMarkerAnnotationFixes(MarkerAnnotation markerAnnotation) { if (markerAnnotation.isQuickFixableStateSet() && !markerAnnotation.isQuickFixable()) return NO_PROPOSALS; IMarker marker= markerAnnotation.getMarker(); ICompilationUnit cu= getCompilationUnit(marker); if (cu == null) return NO_PROPOSALS; IEditorInput input= EditorUtility.getEditorInput(cu); if (input == null) return NO_PROPOSALS; IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(input); if (model == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; AssistContext context= new AssistContext(cu, sourceViewer, position.getOffset(), position.getLength()); ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
private void doSelectionChanged(int offset, int length, CompilationUnit astRoot) { final IAnnotationModel model= getAnnotationModel(); final ICompilationUnit cu= getCompilationUnit(); if (model == null || cu == null) { return; } final AssistContext context= new AssistContext(cu, offset, length); context.setASTRoot(astRoot); boolean hasQuickFix= hasQuickFixLightBulb(model, context.getSelectionOffset()); if (hasQuickFix) { removeLightBulb(model); return; // there is already a quick fix light bulb at the new location } calculateLightBulb(model, context); }
private void doSelectionChanged(int offset, int length, CompilationUnit astRoot) { final IAnnotationModel model= getAnnotationModel(); final ICompilationUnit cu= getCompilationUnit(); if (model == null || cu == null) { return; } final AssistContext context= new AssistContext(cu, offset, length); context.setASTRoot(astRoot); boolean hasQuickFix= hasQuickFixLightBulb(model, context.getSelectionOffset()); if (hasQuickFix) { removeLightBulb(model); return; // there is already a quick fix light bulb at the new location } calculateLightBulb(model, context); }
private void doSelectionChanged(int offset, int length, CompilationUnit astRoot) { final IAnnotationModel model= getAnnotationModel(); final ICompilationUnit cu= getCompilationUnit(); if (model == null || cu == null) { return; } final AssistContext context= new AssistContext(cu, offset, length); context.setASTRoot(astRoot); boolean hasQuickFix= hasQuickFixLightBulb(model, context.getSelectionOffset()); if (hasQuickFix) { removeLightBulb(model); return; // there is already a quick fix light bulb at the new location } calculateLightBulb(model, context); }
private static IMarkerResolution[] internalGetResolutions(IMarker marker) { if (!internalHasResolutions(marker)) { return NO_RESOLUTIONS; } ICompilationUnit cu= getCompilationUnit(marker); if (cu != null) { IEditorInput input= EditorUtility.getEditorInput(cu); if (input != null) { IProblemLocation location= findProblemLocation(input, marker); if (location != null) { IInvocationContext context= new AssistContext(cu, location.getOffset(), location.getLength()); if (!hasProblem(context.getASTRoot().getProblems(), location) && !(marker.getResource() instanceof IFolder)) return NO_RESOLUTIONS; ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals); Collections.sort(proposals, new CompletionProposalComparator()); int nProposals= proposals.size(); IMarkerResolution[] resolutions= new IMarkerResolution[nProposals]; for (int i= 0; i < nProposals; i++) { resolutions[i]= new CorrectionMarkerResolution(context.getCompilationUnit(), location.getOffset(), location.getLength(), proposals.get(i), marker); } return resolutions; } } } return NO_RESOLUTIONS; }
private static IMarkerResolution[] internalGetResolutions(IMarker marker) { if (!internalHasResolutions(marker)) { return NO_RESOLUTIONS; } ICompilationUnit cu= getCompilationUnit(marker); if (cu != null) { IEditorInput input= EditorUtility.getEditorInput(cu); if (input != null) { IProblemLocation location= findProblemLocation(input, marker); if (location != null) { IInvocationContext context= new AssistContext(cu, location.getOffset(), location.getLength()); if (!hasProblem (context.getASTRoot().getProblems(), location)) return NO_RESOLUTIONS; ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals); Collections.sort(proposals, new CompletionProposalComparator()); int nProposals= proposals.size(); IMarkerResolution[] resolutions= new IMarkerResolution[nProposals]; for (int i= 0; i < nProposals; i++) { resolutions[i]= new CorrectionMarkerResolution(context.getCompilationUnit(), location.getOffset(), location.getLength(), proposals.get(i), marker); } return resolutions; } } } return NO_RESOLUTIONS; }
AssistContext context= new AssistContext(cu, documentOffset, length);
AssistContext context= new AssistContext(cu, documentOffset, length);
private CompilationUnitContext createNewContext(IDocument document) throws CoreException, BadLocationException { AssistContext invocationContext= new AssistContext(fCompilationUnit, fContext.getStart(), fContext.getEnd() - fContext.getStart()); SurroundWithTemplate surroundWith= new SurroundWithTemplate(invocationContext, fSelectedStatements, fTemplate); Map options= fCompilationUnit.getJavaProject().getOptions(true); surroundWith.getRewrite().rewriteAST(document, options).apply(document); int offset= surroundWith.getBodyStart(); int length= surroundWith.getBodyLength(); String newSelection= document.get(offset, length); //Create the new context CompilationUnitContextType contextType= (CompilationUnitContextType) JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(JavaContextType.NAME); CompilationUnitContext context= contextType.createContext(document, offset, newSelection.length(), fCompilationUnit); context.setVariable("selection", newSelection); //$NON-NLS-1$ context.setForceEvaluation(true); return context; }
private CompilationUnitContext createNewContext(IDocument document) throws CoreException, BadLocationException { AssistContext invocationContext= new AssistContext(fCompilationUnit, fContext.getStart(), fContext.getEnd() - fContext.getStart()); SurroundWithTemplate surroundWith= new SurroundWithTemplate(invocationContext, fSelectedNodes, fTemplate); Map<String, String> options= fCompilationUnit.getJavaProject().getOptions(true); surroundWith.getRewrite().rewriteAST(document, options).apply(document); int offset= surroundWith.getBodyStart(); int length= surroundWith.getBodyLength(); String newSelection= document.get(offset, length); //Create the new context CompilationUnitContextType contextType= (CompilationUnitContextType) JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(fTemplate.getContextTypeId()); CompilationUnitContext context= contextType.createContext(document, offset, newSelection.length(), fCompilationUnit); context.setVariable("selection", newSelection); //$NON-NLS-1$ context.setForceEvaluation(true); return context; }
private CompilationUnitContext createNewContext(IDocument document) throws CoreException, BadLocationException { AssistContext invocationContext= new AssistContext(fCompilationUnit, fContext.getStart(), fContext.getEnd() - fContext.getStart()); SurroundWithTemplate surroundWith= new SurroundWithTemplate(invocationContext, fSelectedNodes, fTemplate); Map<String, String> options= fCompilationUnit.getJavaProject().getOptions(true); surroundWith.getRewrite().rewriteAST(document, options).apply(document); int offset= surroundWith.getBodyStart(); int length= surroundWith.getBodyLength(); String newSelection= document.get(offset, length); //Create the new context CompilationUnitContextType contextType= (CompilationUnitContextType) JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(fTemplate.getContextTypeId()); CompilationUnitContext context= contextType.createContext(document, offset, newSelection.length(), fCompilationUnit); context.setVariable("selection", newSelection); //$NON-NLS-1$ context.setForceEvaluation(true); return context; }
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; }
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; }
IInvocationContext context= new AssistContext(cu, textSelection.getOffset(), textSelection.getLength());