ImmutableEndLocal.java revision 22c3185bb7c8618437eabe6c597549e0989ec4e6
1a88cfce91374498578c44013041416c0c5b09b1eKenny Root/*
2a88cfce91374498578c44013041416c0c5b09b1eKenny Root * Copyright 2012, Google Inc.
3a88cfce91374498578c44013041416c0c5b09b1eKenny Root * All rights reserved.
4a88cfce91374498578c44013041416c0c5b09b1eKenny Root *
5a88cfce91374498578c44013041416c0c5b09b1eKenny Root * Redistribution and use in source and binary forms, with or without
6a88cfce91374498578c44013041416c0c5b09b1eKenny Root * modification, are permitted provided that the following conditions are
7a88cfce91374498578c44013041416c0c5b09b1eKenny Root * met:
8a88cfce91374498578c44013041416c0c5b09b1eKenny Root *
9a88cfce91374498578c44013041416c0c5b09b1eKenny Root *     * Redistributions of source code must retain the above copyright
10a88cfce91374498578c44013041416c0c5b09b1eKenny Root * notice, this list of conditions and the following disclaimer.
11a88cfce91374498578c44013041416c0c5b09b1eKenny Root *     * Redistributions in binary form must reproduce the above
12a88cfce91374498578c44013041416c0c5b09b1eKenny Root * copyright notice, this list of conditions and the following disclaimer
13a88cfce91374498578c44013041416c0c5b09b1eKenny Root * in the documentation and/or other materials provided with the
14a88cfce91374498578c44013041416c0c5b09b1eKenny Root * distribution.
15a88cfce91374498578c44013041416c0c5b09b1eKenny Root *     * Neither the name of Google Inc. nor the names of its
16a88cfce91374498578c44013041416c0c5b09b1eKenny Root * contributors may be used to endorse or promote products derived from
17a88cfce91374498578c44013041416c0c5b09b1eKenny Root * this software without specific prior written permission.
18a88cfce91374498578c44013041416c0c5b09b1eKenny Root *
19a88cfce91374498578c44013041416c0c5b09b1eKenny Root * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20a88cfce91374498578c44013041416c0c5b09b1eKenny Root * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21a88cfce91374498578c44013041416c0c5b09b1eKenny Root * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22a88cfce91374498578c44013041416c0c5b09b1eKenny Root * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23a88cfce91374498578c44013041416c0c5b09b1eKenny Root * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24a88cfce91374498578c44013041416c0c5b09b1eKenny Root * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25a88cfce91374498578c44013041416c0c5b09b1eKenny Root * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26a88cfce91374498578c44013041416c0c5b09b1eKenny Root * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27a88cfce91374498578c44013041416c0c5b09b1eKenny Root * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28a88cfce91374498578c44013041416c0c5b09b1eKenny Root * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29a88cfce91374498578c44013041416c0c5b09b1eKenny Root * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30a88cfce91374498578c44013041416c0c5b09b1eKenny Root */
31a88cfce91374498578c44013041416c0c5b09b1eKenny Root
32a88cfce91374498578c44013041416c0c5b09b1eKenny Rootpackage org.jf.dexlib2.immutable.debug;
33a88cfce91374498578c44013041416c0c5b09b1eKenny Root
34a88cfce91374498578c44013041416c0c5b09b1eKenny Rootimport org.jf.dexlib2.DebugItemType;
35a88cfce91374498578c44013041416c0c5b09b1eKenny Rootimport org.jf.dexlib2.iface.debug.EndLocal;
36a88cfce91374498578c44013041416c0c5b09b1eKenny Root
37a88cfce91374498578c44013041416c0c5b09b1eKenny Rootimport javax.annotation.Nonnull;
38a88cfce91374498578c44013041416c0c5b09b1eKenny Rootimport javax.annotation.Nullable;
39a88cfce91374498578c44013041416c0c5b09b1eKenny Root
40a88cfce91374498578c44013041416c0c5b09b1eKenny Rootpublic class ImmutableEndLocal extends ImmutableDebugItem implements EndLocal {
41a88cfce91374498578c44013041416c0c5b09b1eKenny Root    protected final int register;
42a88cfce91374498578c44013041416c0c5b09b1eKenny Root    @Nullable protected final String name;
43a88cfce91374498578c44013041416c0c5b09b1eKenny Root    @Nullable protected final String type;
44a88cfce91374498578c44013041416c0c5b09b1eKenny Root    @Nullable protected final String signature;
45a88cfce91374498578c44013041416c0c5b09b1eKenny Root
46a88cfce91374498578c44013041416c0c5b09b1eKenny Root    public ImmutableEndLocal(int codeAddress,
47a88cfce91374498578c44013041416c0c5b09b1eKenny Root                             int register) {
48a88cfce91374498578c44013041416c0c5b09b1eKenny Root        super(codeAddress);
49a88cfce91374498578c44013041416c0c5b09b1eKenny Root        this.register = register;
50a88cfce91374498578c44013041416c0c5b09b1eKenny Root        this.name = null;
51a88cfce91374498578c44013041416c0c5b09b1eKenny Root        this.type = null;
52a88cfce91374498578c44013041416c0c5b09b1eKenny Root        this.signature = null;
53a88cfce91374498578c44013041416c0c5b09b1eKenny Root    }
54a88cfce91374498578c44013041416c0c5b09b1eKenny Root
55a88cfce91374498578c44013041416c0c5b09b1eKenny Root    public ImmutableEndLocal(int codeAddress,
56a88cfce91374498578c44013041416c0c5b09b1eKenny Root                             int register,
57a88cfce91374498578c44013041416c0c5b09b1eKenny Root                             @Nullable String name,
58a88cfce91374498578c44013041416c0c5b09b1eKenny Root                             @Nullable String type,
59a88cfce91374498578c44013041416c0c5b09b1eKenny Root                             @Nullable String signature) {
60a88cfce91374498578c44013041416c0c5b09b1eKenny Root        super(codeAddress);
61a88cfce91374498578c44013041416c0c5b09b1eKenny Root        this.register = register;
62a88cfce91374498578c44013041416c0c5b09b1eKenny Root        this.name = name;
63a88cfce91374498578c44013041416c0c5b09b1eKenny Root        this.type = type;
64a88cfce91374498578c44013041416c0c5b09b1eKenny Root        this.signature = signature;
65a88cfce91374498578c44013041416c0c5b09b1eKenny Root    }
66a88cfce91374498578c44013041416c0c5b09b1eKenny Root
67a88cfce91374498578c44013041416c0c5b09b1eKenny Root    @Nonnull
68a88cfce91374498578c44013041416c0c5b09b1eKenny Root    public static ImmutableEndLocal of(@Nonnull EndLocal endLocal) {
69a88cfce91374498578c44013041416c0c5b09b1eKenny Root        if (endLocal instanceof  ImmutableEndLocal) {
70a88cfce91374498578c44013041416c0c5b09b1eKenny Root            return (ImmutableEndLocal)endLocal;
71a88cfce91374498578c44013041416c0c5b09b1eKenny Root        }
72a88cfce91374498578c44013041416c0c5b09b1eKenny Root        return new ImmutableEndLocal(
73a88cfce91374498578c44013041416c0c5b09b1eKenny Root                endLocal.getCodeAddress(),
74a88cfce91374498578c44013041416c0c5b09b1eKenny Root                endLocal.getRegister(),
75a88cfce91374498578c44013041416c0c5b09b1eKenny Root                endLocal.getType(),
76a88cfce91374498578c44013041416c0c5b09b1eKenny Root                endLocal.getName(),
77a88cfce91374498578c44013041416c0c5b09b1eKenny Root                endLocal.getSignature());
78a88cfce91374498578c44013041416c0c5b09b1eKenny Root    }
79a88cfce91374498578c44013041416c0c5b09b1eKenny Root
80a88cfce91374498578c44013041416c0c5b09b1eKenny Root    @Override public int getRegister() { return register; }
81a88cfce91374498578c44013041416c0c5b09b1eKenny Root    @Nullable @Override public String getName() { return name; }
82a88cfce91374498578c44013041416c0c5b09b1eKenny Root    @Nullable @Override public String getType() { return type; }
83a88cfce91374498578c44013041416c0c5b09b1eKenny Root    @Nullable @Override public String getSignature() { return signature; }
84a88cfce91374498578c44013041416c0c5b09b1eKenny Root
85a88cfce91374498578c44013041416c0c5b09b1eKenny Root    @Override public int getDebugItemType() { return DebugItemType.END_LOCAL; }
86a88cfce91374498578c44013041416c0c5b09b1eKenny Root}
87a88cfce91374498578c44013041416c0c5b09b1eKenny Root