1 24 25 package org.aspectj.compiler.base; 26 import org.aspectj.compiler.base.ast.*; 27 28 import java.util.*; 29 import java.io.*; 30 31 import org.aspectj.tools.ide.SourceLine; 32 import org.aspectj.util.CollectionUtil; 33 34 public class LineMap { 35 private File outputFile; 36 private String outputDirectory; 37 private String outputFileName; 38 39 private int outputLine = 0; 40 41 private ASTObject sourceNode = null; 42 45 private Map outputToSource; 46 private Map sourceToOutput; 47 48 public LineMap(File outputFile, Map outputToSource, Map sourceToOutput) throws IOException { 49 this.outputFile = outputFile; 50 outputFileName = outputFile.getCanonicalPath(); 51 outputDirectory = new File(outputFileName).getParent(); 52 this.outputToSource = outputToSource; 53 this.sourceToOutput = sourceToOutput; 54 } 55 56 57 final String getOutputFile() { 58 return outputFileName; 59 } 60 61 public final boolean hasCurrentSourceLine() { 62 return sourceNode != null; 63 } 64 65 public final int getCurrentSourceLine() { 66 return sourceNode != null ? sourceNode.getBeginLine() : -1; 67 } 68 69 public final String getCurrentSourceFile() { 70 return sourceNode != null ? sourceNode.getSourceFileName() : null; 71 } 72 73 public final void addLineMappings(SourceLine sourceLine, SourceLine outputLine) { 74 Map map = CollectionUtil.getMapInMap(outputToSource, outputDirectory); 75 synchronized (map) { 76 map.put(outputLine, sourceLine); 77 } 78 79 map = CollectionUtil.getMapInMap(sourceToOutput, sourceNode.getSourceDirectoryName()); synchronized (map) { 81 map.put(sourceLine, outputLine); 82 } 83 } 84 85 86 public final void noteNewLine() { 87 if (sourceNode != null) { 88 addLineMappings(new SourceLine(sourceNode.getSourceFileName(), sourceNode.getBeginLine()), 89 new SourceLine(getOutputFile(), outputLine)); 90 } 91 92 outputLine += 1; 93 sourceNode = null; 94 } 95 96 public final void noteNode(ASTObject node) { 97 99 if (node.getStartPosition() != -1) { 102 sourceNode = node; 103 } 106 } 107 } 108 | Popular Tags |