Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/model/CodeVariableElement.java @ 16759:23415229349b
Truffle-DSL: new package structure.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 11 Aug 2014 15:57:14 +0200 |
parents | graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/ast/CodeVariableElement.java@0cd0bdedd4ad |
children | 62cfffca9be2 |
comparison
equal
deleted
inserted
replaced
16758:c5f8eeb3cbc8 | 16759:23415229349b |
---|---|
1 /* | |
2 * Copyright (c) 2012, 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.dsl.processor.java.model; | |
24 | |
25 import java.util.*; | |
26 | |
27 import javax.lang.model.element.*; | |
28 import javax.lang.model.type.*; | |
29 | |
30 import com.oracle.truffle.dsl.processor.java.*; | |
31 | |
32 public final class CodeVariableElement extends CodeElement<Element> implements VariableElement { | |
33 | |
34 private Name name; | |
35 private TypeMirror type; | |
36 private Object constantValue; | |
37 | |
38 private CodeTree init; | |
39 | |
40 public CodeVariableElement(TypeMirror type, String name) { | |
41 super(ElementUtils.modifiers()); | |
42 this.type = type; | |
43 this.name = CodeNames.of(name); | |
44 } | |
45 | |
46 public CodeVariableElement(Set<Modifier> modifiers, TypeMirror type, String name) { | |
47 super(modifiers); | |
48 this.type = type; | |
49 this.name = CodeNames.of(name); | |
50 } | |
51 | |
52 public CodeVariableElement(Set<Modifier> modifiers, TypeMirror type, String name, String init) { | |
53 this(modifiers, type, name); | |
54 if (init != null) { | |
55 this.init = new CodeTree(CodeTreeKind.STRING, null, init); | |
56 } | |
57 } | |
58 | |
59 public CodeTreeBuilder createInitBuilder() { | |
60 CodeTreeBuilder builder = new CodeTreeBuilder(null); | |
61 init = builder.getTree(); | |
62 init.setEnclosingElement(this); | |
63 return builder; | |
64 } | |
65 | |
66 public void setInit(CodeTree init) { | |
67 this.init = init; | |
68 } | |
69 | |
70 public CodeTree getInit() { | |
71 return init; | |
72 } | |
73 | |
74 public Name getSimpleName() { | |
75 return name; | |
76 } | |
77 | |
78 public TypeMirror getType() { | |
79 return type; | |
80 } | |
81 | |
82 @Override | |
83 public TypeMirror asType() { | |
84 return type; | |
85 } | |
86 | |
87 @Override | |
88 public ElementKind getKind() { | |
89 if (getEnclosingElement() instanceof ExecutableElement) { | |
90 return ElementKind.PARAMETER; | |
91 } else if (getEnclosingElement() instanceof TypeElement) { | |
92 return ElementKind.FIELD; | |
93 } else { | |
94 return ElementKind.PARAMETER; | |
95 } | |
96 } | |
97 | |
98 public void setConstantValue(Object constantValue) { | |
99 this.constantValue = constantValue; | |
100 } | |
101 | |
102 @Override | |
103 public Object getConstantValue() { | |
104 return constantValue; | |
105 } | |
106 | |
107 public String getName() { | |
108 return getSimpleName().toString(); | |
109 } | |
110 | |
111 public void setSimpleName(Name name) { | |
112 this.name = name; | |
113 } | |
114 | |
115 public void setName(String name) { | |
116 this.name = CodeNames.of(name); | |
117 } | |
118 | |
119 public void setType(TypeMirror type) { | |
120 this.type = type; | |
121 } | |
122 | |
123 @Override | |
124 public <R, P> R accept(ElementVisitor<R, P> v, P p) { | |
125 return v.visitVariable(this, p); | |
126 } | |
127 | |
128 public static CodeVariableElement clone(VariableElement var) { | |
129 CodeVariableElement copy = new CodeVariableElement(var.getModifiers(), var.asType(), var.getSimpleName().toString()); | |
130 copy.setConstantValue(var.getConstantValue()); | |
131 for (AnnotationMirror mirror : var.getAnnotationMirrors()) { | |
132 copy.addAnnotationMirror(mirror); | |
133 } | |
134 for (Element element : var.getEnclosedElements()) { | |
135 copy.add(element); | |
136 } | |
137 return copy; | |
138 } | |
139 | |
140 } |