protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException { // avoid adding imports when inside imports container if (impRewrite != null && fFullyQualifiedTypeName != null) { String replacementString= getReplacementString(); String qualifiedType= fFullyQualifiedTypeName; if (qualifiedType.indexOf('.') != -1 && replacementString.startsWith(qualifiedType) && !replacementString.endsWith(String.valueOf(';'))) { IType[] types= impRewrite.getCompilationUnit().getTypes(); if (types.length > 0 && types[0].getSourceRange().getOffset() <= offset) { // ignore positions above type. setReplacementString(impRewrite.addImport(getReplacementString())); return true; } } } return false; }
/** * Updates the replacement string. * * @param document the document * @param trigger the trigger * @param offset the offset * @param impRewrite the import rewrite * @return <code>true</code> if the cursor position should be updated, <code>false</code> otherwise * @throws BadLocationException if accessing the document fails * @throws CoreException if something else fails */ protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException { // avoid adding imports when inside imports container if (impRewrite != null && fFullyQualifiedTypeName != null) { String replacementString= getReplacementString(); String qualifiedType= fFullyQualifiedTypeName; if (qualifiedType.indexOf('.') != -1 && replacementString.startsWith(qualifiedType) && !replacementString.endsWith(String.valueOf(';'))) { IType[] types= impRewrite.getCompilationUnit().getTypes(); if (types.length > 0 && types[0].getSourceRange().getOffset() <= offset) { // ignore positions above type. setReplacementString(impRewrite.addImport(getReplacementString())); return true; } } } return false; }
/** * Updates the replacement string. * * @param document the document * @param trigger the trigger * @param offset the offset * @param impRewrite the import rewrite * @return <code>true</code> if the cursor position should be updated, <code>false</code> otherwise * @throws BadLocationException if accessing the document fails * @throws CoreException if something else fails */ protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException { // avoid adding imports when inside imports container if (impRewrite != null && fFullyQualifiedTypeName != null) { String replacementString= getReplacementString(); String qualifiedType= fFullyQualifiedTypeName; if (qualifiedType.indexOf('.') != -1 && replacementString.startsWith(qualifiedType) && !replacementString.endsWith(String.valueOf(';'))) { IType[] types= impRewrite.getCompilationUnit().getTypes(); if (types.length > 0 && types[0].getSourceRange().getOffset() <= offset) { // ignore positions above type. setReplacementString(impRewrite.addImport(getReplacementString())); return true; } } } return false; }