• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2013, Google Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *     * Neither the name of Google Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from
17  * this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 package org.jf.dexlib2.builder;
33 
34 import org.jf.dexlib2.builder.debug.*;
35 import org.jf.dexlib2.iface.instruction.Instruction;
36 import org.jf.dexlib2.iface.reference.StringReference;
37 import org.jf.dexlib2.iface.reference.TypeReference;
38 
39 import javax.annotation.Nonnull;
40 import javax.annotation.Nullable;
41 import java.util.*;
42 
43 public class MethodLocation {
44     @Nullable BuilderInstruction instruction;
45     int codeAddress;
46     int index;
47 
48     private final LocatedItems<Label> labels;
49     private final LocatedItems<BuilderDebugItem> debugItems;
50 
MethodLocation(@ullable BuilderInstruction instruction, int codeAddress, int index)51     MethodLocation(@Nullable BuilderInstruction instruction, int codeAddress, int index) {
52         this.debugItems = new LocatedDebugItems();
53         this.labels = new LocatedLabels();
54         this.instruction = instruction;
55         this.codeAddress = codeAddress;
56         this.index = index;
57     }
58 
59     @Nullable
getInstruction()60     public Instruction getInstruction() {
61         return instruction;
62     }
63 
getCodeAddress()64     public int getCodeAddress() {
65         return codeAddress;
66     }
67 
getIndex()68     public int getIndex() {
69         return index;
70     }
71 
mergeInto(@onnull MethodLocation nextLocation)72     void mergeInto(@Nonnull MethodLocation nextLocation) {
73         labels.mergeItemsIntoNext(nextLocation, nextLocation.labels);
74         debugItems.mergeItemsIntoNext(nextLocation, nextLocation.debugItems);
75     }
76 
77     @Nonnull
getLabels()78     public Set<Label> getLabels() {
79         return labels.getModifiableItems(MethodLocation.this);
80     }
81 
82     @Nonnull
addNewLabel()83     public Label addNewLabel() {
84         Label newLabel = new Label();
85         getLabels().add(newLabel);
86         return newLabel;
87     }
88 
89     @Nonnull
getDebugItems()90     public Set<BuilderDebugItem> getDebugItems() {
91         return debugItems.getModifiableItems(MethodLocation.this);
92     }
93 
addLineNumber(int lineNumber)94     public void addLineNumber(int lineNumber) {
95         getDebugItems().add(new BuilderLineNumber(lineNumber));
96     }
97 
addStartLocal(int registerNumber, @Nullable StringReference name, @Nullable TypeReference type, @Nullable StringReference signature)98     public void addStartLocal(int registerNumber, @Nullable StringReference name, @Nullable TypeReference type,
99                               @Nullable StringReference signature) {
100         getDebugItems().add(new BuilderStartLocal(registerNumber, name, type, signature));
101     }
102 
addEndLocal(int registerNumber)103     public void addEndLocal(int registerNumber) {
104         getDebugItems().add(new BuilderEndLocal(registerNumber));
105     }
106 
addRestartLocal(int registerNumber)107     public void addRestartLocal(int registerNumber) {
108         getDebugItems().add(new BuilderRestartLocal(registerNumber));
109     }
110 
addPrologue()111     public void addPrologue() {
112         getDebugItems().add(new BuilderPrologueEnd());
113     }
114 
addEpilogue()115     public void addEpilogue() {
116         getDebugItems().add(new BuilderEpilogueBegin());
117     }
118 
addSetSourceFile(@ullable StringReference sourceFile)119     public void addSetSourceFile(@Nullable StringReference sourceFile) {
120         getDebugItems().add(new BuilderSetSourceFile(sourceFile));
121     }
122 }
123