Mercurial > hg > truffle
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/GeneratorUtils.java @ 19282:ae81dd154fb6
Truffle-DSL: remove old DSL layout; Make new layout the default.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Thu, 22 Jan 2015 20:44:24 +0100 |
parents | a665483c3881 |
children | 18c0f02fa4d2 |
comparison
equal
deleted
inserted
replaced
19281:92880b0f7fed | 19282:ae81dd154fb6 |
---|---|
33 | 33 |
34 import com.oracle.truffle.api.*; | 34 import com.oracle.truffle.api.*; |
35 import com.oracle.truffle.api.dsl.*; | 35 import com.oracle.truffle.api.dsl.*; |
36 import com.oracle.truffle.api.dsl.internal.DSLOptions.*; | 36 import com.oracle.truffle.api.dsl.internal.DSLOptions.*; |
37 import com.oracle.truffle.dsl.processor.*; | 37 import com.oracle.truffle.dsl.processor.*; |
38 import com.oracle.truffle.dsl.processor.java.*; | |
38 import com.oracle.truffle.dsl.processor.java.model.*; | 39 import com.oracle.truffle.dsl.processor.java.model.*; |
39 import com.oracle.truffle.dsl.processor.model.*; | 40 import com.oracle.truffle.dsl.processor.model.*; |
40 | 41 |
41 public class GeneratorUtils { | 42 public class GeneratorUtils { |
42 | 43 |
146 | 147 |
147 clazz.addAnnotationMirror(generatedByAnnotation); | 148 clazz.addAnnotationMirror(generatedByAnnotation); |
148 return clazz; | 149 return clazz; |
149 } | 150 } |
150 | 151 |
152 public static List<ExecutableElement> findUserConstructors(TypeMirror nodeType) { | |
153 List<ExecutableElement> constructors = new ArrayList<>(); | |
154 for (ExecutableElement constructor : ElementFilter.constructorsIn(ElementUtils.fromTypeMirror(nodeType).getEnclosedElements())) { | |
155 if (constructor.getModifiers().contains(PRIVATE)) { | |
156 continue; | |
157 } | |
158 if (isCopyConstructor(constructor)) { | |
159 continue; | |
160 } | |
161 constructors.add(constructor); | |
162 } | |
163 | |
164 if (constructors.isEmpty()) { | |
165 constructors.add(new CodeExecutableElement(null, ElementUtils.getSimpleName(nodeType))); | |
166 } | |
167 | |
168 return constructors; | |
169 } | |
170 | |
171 public static boolean isCopyConstructor(ExecutableElement element) { | |
172 if (element.getParameters().size() != 1) { | |
173 return false; | |
174 } | |
175 VariableElement var = element.getParameters().get(0); | |
176 TypeElement enclosingType = ElementUtils.findNearestEnclosingType(var); | |
177 if (ElementUtils.typeEquals(var.asType(), enclosingType.asType())) { | |
178 return true; | |
179 } | |
180 List<TypeElement> types = ElementUtils.getDirectSuperTypes(enclosingType); | |
181 for (TypeElement type : types) { | |
182 if (!(type instanceof CodeTypeElement)) { | |
183 // no copy constructors which are not generated types | |
184 return false; | |
185 } | |
186 | |
187 if (ElementUtils.typeEquals(var.asType(), type.asType())) { | |
188 return true; | |
189 } | |
190 } | |
191 return false; | |
192 } | |
193 | |
151 } | 194 } |