author | joehw |
Sun, 13 Aug 2017 21:10:40 -0700 | |
changeset 46174 | 5611d2529b49 |
parent 44797 | 8b3b3b911b8a |
permissions | -rw-r--r-- |
6 | 1 |
/* |
46174 | 2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
6 | 3 |
*/ |
44797
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
4 |
/* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
5 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
6 |
* contributor license agreements. See the NOTICE file distributed with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
7 |
* this work for additional information regarding copyright ownership. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
8 |
* The ASF licenses this file to You under the Apache License, Version 2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
9 |
* (the "License"); you may not use this file except in compliance with |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
10 |
* the License. You may obtain a copy of the License at |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
11 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
13 |
* |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
14 |
* Unless required by applicable law or agreed to in writing, software |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
17 |
* See the License for the specific language governing permissions and |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
18 |
* limitations under the License. |
8b3b3b911b8a
8162572: Update License Header for all JAXP sources
joehw
parents:
25868
diff
changeset
|
19 |
*/ |
6 | 20 |
package com.sun.org.apache.bcel.internal.generic; |
21 |
||
46174 | 22 |
import java.util.ArrayList; |
23 |
import java.util.List; |
|
6 | 24 |
|
46174 | 25 |
import com.sun.org.apache.bcel.internal.Const; |
26 |
import com.sun.org.apache.bcel.internal.classfile.AccessFlags; |
|
27 |
import com.sun.org.apache.bcel.internal.classfile.Attribute; |
|
6 | 28 |
|
29 |
/** |
|
46174 | 30 |
* Super class for FieldGen and MethodGen objects, since they have some methods |
31 |
* in common! |
|
6 | 32 |
* |
46174 | 33 |
* @version $Id: FieldGenOrMethodGen.java 1749603 2016-06-21 20:50:19Z ggregory |
34 |
* $ |
|
6 | 35 |
*/ |
46174 | 36 |
public abstract class FieldGenOrMethodGen extends AccessFlags implements NamedAndTyped, Cloneable { |
37 |
||
38 |
private String name; |
|
39 |
private Type type; |
|
40 |
private ConstantPoolGen cp; |
|
41 |
||
42 |
private final List<Attribute> attribute_vec = new ArrayList<>(); |
|
6 | 43 |
|
46174 | 44 |
// @since 6.0 |
45 |
private final List<AnnotationEntryGen> annotation_vec = new ArrayList<>(); |
|
46 |
||
47 |
protected FieldGenOrMethodGen() { |
|
48 |
} |
|
49 |
||
50 |
/** |
|
51 |
* @since 6.0 |
|
52 |
*/ |
|
53 |
protected FieldGenOrMethodGen(final int access_flags) { // TODO could this be package protected? |
|
54 |
super(access_flags); |
|
55 |
} |
|
6 | 56 |
|
46174 | 57 |
@Override |
58 |
public void setType(final Type type) { // TODO could be package-protected? |
|
59 |
if (type.getType() == Const.T_ADDRESS) { |
|
60 |
throw new IllegalArgumentException("Type can not be " + type); |
|
61 |
} |
|
62 |
this.type = type; |
|
63 |
} |
|
6 | 64 |
|
46174 | 65 |
@Override |
66 |
public Type getType() { |
|
67 |
return type; |
|
68 |
} |
|
6 | 69 |
|
46174 | 70 |
/** |
71 |
* @return name of method/field. |
|
72 |
*/ |
|
73 |
@Override |
|
74 |
public String getName() { |
|
75 |
return name; |
|
76 |
} |
|
6 | 77 |
|
46174 | 78 |
@Override |
79 |
public void setName(final String name) { // TODO could be package-protected? |
|
80 |
this.name = name; |
|
81 |
} |
|
82 |
||
83 |
public ConstantPoolGen getConstantPool() { |
|
84 |
return cp; |
|
85 |
} |
|
86 |
||
87 |
public void setConstantPool(final ConstantPoolGen cp) { // TODO could be package-protected? |
|
88 |
this.cp = cp; |
|
89 |
} |
|
6 | 90 |
|
46174 | 91 |
/** |
92 |
* Add an attribute to this method. Currently, the JVM knows about the |
|
93 |
* `Code', `ConstantValue', `Synthetic' and `Exceptions' attributes. Other |
|
94 |
* attributes will be ignored by the JVM but do no harm. |
|
95 |
* |
|
96 |
* @param a attribute to be added |
|
97 |
*/ |
|
98 |
public void addAttribute(final Attribute a) { |
|
99 |
attribute_vec.add(a); |
|
100 |
} |
|
6 | 101 |
|
46174 | 102 |
/** |
103 |
* @since 6.0 |
|
104 |
*/ |
|
105 |
protected void addAnnotationEntry(final AnnotationEntryGen ag) // TODO could this be package protected? |
|
106 |
{ |
|
107 |
annotation_vec.add(ag); |
|
108 |
} |
|
6 | 109 |
|
46174 | 110 |
/** |
111 |
* Remove an attribute. |
|
112 |
*/ |
|
113 |
public void removeAttribute(final Attribute a) { |
|
114 |
attribute_vec.remove(a); |
|
115 |
} |
|
116 |
||
117 |
/** |
|
118 |
* @since 6.0 |
|
119 |
*/ |
|
120 |
protected void removeAnnotationEntry(final AnnotationEntryGen ag) // TODO could this be package protected? |
|
121 |
{ |
|
122 |
annotation_vec.remove(ag); |
|
123 |
} |
|
6 | 124 |
|
46174 | 125 |
/** |
126 |
* Remove all attributes. |
|
127 |
*/ |
|
128 |
public void removeAttributes() { |
|
129 |
attribute_vec.clear(); |
|
130 |
} |
|
131 |
||
132 |
/** |
|
133 |
* @since 6.0 |
|
134 |
*/ |
|
135 |
protected void removeAnnotationEntries() // TODO could this be package protected? |
|
136 |
{ |
|
137 |
annotation_vec.clear(); |
|
138 |
} |
|
6 | 139 |
|
46174 | 140 |
/** |
141 |
* @return all attributes of this method. |
|
142 |
*/ |
|
143 |
public Attribute[] getAttributes() { |
|
144 |
final Attribute[] attributes = new Attribute[attribute_vec.size()]; |
|
145 |
attribute_vec.toArray(attributes); |
|
146 |
return attributes; |
|
147 |
} |
|
148 |
||
149 |
public AnnotationEntryGen[] getAnnotationEntries() { |
|
150 |
final AnnotationEntryGen[] annotations = new AnnotationEntryGen[annotation_vec.size()]; |
|
151 |
annotation_vec.toArray(annotations); |
|
152 |
return annotations; |
|
153 |
} |
|
6 | 154 |
|
46174 | 155 |
/** |
156 |
* @return signature of method/field. |
|
157 |
*/ |
|
158 |
public abstract String getSignature(); |
|
159 |
||
160 |
@Override |
|
161 |
public Object clone() { |
|
162 |
try { |
|
163 |
return super.clone(); |
|
164 |
} catch (final CloneNotSupportedException e) { |
|
165 |
throw new Error("Clone Not Supported"); // never happens |
|
166 |
} |
|
6 | 167 |
} |
168 |
} |