String newContent; if (!created.isEmpty()) { if (!container.exists()) { buf.append(lineDelim); if (importsStart > 0) { buf.insert(0, lineDelim); buf.insert(0, lineDelim); } else { buf.append(lineDelim); }
if (!container.exists()) { buf.append(lineDelim); if (importsStart > 0) { buf.insert(0, lineDelim); buf.insert(0, lineDelim); } else { buf.append(lineDelim);
	private void performCreate(ArrayList created, IDocument doc) throws JavaModelException {		int importsStart, importsLen;				// 1GF5UU0: ITPJUI:WIN2000 - "Organize Imports" in java editor inserts lines in wrong format		String lineDelim= StubUtility.getLineDelimiterFor(doc);				int lastPos;		StringBuffer buf= new StringBuffer();		IImportContainer container= fCompilationUnit.getImportContainer();		if (container.exists()) {			ISourceRange importSourceRange= container.getSourceRange();			importsStart= importSourceRange.getOffset();			importsLen= importSourceRange.getLength();			if (!fReplaceExistingImports) {				buf.append(container.getSource());			}			lastPos= buf.length();		} else {			importsStart= getPackageStatementEndPos();			importsLen= 0;			lastPos= 0;					}				// all (top level) types in this cu		IType[] topLevelTypes= fCompilationUnit.getTypes();			int lastCategory= -1;				// create from last to first to not invalidate positions		for (int i= fPackageEntries.size() -1; i >= 0; i--) {			PackageEntry pack= (PackageEntry) fPackageEntries.get(i);			int nImports= pack.getNumberOfImports();			if (nImports > 0) {				String packName= pack.getName();				if (isImportNeeded(packName, topLevelTypes)) {					// add empty line					if (pack.getCategory() != lastCategory) {						if (lastCategory != -1) {							buf.insert(lastPos, lineDelim);						}						lastCategory= pack.getCategory();					}										if (nImports >= fImportOnDemandThreshold) {						// assume no existing imports						String starimport= packName + ".*"; //$NON-NLS-1$						lastPos= insertImport(buf, lastPos, starimport, lineDelim);						created.add(fCompilationUnit.getImport(starimport));					} else {						for (int j= nImports - 1; j >= 0; j--) {							IImportDeclaration currDecl= pack.getImportAt(j);							if (fReplaceExistingImports || !currDecl.exists()) {								lastPos= insertImport(buf, lastPos, currDecl.getElementName(), lineDelim);								created.add(currDecl);							} else {								lastPos= currDecl.getSourceRange().getOffset() - importsStart;							}						}					}				}			}		}				try {			String newContent;			if (!created.isEmpty()) {				if (!container.exists()) {					buf.append(lineDelim);	// nl after import (<nl+>)					if (importsStart > 0) { // package statement						buf.insert(0, lineDelim);						buf.insert(0, lineDelim);  //<pack><nl*><nl*><import><nl+><nl-pack><cl>					} else {						buf.append(lineDelim);					}				}				newContent= buf.toString();			} else {				newContent= ""; //$NON-NLS-1$			}			if (hasChanged(doc, importsStart, importsLen, newContent)) {				doc.replace(importsStart, importsLen, newContent);			}		} catch (BadLocationException e) {			// can not happen			JavaPlugin.log(e);		}	}