From 24648ae9edadb211d4dc86858e72f017896a9a09 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Mon, 30 May 2005 20:32:56 +0000 Subject: [PATCH] Moved clients towards IASTNode.getFileLocation() and away from IASTTranslationUnit.flattenLocations( ... ). --- .../tests/ast2/AST2SelectionParseTest.java | 2 +- .../tests/ast2/DOMLocationInclusionTests.java | 2 +- .../tests/ast2/DOMLocationMacroTests.java | 6 ++-- .../cdt/internal/core/dom/parser/ASTNode.java | 6 +++- .../core/dom/parser/ProblemBinding.java | 4 +-- .../core/dom/parser/c/CASTProblem.java | 28 ++++++++----------- .../core/dom/parser/cpp/CPPASTProblem.java | 28 ++++++++----------- .../core/parser/scanner2/LocationMap.java | 2 +- .../cdt/ui/tests/DOMAST/DOMASTNodeLeaf.java | 15 ++-------- .../tests/DOMAST/DOMDisplaySearchNames.java | 2 +- .../cdt/internal/ui/search/DOMQuery.java | 2 +- .../actions/OpenDeclarationsAction.java | 2 +- .../search/actions/OpenDefinitionAction.java | 2 +- 13 files changed, 41 insertions(+), 60 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java index aaacc1d99e1..5027d93ff8a 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2SelectionParseTest.java @@ -1632,7 +1632,7 @@ public class AST2SelectionParseTest extends AST2SelectionParseBaseTest { IASTTranslationUnit tu = parse(file, ParserLanguage.CPP, false, true); IASTPreprocessorStatement[] stmts = tu.getAllPreprocessorStatements(); - IASTFileLocation fileLoc = tu.flattenLocationsToFile(stmts[5].getNodeLocations()); + IASTFileLocation fileLoc = stmts[5].getFileLocation(); int fileOffset = test2_h.indexOf("#ifndef _WINGDI_H"); int fileLocOffset = fileLoc.getNodeOffset(); assertEquals(fileOffset, fileLocOffset); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java index 8cd2b31fa79..44d5371d6b8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationInclusionTests.java @@ -344,7 +344,7 @@ public class DOMLocationInclusionTests extends FileBasePluginTest { IASTPreprocessorMacroDefinition INCLUDE_H = macro_defs[1]; final IASTNodeLocation[] nodeLocations = INCLUDE_H.getName().getNodeLocations(); assertEquals( nodeLocations.length, 1 ); - final IASTFileLocation flatLoc = tu.flattenLocationsToFile( nodeLocations ); + final IASTFileLocation flatLoc = INCLUDE_H.getName().getFileLocation(); assertNotNull( flatLoc ); assertEquals( include_file.getLocation().toOSString(), flatLoc.getFileName() ); assertEquals( inc_file_code.indexOf( "#define _INCLUDE_H_") + "#define ".length(), flatLoc.getNodeOffset() ); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java index 1154cddc801..1ff20107243 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/DOMLocationMacroTests.java @@ -209,7 +209,7 @@ public class DOMLocationMacroTests extends AST2BaseTest { IASTFileLocation tenth_loc = (IASTFileLocation) nodeLocations[9]; assertEquals( 1, tenth_loc.getNodeLength() ); - final IASTFileLocation flatLocation = tu.flattenLocationsToFile(nodeLocations); + final IASTFileLocation flatLocation = var.getFileLocation(); assertNotNull( flatLocation); assertEquals( code.indexOf("XYZ IT C_PO C_PO V;"), flatLocation.getNodeOffset() ); //$NON-NLS-1$ assertEquals( "XYZ IT C_PO C_PO V;".length(), flatLocation.getNodeLength() ); //$NON-NLS-1$ @@ -244,13 +244,13 @@ public class DOMLocationMacroTests extends AST2BaseTest { IASTFileLocation loc_4 = (IASTFileLocation) locations[3]; assertEquals( loc_4.getNodeOffset(), code.indexOf( ";")); //$NON-NLS-1$ assertEquals( loc_4.getNodeLength(), 1 ); - IASTFileLocation flat = tu.flattenLocationsToFile(locations); + IASTFileLocation flat = memchr.getFileLocation(); assertEquals( flat.getNodeOffset() , code.indexOf( "_PTR _EXFUN(memchr,(const _PTR, int, size_t));")); //$NON-NLS-1$ assertEquals( flat.getNodeLength(), "_PTR _EXFUN(memchr,(const _PTR, int, size_t));".length() ); //$NON-NLS-1$ IASTDeclarator d = memchr.getDeclarators()[0]; final IASTNodeLocation[] declaratorLocations = d.getNodeLocations(); - IASTFileLocation f = tu.flattenLocationsToFile( declaratorLocations ); + IASTFileLocation f = d.getFileLocation(); assertEquals( code.indexOf( "_PTR _EXFUN(memchr,(const _PTR, int, size_t))"), f.getNodeOffset() ); //$NON-NLS-1$ assertEquals( "_PTR _EXFUN(memchr,(const _PTR, int, size_t))".length(), f.getNodeLength() ); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java index f9c918f0188..51dcc823461 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ASTNode.java @@ -53,6 +53,7 @@ public abstract class ASTNode implements IASTNode { } private IASTNodeLocation[] locations = null; + private IASTFileLocation fileLocation = null; /* * (non-Javadoc) @@ -83,6 +84,9 @@ public abstract class ASTNode implements IASTNode { } public IASTFileLocation getFileLocation() { - return getTranslationUnit().flattenLocationsToFile( getNodeLocations() ); + if( fileLocation != null ) + return fileLocation; + fileLocation = getTranslationUnit().flattenLocationsToFile( getNodeLocations() ); + return fileLocation; } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java index 1b4a5694204..e0868d92734 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/ProblemBinding.java @@ -20,7 +20,6 @@ import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IScope; @@ -197,8 +196,7 @@ public class ProblemBinding implements IProblemBinding, IType, IScope { public int getLineNumber() { if( node != null ){ - IASTNodeLocation [] locs = node.getNodeLocations(); - IASTFileLocation fileLoc = node.getTranslationUnit().flattenLocationsToFile( locs ); + IASTFileLocation fileLoc = node.getFileLocation(); return fileLoc.getStartingLineNumber(); } return -1; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java index d9334e2aaba..603b45ff187 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/c/CASTProblem.java @@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.internal.core.parser.ParserMessages; @@ -270,24 +269,19 @@ public class CASTProblem extends CASTNode implements IASTProblem { msg = MessageFormat.format(msg, new Object[] { new String(arg) }); } - IASTNodeLocation [] locs = getNodeLocations(); + String file = null; int offset = 0; - if( locs != null && locs.length == 1 && locs[0] instanceof IASTFileLocation ){ - file = ((IASTFileLocation) locs[0]).getFileName(); - offset = locs[0].getNodeOffset(); - } else { - IASTFileLocation f = getTranslationUnit().flattenLocationsToFile(locs); - if( f == null ) - { - file = ""; //$NON-NLS-1$ - offset = 0; - } - else - { - file = f.getFileName(); - offset = f.getNodeOffset(); - } + IASTFileLocation f = getFileLocation(); + if( f == null ) + { + file = ""; //$NON-NLS-1$ + offset = 0; + } + else + { + file = f.getFileName(); + offset = f.getNodeOffset(); } Object[] args = new Object[] { msg, file, new Integer( offset ) }; //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java index edfd9e7d571..9732fb0d2e1 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTProblem.java @@ -18,7 +18,6 @@ import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTNodeLocation; import org.eclipse.cdt.core.dom.ast.IASTProblem; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.internal.core.parser.ParserMessages; @@ -269,24 +268,19 @@ public class CPPASTProblem extends CPPASTNode implements IASTProblem { msg = MessageFormat.format(msg, new Object[] { new String(arg) }); } - IASTNodeLocation [] locs = getNodeLocations(); + String file = null; int offset = 0; - if( locs != null && locs.length == 1 && locs[0] instanceof IASTFileLocation ){ - file = ((IASTFileLocation) locs[0]).getFileName(); - offset = locs[0].getNodeOffset(); - } else { - IASTFileLocation f = getTranslationUnit().flattenLocationsToFile(locs); - if( f == null ) - { - file = ""; //$NON-NLS-1$ - offset = 0; - } - else - { - file = f.getFileName(); - offset = f.getNodeOffset(); - } + IASTFileLocation f = getFileLocation(); + if( f == null ) + { + file = ""; //$NON-NLS-1$ + offset = 0; + } + else + { + file = f.getFileName(); + offset = f.getNodeOffset(); } Object[] args = new Object[] { msg, file, new Integer(offset) }; //$NON-NLS-1$ message = ParserMessages.getFormattedString(AST_PROBLEM_PATTERN, args); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java index 6cc9a1b9fd9..5491df4c4f3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner2/LocationMap.java @@ -91,7 +91,7 @@ public class LocationMap implements ILocationResolver, IScannerPreprocessorLog { } public IASTFileLocation asFileLocation() { - return rootNode.flattenLocationsToFile(getExpansionLocations()); + return rootNode.flattenLocationsToFile(locations); } public String toString() { diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeLeaf.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeLeaf.java index 71b51ad2b49..6c96d860928 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeLeaf.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMASTNodeLeaf.java @@ -284,30 +284,21 @@ public class DOMASTNodeLeaf implements IAdaptable { public String getFilename() { if ( node == null ) return BLANK_STRING; - IASTNodeLocation [] location = node.getNodeLocations(); - if( location.length == 1 && location[0] instanceof IASTFileLocation ) - return ((IASTFileLocation)location[0]).getFileName(); - IASTFileLocation f = node.getTranslationUnit().flattenLocationsToFile(location); + IASTFileLocation f = node.getFileLocation(); if( f == null ) return BLANK_STRING; //$NON-NLS-1$ return f.getFileName(); } public int getOffset() { - IASTNodeLocation [] location = node.getNodeLocations(); - if( location.length == 1 && location[0] instanceof IASTFileLocation ) - return location[0].getNodeOffset(); - IASTFileLocation f = node.getTranslationUnit().flattenLocationsToFile(location); + IASTFileLocation f = node.getFileLocation(); if( f == null ) return 0; //$NON-NLS-1$ return f.getNodeOffset(); } public int getLength() { - IASTNodeLocation [] location = node.getNodeLocations(); - if( location.length == 1 && location[0] instanceof IASTFileLocation ) - return location[0].getNodeLength(); - IASTFileLocation f = node.getTranslationUnit().flattenLocationsToFile(location); + IASTFileLocation f = node.getFileLocation(); if( f == null ) return 0; //$NON-NLS-1$ return f.getNodeLength(); diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMDisplaySearchNames.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMDisplaySearchNames.java index 473e6ff637a..2c8f68df6d1 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMDisplaySearchNames.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMDisplaySearchNames.java @@ -93,7 +93,7 @@ public class DOMDisplaySearchNames extends CSearchQuery implements ISearchQuery int start = 0; int end = 0; if ( nodes[i] != null ) { - IASTFileLocation location = nodes[i].getTranslationUnit().flattenLocationsToFile( nodes[i].getNodeLocations() ); + IASTFileLocation location = nodes[i].getFileLocation(); if (location == null) { return new Status(IStatus.ERROR, CUIPlugin.getPluginId(), 0, "Null Location associated with IASTFileLocation.", null); //$NON-NLS-1$ } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java index 01be2960c25..45782cd9dc5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/DOMQuery.java @@ -118,7 +118,7 @@ public class DOMQuery extends CSearchQuery implements ISearchQuery { int end = 0; if ( foundNames[i].getTranslationUnit() != null ) { - IASTFileLocation location = foundNames[i].getTranslationUnit().flattenLocationsToFile( foundNames[i].getNodeLocations() ); + IASTFileLocation location = foundNames[i].getFileLocation(); fileName = location.getFileName(); start = location.getNodeOffset(); end = location.getNodeOffset() + location.getNodeLength(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java index 243af5e9c0b..97ae0b048b1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDeclarationsAction.java @@ -149,7 +149,7 @@ public class OpenDeclarationsAction extends SelectionParseAction implements IUpd int end=0; if ( domNames[0].getTranslationUnit() != null ) { - IASTFileLocation location = domNames[0].getTranslationUnit().flattenLocationsToFile( domNames[0].getNodeLocations() ); + IASTFileLocation location = domNames[0].getFileLocation(); fileName = location.getFileName(); start = location.getNodeOffset(); end = location.getNodeOffset() + location.getNodeLength(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java index 4c0c9e82c17..e647e1762d4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/OpenDefinitionAction.java @@ -161,7 +161,7 @@ public class OpenDefinitionAction extends SelectionParseAction implements int end=0; if ( domNames[0].getTranslationUnit() != null ) { - IASTFileLocation location = domNames[0].getTranslationUnit().flattenLocationsToFile( domNames[0].getNodeLocations() ); + IASTFileLocation location = domNames[0].getFileLocation(); fileName = location.getFileName(); start = location.getNodeOffset(); end = location.getNodeOffset() + location.getNodeLength();