comparison graal/com.oracle.truffle.object/src/com/oracle/truffle/object/Transition.java @ 18408:2c3666f44855

Truffle: initial commit of object API implementation
author Andreas Woess <andreas.woess@jku.at>
date Tue, 18 Nov 2014 23:19:43 +0100
parents
children b3b241bbbbdb
comparison
equal deleted inserted replaced
18407:f439fdb137a3 18408:2c3666f44855
1 /*
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.object;
24
25 import java.util.*;
26
27 import com.oracle.truffle.api.object.*;
28
29 public abstract class Transition {
30 @Override
31 public int hashCode() {
32 int result = 1;
33 return result;
34 }
35
36 @Override
37 public boolean equals(Object obj) {
38 if (this == obj) {
39 return true;
40 }
41 if (obj == null) {
42 return false;
43 }
44 if (getClass() != obj.getClass()) {
45 return false;
46 }
47 return true;
48 }
49
50 public abstract static class PropertyTransition extends Transition {
51 private final Property property;
52
53 public PropertyTransition(Property property) {
54 this.property = property;
55 }
56
57 @Override
58 public int hashCode() {
59 final int prime = 31;
60 int result = super.hashCode();
61 result = prime * result + ((property == null) ? 0 : property.hashCode());
62 return result;
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (!super.equals(obj)) {
68 return false;
69 }
70 PropertyTransition other = (PropertyTransition) obj;
71 if (!Objects.equals(property, other.property)) {
72 return false;
73 }
74 return true;
75 }
76
77 public Property getProperty() {
78 return property;
79 }
80 }
81
82 public static final class AddTransition extends PropertyTransition {
83 public AddTransition(Property property) {
84 super(property);
85 }
86 }
87
88 public static final class RemoveTransition extends PropertyTransition {
89 public RemoveTransition(Property property) {
90 super(property);
91 }
92 }
93
94 public static final class OperationsTransition extends Transition {
95 private final ObjectType operations;
96
97 public OperationsTransition(ObjectType operations) {
98 this.operations = operations;
99 }
100
101 public ObjectType getOperations() {
102 return operations;
103 }
104
105 @Override
106 public boolean equals(Object other) {
107 return super.equals(other) && Objects.equals(operations, ((OperationsTransition) other).operations);
108 }
109
110 @Override
111 public int hashCode() {
112 final int prime = 31;
113 int result = super.hashCode();
114 result = prime * result + ((operations == null) ? 0 : operations.hashCode());
115 return result;
116 }
117 }
118
119 public static final class TypeTransition extends PropertyTransition {
120 private final Property after;
121
122 public TypeTransition(Property before, Property after) {
123 super(before);
124 this.after = after;
125 }
126
127 public Property getPropertyBefore() {
128 return this.getProperty();
129 }
130
131 public Property getPropertyAfter() {
132 return after;
133 }
134 }
135
136 public static final class ReservePrimitiveArrayTransition extends Transition {
137 public ReservePrimitiveArrayTransition() {
138 }
139 }
140
141 public String getShortName() {
142 return this.getClass().getSimpleName().replaceFirst("Transition$", "").toLowerCase();
143 }
144 }