]> source.dussan.org Git - aspectj.git/commitdiff
Bug 33011. Added correct calculations for start and end
authoracolyer <acolyer>
Tue, 25 Feb 2003 17:07:22 +0000 (17:07 +0000)
committeracolyer <acolyer>
Tue, 25 Feb 2003 17:07:22 +0000 (17:07 +0000)
line for CompilationUnitDeclarations and for sub-nodes
(makeLocation).

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmBuilder.java

index 83be0af506bae66acc6f8de708d3cd4852dd19e0..116ce05b3ca8131d73004c73e5f5c70d2102b6fd 100644 (file)
@@ -15,27 +15,42 @@ package org.aspectj.ajdt.internal.core.builder;
 
 import java.io.File;
 import java.io.IOException;
-import java.text.CollationElementIterator;
-import java.util.*;
-import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Stack;
 
-import org.aspectj.ajdt.internal.compiler.ast.*;
 import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration;
-import org.aspectj.ajdt.internal.compiler.lookup.*;
-import org.aspectj.ajdt.internal.compiler.lookup.EclipseShadow;
-import org.aspectj.asm.*;
+import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration;
+import org.aspectj.ajdt.internal.compiler.ast.DeclareDeclaration;
+import org.aspectj.ajdt.internal.compiler.ast.InterTypeDeclaration;
+import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration;
+import org.aspectj.ajdt.internal.compiler.lookup.EclipseWorld;
+import org.aspectj.asm.ProgramElementNode;
 import org.aspectj.asm.StructureModel;
-import org.aspectj.bridge.*;
+import org.aspectj.asm.StructureModelManager;
+import org.aspectj.asm.StructureNode;
 import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.SourceLocation;
 import org.aspectj.weaver.Member;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.internal.compiler.*;
 import org.eclipse.jdt.internal.compiler.AbstractSyntaxTreeVisitorAdapter;
-import org.eclipse.jdt.internal.compiler.ast.*;
+import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.AnonymousLocalTypeDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.AstNode;
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
-import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
-import org.eclipse.jdt.internal.compiler.lookup.*;
+import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.ImportReference;
+import org.eclipse.jdt.internal.compiler.ast.Initializer;
+import org.eclipse.jdt.internal.compiler.ast.LocalTypeDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.MemberTypeDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
+import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
 import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
+import org.eclipse.jdt.internal.compiler.lookup.MethodScope;
 import org.eclipse.jdt.internal.compiler.problem.ProblemHandler;
 
 public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
