@Override public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) { if (getEditor() != null) { JavaCorrectionAssistant assistant= new JavaCorrectionAssistant(getEditor()); assistant.setRestoreCompletionProposalSize(getSettings("quick_assist_proposal_size")); //$NON-NLS-1$ return assistant; } return null; }
/** * Constructor for JavaCorrectionAssistant. * @param editor the editor */ public JavaCorrectionAssistant(ITextEditor editor) { super(); Assert.isNotNull(editor); fEditor= editor; IQuickAssistProcessor processor; if (editor instanceof ClassFileEditor) processor= new ExternalNullAnnotationQuickAssistProcessor(this); else processor= new JavaCorrectionProcessor(this); setQuickAssistProcessor(processor); enableColoredLabels(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)); setInformationControlCreator(getInformationControlCreator()); addCompletionListener(new ICompletionListener() { @Override public void assistSessionEnded(ContentAssistEvent event) { fIsCompletionActive= false; } @Override public void assistSessionStarted(ContentAssistEvent event) { fIsCompletionActive= true; } @Override public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) { } }); }
private Annotation[] getAnnotations(int offset, boolean goToClosest) throws BadLocationException { ArrayList resultingAnnotations= new ArrayList(); JavaCorrectionAssistant.collectQuickFixableAnnotations(fEditor, offset, goToClosest, resultingAnnotations); return (Annotation[]) resultingAnnotations.toArray(new Annotation[resultingAnnotations.size()]); }
private static int processAnnotation(Annotation annot, Position pos, int invocationLocation, int bestOffset) { int posBegin= pos.offset; int posEnd= posBegin + pos.length; if (isInside(invocationLocation, posBegin, posEnd)) { // covers invocation location? return invocationLocation; } else if (bestOffset != invocationLocation) { int newClosestPosition= computeBestOffset(posBegin, invocationLocation, bestOffset); if (newClosestPosition != -1) { if (newClosestPosition != bestOffset) { // new best if (JavaCorrectionProcessor.hasCorrections(annot)) { // only jump to it if there are proposals return newClosestPosition; } } } } return bestOffset; }
/** * Constructor for JavaCorrectionAssistant. */ public JavaCorrectionAssistant(ITextEditor editor) { super(); Assert.isNotNull(editor); fEditor= editor; JavaCorrectionProcessor processor= new JavaCorrectionProcessor(this); setQuickAssistProcessor(processor); setInformationControlCreator(getInformationControlCreator()); JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools(); IColorManager manager= textTools.getColorManager(); IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); Color c= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND, manager); setProposalSelectorForeground(c); c= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND, manager); setProposalSelectorBackground(c); }
ensureUpdatedAnnotations(editor); IRegion lineInfo= getRegionOfInterest(editor, invocationLocation); if (lineInfo == null) { return invocationLocation; if (JavaCorrectionProcessor.isQuickFixableType(annot)) { Position pos= model.getPosition(annot); if (pos != null && isInside(pos.offset, rangeStart, rangeEnd)) { // inside our range? allAnnotations.add(annot); allPositions.add(pos); bestOffset= processAnnotation(annot, pos, invocationLocation, bestOffset); if (isInside(bestOffset, pos.offset, pos.offset + pos.length)) { resultingAnnotations.add(allAnnotations.get(i)); if (JavaCorrectionProcessor.isQuickFixableType(annot)) { Position pos= model.getPosition(annot); if (pos != null && isInside(invocationLocation, pos.offset, pos.offset + pos.length)) { resultingAnnotations.add(annot);
if (isUpdatedOffset()) { isReinvoked= true; restorePosition(); hide(); fIsProblemLocationAvailable= true; boolean goToClosest= (currLength == 0) && !isReinvoked; int newOffset= collectQuickFixableAnnotations(fEditor, currOffset, goToClosest, resultingAnnotations); if (newOffset != currOffset) { storePosition(currOffset, currLength); fViewer.setSelectedRange(newOffset, 0); fViewer.revealRange(newOffset, 0); fIsProblemLocationAvailable= true; if (fIsCompletionActive) { hide();
int documentOffset= quickAssistContext.getOffset(); IEditorPart part= fAssistant.getEditor(); AssistContext context= new AssistContext(cu, documentOffset, length); Annotation[] annotations= fAssistant.getAnnotationsAtOffset(); if (model != null && annotations != null) { ArrayList proposals= new ArrayList(10); IStatus status= collectProposals(context, model, annotations, true, !fAssistant.isUpdatedOffset(), proposals); res= (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]); if (!status.isOK()) {
boolean goToClosest= (currLength == 0); int newOffset= collectQuickFixableAnnotations(fEditor, currOffset, goToClosest, resultingAnnotations); if (newOffset != currOffset) { storePosition(currOffset, currLength); fViewer.setSelectedRange(newOffset, 0); fViewer.revealRange(newOffset, 0);
@Override public boolean canAssist(IQuickAssistInvocationContext invocationContext) { IEditorPart part= fAssistant.getEditor(); IClassFile classFile= ((IClassFileEditorInput) part.getEditorInput()).getClassFile(); return classFile.getJavaProject().getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true).equals(JavaCore.ENABLED); }
public JavaCorrectionProcessor(JavaCorrectionAssistant assistant) { fAssistant= assistant; fAssistant.addCompletionListener(new ICompletionListener() { public void assistSessionEnded(ContentAssistEvent event) { fAssistant.setStatusLineVisible(false); } public void assistSessionStarted(ContentAssistEvent event) { fAssistant.setStatusLineVisible(true); } public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) { if (proposal instanceof IStatusLineProposal) { IStatusLineProposal statusLineProposal= (IStatusLineProposal)proposal; String message= statusLineProposal.getStatusMessage(); if (message != null) { fAssistant.setStatusMessage(message); } else { fAssistant.setStatusMessage(""); //$NON-NLS-1$ } } else { fAssistant.setStatusMessage(""); //$NON-NLS-1$ } } }); }
public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) { if (getEditor() != null) return new JavaCorrectionAssistant(getEditor()); return null; }
ensureUpdatedAnnotations(editor); IRegion lineInfo= getRegionOfInterest(editor, invocationLocation); if (lineInfo == null) { return invocationLocation; if (JavaCorrectionProcessor.isQuickFixableType(annot)) { Position pos= model.getPosition(annot); if (pos != null && isInside(pos.offset, rangeStart, rangeEnd)) { // inside our range? allAnnotations.add(annot); allPositions.add(pos); bestOffset= processAnnotation(annot, pos, invocationLocation, bestOffset); if (isInside(bestOffset, pos.offset, pos.offset + pos.length)) { resultingAnnotations.add(allAnnotations.get(i)); if (JavaCorrectionProcessor.isQuickFixableType(annot)) { Position pos= model.getPosition(annot); if (pos != null && isInside(invocationLocation, pos.offset, pos.offset + pos.length)) { resultingAnnotations.add(annot);
if (isUpdatedOffset()) { isReinvoked= true; restorePosition(); hide(); fIsProblemLocationAvailable= true; boolean goToClosest= (currLength == 0) && !isReinvoked; int newOffset= collectQuickFixableAnnotations(fEditor, currOffset, goToClosest, resultingAnnotations); if (newOffset != currOffset) { storePosition(currOffset, currLength); fViewer.setSelectedRange(newOffset, 0); fViewer.revealRange(newOffset, 0); fIsProblemLocationAvailable= true; if (fIsCompletionActive) { hide();
int documentOffset= quickAssistContext.getOffset(); IEditorPart part= fAssistant.getEditor(); Annotation[] annotations= fAssistant.getAnnotationsAtOffset(); if (model != null && context != null && annotations != null) { ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(10); IStatus status= collectProposals(context, model, annotations, true, !fAssistant.isUpdatedOffset(), proposals); res= proposals.toArray(new ICompletionProposal[proposals.size()]); if (!status.isOK()) {
private static int processAnnotation(Annotation annot, Position pos, int invocationLocation, int bestOffset) { int posBegin= pos.offset; int posEnd= posBegin + pos.length; if (isInside(invocationLocation, posBegin, posEnd) && JavaCorrectionProcessor.hasCorrections(annot)) { // covers invocation location? return invocationLocation; } else if (bestOffset != invocationLocation) { int newClosestPosition= computeBestOffset(posBegin, invocationLocation, bestOffset); if (newClosestPosition != -1) { if (newClosestPosition != bestOffset) { // new best if (JavaCorrectionProcessor.hasCorrections(annot)) { // only jump to it if there are proposals return newClosestPosition; } } } } return bestOffset; }
@Override public boolean canAssist(IQuickAssistInvocationContext invocationContext) { IEditorPart part= fAssistant.getEditor(); IClassFile classFile= ((IClassFileEditorInput) part.getEditorInput()).getClassFile(); return classFile.getJavaProject().getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true).equals(JavaCore.ENABLED); }
public JavaCorrectionProcessor(JavaCorrectionAssistant assistant) { fAssistant= assistant; fAssistant.addCompletionListener(new ICompletionListener() {
ensureUpdatedAnnotations(editor); IRegion lineInfo= getRegionOfInterest(editor, invocationLocation); if (lineInfo == null) { return invocationLocation; if (JavaCorrectionProcessor.isQuickFixableType(annot)) { Position pos= model.getPosition(annot); if (pos != null && isInside(pos.offset, rangeStart, rangeEnd)) { // inside our range? allAnnotations.add(annot); allPositions.add(pos); bestOffset= processAnnotation(annot, pos, invocationLocation, bestOffset); if (isInside(bestOffset, pos.offset, pos.offset + pos.length)) { resultingAnnotations.add(allAnnotations.get(i)); if (JavaCorrectionProcessor.isQuickFixableType(annot)) { Position pos= model.getPosition(annot); if (pos != null && isInside(invocationLocation, pos.offset, pos.offset + pos.length)) { resultingAnnotations.add(annot);
/** * Constructor for JavaCorrectionAssistant. * @param editor the editor */ public JavaCorrectionAssistant(ITextEditor editor) { super(); Assert.isNotNull(editor); fEditor= editor; IQuickAssistProcessor processor; if (editor instanceof ClassFileEditor) processor= new ExternalNullAnnotationQuickAssistProcessor(this); else processor= new JavaCorrectionProcessor(this); setQuickAssistProcessor(processor); enableColoredLabels(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)); setInformationControlCreator(getInformationControlCreator()); addCompletionListener(new ICompletionListener() { @Override public void assistSessionEnded(ContentAssistEvent event) { fIsCompletionActive= false; } @Override public void assistSessionStarted(ContentAssistEvent event) { fIsCompletionActive= true; } @Override public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) { } }); }