1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

Further LocationMap fixes to remove loops.

This commit is contained in:
John Camelon 2005-04-06 18:05:52 +00:00
parent c3b7353bc6
commit 3119b13099
3 changed files with 19 additions and 7 deletions

View file

@ -1091,6 +1091,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
} }
public int getLineNumber(int nodeOffset) { public int getLineNumber(int nodeOffset) {
if( nodeOffset >= reader.buffer.length )
return 1;
int lineNumber = 1; int lineNumber = 1;
for( int i = 0; i < nodeOffset; ++i ) for( int i = 0; i < nodeOffset; ++i )
{ {
@ -2322,6 +2324,8 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog {
filename = result[0].getFileName(); filename = result[0].getFileName();
length = result[0].getNodeLength(); length = result[0].getNodeLength();
} else { } else {
if( result[i] != null && !result[i].getFileName().equals( filename ) )
return null;
if (result[i] != null if (result[i] != null
&& result[i].getNodeOffset() != (offset + length)) && result[i].getNodeOffset() != (offset + length))
return null; return null;

View file

@ -103,6 +103,7 @@ import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI; import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.DrillDownAdapter; import org.eclipse.ui.part.DrillDownAdapter;
import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.views.properties.PropertySheet; import org.eclipse.ui.views.properties.PropertySheet;
/** /**
@ -947,7 +948,7 @@ public class DOMAST extends ViewPart {
} }
private class ASTHighlighterAction extends Action { private class ASTHighlighterAction extends Action {
IEditorPart aPart = null; IEditorPart aPart = null;
public ASTHighlighterAction(IEditorPart part) { public ASTHighlighterAction(IEditorPart part) {
this.aPart = part; this.aPart = part;
@ -975,7 +976,7 @@ public class DOMAST extends ViewPart {
public void run() { public void run() {
ISelection selection = viewer.getSelection(); ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement(); Object obj = ((IStructuredSelection) selection).getFirstElement();
if (aPart instanceof CEditor && obj instanceof DOMASTNodeLeaf) { if (obj instanceof DOMASTNodeLeaf) {
String filename = ((DOMASTNodeLeaf) obj).getFilename(); String filename = ((DOMASTNodeLeaf) obj).getFilename();
if (filename.equals(DOMASTNodeLeaf.BLANK_STRING)) if (filename.equals(DOMASTNodeLeaf.BLANK_STRING))
@ -1001,10 +1002,17 @@ public class DOMAST extends ViewPart {
return; return;
} }
} }
((CEditor) aPart).selectAndReveal(((DOMASTNodeLeaf) obj).getOffset(),
((DOMASTNodeLeaf) obj).getLength()); if( aPart instanceof AbstractTextEditor )
{
((AbstractTextEditor) aPart).selectAndReveal(((DOMASTNodeLeaf) obj).getOffset(),
((DOMASTNodeLeaf) obj).getLength());
}
else
System.out.println( "aPart instanceof " + aPart.getClass().getName() );
aPart.getSite().getPage().activate(aPart.getSite().getPage().findView(VIEW_ID)); aPart.getSite().getPage().activate(aPart.getSite().getPage().findView(VIEW_ID));
} }
} }
} }

View file

@ -151,7 +151,7 @@ public class DOMASTNodeLeaf implements IAdaptable {
buffer.append(node); buffer.append(node);
return buffer.toString(); return buffer.toString();
} else if ( node instanceof IASTTranslationUnit ) { } else if ( node instanceof IASTTranslationUnit ) {
String fileName = getFilename(); String fileName = ((IASTTranslationUnit)node).getFilePath();
int lastSlash = fileName.lastIndexOf(FILE_SEPARATOR); int lastSlash = fileName.lastIndexOf(FILE_SEPARATOR);
if (lastSlash > 0) { if (lastSlash > 0) {
@ -277,7 +277,7 @@ public class DOMASTNodeLeaf implements IAdaptable {
{ {
if ( node == null ) return BLANK_STRING; if ( node == null ) return BLANK_STRING;
IASTNodeLocation [] location = node.getNodeLocations(); IASTNodeLocation [] location = node.getNodeLocations();
if( location.length > 0 && location[0] instanceof IASTFileLocation ) if( location.length == 1 && location[0] instanceof IASTFileLocation )
return ((IASTFileLocation)location[0]).getFileName(); return ((IASTFileLocation)location[0]).getFileName();
IASTFileLocation f = node.getTranslationUnit().flattenLocationsToFile(location); IASTFileLocation f = node.getTranslationUnit().flattenLocationsToFile(location);
if( f == null ) if( f == null )