@@ -52,7 +67,12 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
        private void internalBuild(CompilationUnitDeclaration unit, StructureModel structureModel) {
                currCompilationResult = unit.compilationResult();
                File file = new File(new String(unit.getFileName()));
-               ISourceLocation sourceLocation = new SourceLocation(file, 1);           
+               // AMC - use the source start and end from the compilation unit decl
+               //ISourceLocation sourceLocation = new SourceLocation(file, 1);
+               int startLine = getStartLine(unit);
+               int endLine = getEndLine(unit);         
+               ISourceLocation sourceLocation = new SourceLocation(file, 
+                       startLine, endLine);            
 
                ProgramElementNode cuNode = new ProgramElementNode(
                        new String(file.getName()),
@@ -93,7 +113,8 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
                unit.traverse(this, unit.scope);  
                
                try {
-               StructureModelManager.INSTANCE.getStructureModel().getFileMap().put(
+               //StructureModelManager.INSTANCE.getStructureModel().getFileMap().put(
+                       StructureModelManager.INSTANCE.getStructureModel().addToFileMap(
                        file.getCanonicalPath(),//.replace('\\', '/'),
                        cuNode
                );
@@ -341,11 +362,98 @@ public class AsmBuilder extends AbstractSyntaxTreeVisitorAdapter {
        // ??? handle non-existant files
        private ISourceLocation makeLocation(AstNode node) {
                String fileName = new String(currCompilationResult.getFileName());
-               int line = ProblemHandler.searchLineNumber(
-                               currCompilationResult.lineSeparatorPositions, 
-                               node.sourceStart);
-               return new SourceLocation(new File(fileName), line);    
+               // AMC - different strategies based on node kind
+               int startLine = getStartLine(node);
+               int endLine = getEndLine(node);
+               ISourceLocation loc = null;
+               if ( startLine <= endLine ) {
+                       // found a valid end line for this node...
+                       loc = new SourceLocation(new File(fileName), startLine, endLine);                       
+               } else {
+                       loc = new SourceLocation(new File(fileName), startLine);
+               }
+               return loc;
+       }
+
+
+       // AMC - overloaded set of methods to get start and end lines for
+       // various ASTNode types. They have no common ancestor in the
+       // hierarchy!!
+       private int getStartLine( AstNode n){
+               if (  n instanceof AbstractVariableDeclaration ) return getStartLine( (AbstractVariableDeclaration)n);
+               if (  n instanceof AbstractMethodDeclaration ) return getStartLine( (AbstractMethodDeclaration)n);
+               if (  n instanceof TypeDeclaration ) return getStartLine( (TypeDeclaration)n);
+               return ProblemHandler.searchLineNumber(
+                       currCompilationResult.lineSeparatorPositions,
+                       n.sourceStart);         
+       }
+       
+       // AMC - overloaded set of methods to get start and end lines for
+       // various ASTNode types. They have no common ancestor in the
+       // hierarchy!!
+       private int getEndLine( AstNode n){
+               if (  n instanceof AbstractVariableDeclaration ) return getEndLine( (AbstractVariableDeclaration)n);
+               if (  n instanceof AbstractMethodDeclaration ) return getEndLine( (AbstractMethodDeclaration)n);
+               if (  n instanceof TypeDeclaration ) return getEndLine( (TypeDeclaration)n);    
+               return ProblemHandler.searchLineNumber(
+                       currCompilationResult.lineSeparatorPositions,
+                       n.sourceEnd);
+       }
+       
+       // AMC - overloaded set of methods to get start and end lines for
+       // various ASTNode types. They have no common ancestor in the
+       // hierarchy!!
+       private int getStartLine( AbstractVariableDeclaration avd ) {
+               return ProblemHandler.searchLineNumber(
+                       currCompilationResult.lineSeparatorPositions,
+                       avd.declarationSourceStart);
+       }
+       
+       // AMC - overloaded set of methods to get start and end lines for
+       // various ASTNode types. They have no common ancestor in the
+       // hierarchy!!
+       private int getEndLine( AbstractVariableDeclaration avd ){
+               return ProblemHandler.searchLineNumber(
+                       currCompilationResult.lineSeparatorPositions,
+                       avd.declarationSourceEnd);              
+       }
+       
+       // AMC - overloaded set of methods to get start and end lines for
+       // various ASTNode types. They have no common ancestor in the
+       // hierarchy!!
+       private int getStartLine( AbstractMethodDeclaration amd ){
+               return ProblemHandler.searchLineNumber(
+                       currCompilationResult.lineSeparatorPositions,
+                       amd.declarationSourceStart);
+       }
+       
+       // AMC - overloaded set of methods to get start and end lines for
+       // various ASTNode types. They have no common ancestor in the
+       // hierarchy!!
+       private int getEndLine( AbstractMethodDeclaration amd) {
+               return ProblemHandler.searchLineNumber(
+                       currCompilationResult.lineSeparatorPositions,
+                       amd.declarationSourceEnd);
        }
+       
+       // AMC - overloaded set of methods to get start and end lines for
+       // various ASTNode types. They have no common ancestor in the
+       // hierarchy!!
+       private int getStartLine( TypeDeclaration td ){
+               return ProblemHandler.searchLineNumber(
+                       currCompilationResult.lineSeparatorPositions,
+                       td.declarationSourceStart);
+       }
+       
+       // AMC - overloaded set of methods to get start and end lines for
+       // various ASTNode types. They have no common ancestor in the
+       // hierarchy!!
+       private int getEndLine( TypeDeclaration td){
+               return ProblemHandler.searchLineNumber(
+                       currCompilationResult.lineSeparatorPositions,
+                       td.declarationSourceEnd);
+       }
+       
 
        // !!! move or replace
        private String translateAdviceName(String label) {