mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix Compare Viewer highlighting
This commit is contained in:
parent
2631135c07
commit
c1ecf194d1
2 changed files with 73 additions and 36 deletions
|
@ -27,6 +27,7 @@ import org.eclipse.swt.widgets.Composite;
|
|||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
|
@ -130,7 +131,7 @@ public class CMergeViewer extends TextMergeViewer {
|
|||
if (fSourceViewerConfiguration == null) {
|
||||
CTextTools tools= CUIPlugin.getDefault().getTextTools();
|
||||
IPreferenceStore store = getPreferenceStore();
|
||||
fSourceViewerConfiguration = new CSourceViewerConfiguration(tools.getColorManager(), store, null, null);
|
||||
fSourceViewerConfiguration = new CSourceViewerConfiguration(tools.getColorManager(), store, null, ICPartitions.C_PARTITIONING);
|
||||
}
|
||||
return fSourceViewerConfiguration;
|
||||
}
|
||||
|
@ -139,6 +140,16 @@ public class CMergeViewer extends TextMergeViewer {
|
|||
return CUIPlugin.getResourceString(TITLE);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.compare.contentmergeviewer.TextMergeViewer#getDocumentPartitioning()
|
||||
*/
|
||||
protected String getDocumentPartitioning() {
|
||||
return ICPartitions.C_PARTITIONING;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.compare.contentmergeviewer.TextMergeViewer#getDocumentPartitioner()
|
||||
*/
|
||||
protected IDocumentPartitioner getDocumentPartitioner() {
|
||||
return CUIPlugin.getDefault().getTextTools().createDocumentPartitioner();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2006 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* QNX Software System
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.compare;
|
||||
|
||||
|
@ -16,6 +17,19 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.eclipse.compare.CompareUI;
|
||||
import org.eclipse.compare.IEditableContent;
|
||||
import org.eclipse.compare.IEncodedStreamContentAccessor;
|
||||
import org.eclipse.compare.IStreamContentAccessor;
|
||||
import org.eclipse.compare.structuremergeviewer.Differencer;
|
||||
import org.eclipse.compare.structuremergeviewer.IDiffContainer;
|
||||
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
|
||||
import org.eclipse.compare.structuremergeviewer.IStructureCreator;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
|
@ -28,15 +42,8 @@ import org.eclipse.cdt.core.parser.ParserMode;
|
|||
import org.eclipse.cdt.core.parser.ParserUtil;
|
||||
import org.eclipse.cdt.core.parser.ScannerInfo;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.compare.IEditableContent;
|
||||
import org.eclipse.compare.IStreamContentAccessor;
|
||||
import org.eclipse.compare.structuremergeviewer.Differencer;
|
||||
import org.eclipse.compare.structuremergeviewer.IDiffContainer;
|
||||
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
|
||||
import org.eclipse.compare.structuremergeviewer.IStructureCreator;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.CDocumentSetupParticipant;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -53,19 +60,23 @@ public class CStructureCreator implements IStructureCreator {
|
|||
|
||||
public IStructureComparator getStructure(Object input) {
|
||||
|
||||
String s = null;
|
||||
if (input instanceof IStreamContentAccessor) {
|
||||
try {
|
||||
s = readString(((IStreamContentAccessor) input).getContents());
|
||||
} catch (CoreException ex) {
|
||||
IDocument doc= CompareUI.getDocument(input);
|
||||
if (doc == null) {
|
||||
if (input instanceof IStreamContentAccessor) {
|
||||
String s = null;
|
||||
try {
|
||||
s = readString((IStreamContentAccessor) input);
|
||||
} catch (CoreException ex) {
|
||||
}
|
||||
if (s != null) {
|
||||
doc = new Document(s);
|
||||
new CDocumentSetupParticipant().setup(doc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (s == null) {
|
||||
s = new String();
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
Document doc = new Document(s);
|
||||
|
||||
CNode root = new CNode(null, ICElement.C_UNIT, "root", doc, 0, 0); //$NON-NLS-1$
|
||||
|
||||
ISourceElementRequestor builder = new CParseTreeBuilder(root, doc);
|
||||
|
@ -74,7 +85,7 @@ public class CStructureCreator implements IStructureCreator {
|
|||
//are bugs while parsing C files, we might want to create a separate Structure
|
||||
//compare for c files, but we'll never be completely right about .h files
|
||||
IScanner scanner =
|
||||
ParserFactory.createScanner(new CodeReader(s.toCharArray()), new ScannerInfo(), ParserMode.QUICK_PARSE, ParserLanguage.CPP, builder, new NullLogService(), null);
|
||||
ParserFactory.createScanner(new CodeReader(doc.get().toCharArray()), new ScannerInfo(), ParserMode.QUICK_PARSE, ParserLanguage.CPP, builder, new NullLogService(), null);
|
||||
IParser parser = ParserFactory.createParser(scanner, builder, ParserMode.QUICK_PARSE, ParserLanguage.CPP, ParserUtil.getParserLogService() );
|
||||
parser.parse();
|
||||
} catch (Exception e) {
|
||||
|
@ -122,41 +133,56 @@ public class CStructureCreator implements IStructureCreator {
|
|||
if (node instanceof IStreamContentAccessor) {
|
||||
IStreamContentAccessor sca = (IStreamContentAccessor) node;
|
||||
try {
|
||||
return readString(sca.getContents());
|
||||
return readString(sca);
|
||||
} catch (CoreException ex) {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns null if an error occurred.
|
||||
*/
|
||||
private static String readString(InputStream is) {
|
||||
private static String readString(IStreamContentAccessor sa) throws CoreException {
|
||||
InputStream is= sa.getContents();
|
||||
if (is != null) {
|
||||
String encoding= null;
|
||||
if (sa instanceof IEncodedStreamContentAccessor) {
|
||||
try {
|
||||
encoding= ((IEncodedStreamContentAccessor) sa).getCharset();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (encoding == null)
|
||||
encoding= ResourcesPlugin.getEncoding();
|
||||
return readString(is, encoding);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String readString(InputStream is, String encoding) {
|
||||
if (is == null)
|
||||
return null;
|
||||
BufferedReader reader = null;
|
||||
BufferedReader reader= null;
|
||||
try {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
char[] part = new char[2048];
|
||||
int read = 0;
|
||||
reader = new BufferedReader(new InputStreamReader(is));
|
||||
StringBuffer buffer= new StringBuffer();
|
||||
char[] part= new char[2048];
|
||||
int read= 0;
|
||||
reader= new BufferedReader(new InputStreamReader(is, encoding));
|
||||
|
||||
while ((read = reader.read(part)) != -1)
|
||||
while ((read= reader.read(part)) != -1)
|
||||
buffer.append(part, 0, read);
|
||||
|
||||
|
||||
return buffer.toString();
|
||||
|
||||
|
||||
} catch (IOException ex) {
|
||||
// NeedWork
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException ex) {
|
||||
// silently ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue