@Override public final String getReplacementString() { if (!fReplacementStringComputed) setReplacementString(computeReplacementString()); return super.getReplacementString(); }
/** * Returns <code>true</code> if imports should be added. The return value depends on the context * and preferences only and does not take into account the contents of the compilation unit or * the kind of proposal. Even if <code>true</code> is returned, there may be cases where no * imports are added for the proposal. For example: * <ul> * <li>when completing within the import section</li> * <li>when completing informal javadoc references (e.g. within <code><code></code> * tags)</li> * <li>when completing a type that conflicts with an existing import</li> * <li>when completing an implicitly imported type (same package, <code>java.lang</code> * types)</li> * </ul> * <p> * The decision whether a qualified type or the simple type name should be inserted must take * into account these different scenarios. * </p> * * @return <code>true</code> if imports may be added, <code>false</code> if not */ private boolean shouldAddImports() { if (isInJavadoc() && !isJavadocProcessingEnabled()) return false; IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore(); return preferenceStore.getBoolean(PreferenceConstants.CODEASSIST_ADDIMPORT); }
setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.TYPE_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen - proposal.getLengthOfImportsAddedBehindReplacementOffset()); } else if (requiredProposals[i].getKind() == CompletionProposal.METHOD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen - proposal.getLengthOfImportsAddedBehindReplacementOffset()); } else if (requiredProposals[i].getKind() == CompletionProposal.FIELD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen - proposal.getLengthOfImportsAddedBehindReplacementOffset()); } else {
setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.TYPE_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.METHOD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.FIELD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else {
public void apply(IDocument document, char trigger, int offset) { try { super.apply(document, trigger, offset); if (fImportRewrite != null && fImportRewrite.hasRecordedChanges()) { int oldLen= document.getLength(); fImportRewrite.rewriteImports(new NullProgressMonitor()).apply(document, TextEdit.UPDATE_REGIONS); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } } catch (CoreException e) { JavaPlugin.log(e); } catch (BadLocationException e) { JavaPlugin.log(e); } }
/** * Creates and returns the import rewrite * if imports should be added at all. * * @return the import rewrite or <code>null</code> if no imports can or should be added */ private ImportRewrite createImportRewrite() { if (fCompilationUnit != null && shouldAddImports()) { try { CompilationUnit cu= getASTRoot(fCompilationUnit); if (cu == null) { ImportRewrite rewrite= StubUtility.createImportRewrite(fCompilationUnit, true); fImportContext= null; return rewrite; } else { ImportRewrite rewrite= StubUtility.createImportRewrite(cu, true); fImportContext= new ContextSensitiveImportRewriteContext(cu, fInvocationContext.getInvocationOffset(), rewrite); return rewrite; } } catch (CoreException x) { JavaPlugin.log(x); } } return null; }
fImportRewrite= createImportRewrite(); if (fImportRewrite != null) { if (proposalKind == CompletionProposal.TYPE_IMPORT) {
setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.TYPE_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.METHOD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else if (requiredProposals[i].getKind() == CompletionProposal.FIELD_IMPORT) { ImportCompletionProposal proposal= new ImportCompletionProposal(requiredProposals[i], fInvocationContext, coreProposal.getKind()); proposal.setReplacementOffset(getReplacementOffset()); proposal.apply(document); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } else {
@Override public void apply(IDocument document, char trigger, int offset) { try { super.apply(document, trigger, offset); if (fImportRewrite != null && fImportRewrite.hasRecordedChanges()) { int oldLen= document.getLength(); fImportRewrite.rewriteImports(new NullProgressMonitor()).apply(document, TextEdit.UPDATE_REGIONS); setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } } catch (CoreException e) { JavaPlugin.log(e); } catch (BadLocationException e) { JavaPlugin.log(e); } }
/** * Creates and returns the import rewrite * if imports should be added at all. * * @return the import rewrite or <code>null</code> if no imports can or should be added */ private ImportRewrite createImportRewrite() { if (fCompilationUnit != null && shouldAddImports()) { try { CompilationUnit cu= getASTRoot(fCompilationUnit); if (cu == null) { ImportRewrite rewrite= StubUtility.createImportRewrite(fCompilationUnit, true); fImportContext= null; return rewrite; } else { ImportRewrite rewrite= StubUtility.createImportRewrite(cu, true); fImportContext= new ContextSensitiveImportRewriteContext(cu, fInvocationContext.getInvocationOffset(), rewrite); return rewrite; } } catch (CoreException x) { JavaPlugin.log(x); } } return null; }
fImportRewrite= createImportRewrite(); if (fImportRewrite != null) { if (proposalKind == CompletionProposal.TYPE_IMPORT) {
@Override public final String getReplacementString() { if (!fReplacementStringComputed) setReplacementString(computeReplacementString()); return super.getReplacementString(); }
@Override public void apply(IDocument document, char trigger, int offset) { try { super.apply(document, trigger, offset); if (fImportRewrite != null && fImportRewrite.hasRecordedChanges()) { int oldLen= document.getLength(); TextEdit textEdit= fImportRewrite.rewriteImports(new NullProgressMonitor()); textEdit.apply(document, TextEdit.UPDATE_REGIONS); if (textEdit.getOffset() > getReplacementOffset()) fLengthOfImportsAddedBehindReplacementOffset= document.getLength() - oldLen; else fLengthOfImportsAddedBehindReplacementOffset= 0; setReplacementOffset(getReplacementOffset() + document.getLength() - oldLen); } } catch (CoreException e) { JavaPlugin.log(e); } catch (BadLocationException e) { JavaPlugin.log(e); } }
/** * Returns <code>true</code> if imports should be added. The return value depends on the context * and preferences only and does not take into account the contents of the compilation unit or * the kind of proposal. Even if <code>true</code> is returned, there may be cases where no * imports are added for the proposal. For example: * <ul> * <li>when completing within the import section</li> * <li>when completing informal javadoc references (e.g. within <code><code></code> * tags)</li> * <li>when completing a type that conflicts with an existing import</li> * <li>when completing an implicitly imported type (same package, <code>java.lang</code> * types)</li> * </ul> * <p> * The decision whether a qualified type or the simple type name should be inserted must take * into account these different scenarios. * </p> * * @return <code>true</code> if imports may be added, <code>false</code> if not */ private boolean shouldAddImports() { if (isInJavadoc() && !isJavadocProcessingEnabled()) return false; IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore(); return preferenceStore.getBoolean(PreferenceConstants.CODEASSIST_ADDIMPORT); }
/** * Creates and returns the import rewrite * if imports should be added at all. * * @return the import rewrite or <code>null</code> if no imports can or should be added */ private ImportRewrite createImportRewrite() { if (fCompilationUnit != null && shouldAddImports()) { try { CompilationUnit cu= getASTRoot(fCompilationUnit); if (cu == null) { ImportRewrite rewrite= StubUtility.createImportRewrite(fCompilationUnit, true); fImportContext= null; return rewrite; } else { ImportRewrite rewrite= StubUtility.createImportRewrite(cu, true); fImportContext= new ContextSensitiveImportRewriteContext(cu, fInvocationContext.getInvocationOffset(), rewrite); return rewrite; } } catch (CoreException x) { JavaPlugin.log(x); } } return null; }
fImportRewrite= createImportRewrite(); if (fImportRewrite != null) { if (proposalKind == CompletionProposal.TYPE_IMPORT) {
public final String getReplacementString() { if (!fReplacementStringComputed) setReplacementString(computeReplacementString()); return super.getReplacementString(); }
/** * Returns <code>true</code> if imports should be added. The return value depends on the context * and preferences only and does not take into account the contents of the compilation unit or * the kind of proposal. Even if <code>true</code> is returned, there may be cases where no * imports are added for the proposal. For example: * <ul> * <li>when completing within the import section</li> * <li>when completing informal javadoc references (e.g. within <code><code></code> * tags)</li> * <li>when completing a type that conflicts with an existing import</li> * <li>when completing an implicitly imported type (same package, <code>java.lang</code> * types)</li> * </ul> * <p> * The decision whether a qualified type or the simple type name should be inserted must take * into account these different scenarios. * </p> * * @return <code>true</code> if imports may be added, <code>false</code> if not */ private boolean shouldAddImports() { if (isInJavadoc() && !isJavadocProcessingEnabled()) return false; IPreferenceStore preferenceStore= JavaPlugin.getDefault().getPreferenceStore(); return preferenceStore.getBoolean(PreferenceConstants.CODEASSIST_ADDIMPORT); }