langtools/src/share/classes/com/sun/tools/javap/SourceWriter.java
changeset 22163 3651128c74eb
parent 7681 1f0819a3341f
equal deleted inserted replaced
22162:3b3e23e67329 22163:3651128c74eb
   104     public boolean hasSource() {
   104     public boolean hasSource() {
   105         return (sourceLines.length > 0);
   105         return (sourceLines.length > 0);
   106     }
   106     }
   107 
   107 
   108     private void setLineMap(Code_attribute attr) {
   108     private void setLineMap(Code_attribute attr) {
   109         SortedMap<Integer, SortedSet<Integer>> map =
   109         SortedMap<Integer, SortedSet<Integer>> map = new TreeMap<>();
   110                 new TreeMap<Integer, SortedSet<Integer>>();
   110         SortedSet<Integer> allLines = new TreeSet<>();
   111         SortedSet<Integer> allLines = new TreeSet<Integer>();
       
   112         for (Attribute a: attr.attributes) {
   111         for (Attribute a: attr.attributes) {
   113             if (a instanceof LineNumberTable_attribute) {
   112             if (a instanceof LineNumberTable_attribute) {
   114                 LineNumberTable_attribute t = (LineNumberTable_attribute) a;
   113                 LineNumberTable_attribute t = (LineNumberTable_attribute) a;
   115                 for (LineNumberTable_attribute.Entry e: t.line_number_table) {
   114                 for (LineNumberTable_attribute.Entry e: t.line_number_table) {
   116                     int start_pc = e.start_pc;
   115                     int start_pc = e.start_pc;
   117                     int line = e.line_number;
   116                     int line = e.line_number;
   118                     SortedSet<Integer> pcLines = map.get(start_pc);
   117                     SortedSet<Integer> pcLines = map.get(start_pc);
   119                     if (pcLines == null) {
   118                     if (pcLines == null) {
   120                         pcLines = new TreeSet<Integer>();
   119                         pcLines = new TreeSet<>();
   121                         map.put(start_pc, pcLines);
   120                         map.put(start_pc, pcLines);
   122                     }
   121                     }
   123                     pcLines.add(line);
   122                     pcLines.add(line);
   124                     allLines.add(line);
   123                     allLines.add(line);
   125                 }
   124                 }
   126             }
   125             }
   127         }
   126         }
   128         lineMap = map;
   127         lineMap = map;
   129         lineList = new ArrayList<Integer>(allLines);
   128         lineList = new ArrayList<>(allLines);
   130     }
   129     }
   131 
   130 
   132     private void setSource(ClassFile cf) {
   131     private void setSource(ClassFile cf) {
   133         if (cf != classFile) {
   132         if (cf != classFile) {
   134             classFile = cf;
   133             classFile = cf;
   184 
   183 
   185     private static String[] splitLines(String text) {
   184     private static String[] splitLines(String text) {
   186         if (text == null)
   185         if (text == null)
   187             return new String[0];
   186             return new String[0];
   188 
   187 
   189         List<String> lines = new ArrayList<String>();
   188         List<String> lines = new ArrayList<>();
   190         lines.add(""); // dummy line 0
   189         lines.add(""); // dummy line 0
   191         try {
   190         try {
   192             BufferedReader r = new BufferedReader(new StringReader(text));
   191             BufferedReader r = new BufferedReader(new StringReader(text));
   193             String line;
   192             String line;
   194             while ((line = r.readLine()) != null)
   193             while ((line = r.readLine()) != null)