comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java @ 18780:f4d78e4a878d

Truffle-DSL: fixed create method should have the same visibility as its originating constructor. (GRAAL-365 #resolve)
author Christian Humer <christian.humer@gmail.com>
date Mon, 05 Jan 2015 20:23:22 +0100
parents 76cbf5f33f82
children 93016f2f3f16
comparison
equal deleted inserted replaced
18779:7ea9a39bd7cc 18780:f4d78e4a878d
149 method.createBuilder().startReturn().string("this.").string(field.getName()).end(); 149 method.createBuilder().startReturn().string("this.").string(field.getName()).end();
150 clazz.add(method); 150 clazz.add(method);
151 } 151 }
152 } 152 }
153 153
154 List<? extends ExecutableElement> superConstructors = ElementFilter.constructorsIn(node.getTemplateType().getEnclosedElements()); 154 for (ExecutableElement superConstructor : NodeBaseFactory.findUserConstructors(node.getTemplateType().asType())) {
155 for (ExecutableElement superConstructor : superConstructors) {
156 if (getVisibility(superConstructor.getModifiers()) == PRIVATE) {
157 continue;
158 }
159 if (superConstructors.size() > 1 && superConstructor.getParameters().size() > 0 &&
160 ElementUtils.typeEquals(superConstructor.getEnclosingElement().asType(), superConstructor.getParameters().get(0).asType())) {
161 // constructor is copy constructor
162 continue;
163 }
164 clazz.add(createNodeConstructor(clazz, superConstructor)); 155 clazz.add(createNodeConstructor(clazz, superConstructor));
165 } 156 }
166 157
167 for (NodeExecutionData execution : node.getChildExecutions()) { 158 for (NodeExecutionData execution : node.getChildExecutions()) {
168 clazz.add(createNodeField(PRIVATE, execution.getNodeType(), nodeFieldName(execution), Child.class)); 159 clazz.add(createNodeField(PRIVATE, execution.getNodeType(), nodeFieldName(execution), Child.class));
205 196
206 return clazz; 197 return clazz;
207 } 198 }
208 199
209 private CodeExecutableElement createNodeConstructor(CodeTypeElement clazz, ExecutableElement superConstructor) { 200 private CodeExecutableElement createNodeConstructor(CodeTypeElement clazz, ExecutableElement superConstructor) {
210 CodeExecutableElement constructor = GeneratorUtils.createConstructorUsingFields(modifiers(PUBLIC), clazz, superConstructor); 201 CodeExecutableElement constructor = GeneratorUtils.createConstructorUsingFields(modifiers(), clazz, superConstructor);
202 ElementUtils.setVisibility(constructor.getModifiers(), ElementUtils.getVisibility(superConstructor.getModifiers()));
211 203
212 List<CodeVariableElement> childParameters = new ArrayList<>(); 204 List<CodeVariableElement> childParameters = new ArrayList<>();
213 for (NodeChildData child : node.getChildren()) { 205 for (NodeChildData child : node.getChildren()) {
214 childParameters.add(new CodeVariableElement(child.getOriginalType(), child.getName())); 206 childParameters.add(new CodeVariableElement(child.getOriginalType(), child.getName()));
215 } 207 }