Bug 43352 IBuffer not line delimiter aware
20030919 The buffer adapter provided from org.eclipse.core.filebuffers nomalizes all text coming from IBuffer.append, IBuffer.replace and IBuffer.setContents to ensure line delimiter consistency. When working copies are created IBuffer.setContents is used what leads to the normalization of the whole source content. This is not wanted, only new text should be normalized. See test case PrimaryWorkingCopyTest.testLineDelimiterConsistency2 Suggestion is to - either add a new method setRawContent that does not normalize or - make IBuffer line delimiter aware: All client should first normalize what they want to insert or replace. A method IBuffer.normalize() could offer this. An extended request would be to also add the rest of line tracking methods to IBuffer: As offered by IDocument int getLineOfOffset(int offset) int getLineOffset(int line) int getLineLength(int line) IRegion getLineInformation(int line) IRegion getLineInformationOfOffset(int offset) int getNumberOfLines() String[] getLegalLineDelimiters() (all line delimiters in the document) String getLineDelimiter(int line) To implement this, the ILineTracker of org.eclipse.text can be used (but only created on demand).
org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/PrimaryWorkingCopyTest.java
} finally {
				wcopy.destroy();
			}
		} finally {
			JavaPlugin.getActivePage().closeAllEditors(false);
		}
		
		workingCopies= JavaUI.getSharedWorkingCopiesOnClasspath();
		result= doSearchForReferences("A", workingCopies);
		assertTrue("Should contain 1 references, contains: " + result.size(), result.size() == 1);
	}
	
	private static boolean BUG_43300= true;
	
	
	private List doSearchForReferences(String ref, IWorkingCopy[] workingCopies) throws JavaModelException {
		SearchEngine engine= new SearchEngine(workingCopies);
		if (BUG_43300 && workingCopies.length == 0) {
			engine= new SearchEngine();
		}
		
		IJavaSearchScope scope= SearchEngine.createWorkspaceScope();
		SearchResultCollector collector= new SearchResultCollector(null);
		engine.search(ResourcesPlugin.getWorkspace(), ref, IJavaSearchConstants.TYPE, IJavaSearchConstants.REFERENCES, scope, collector);
		return collector.getResults();
	}
	
	
}