Mercurial > hg > truffle
comparison graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/parser/CreateCastParser.java @ 20938:18c0f02fa4d2
Truffle-DSL: make type systems optional.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Tue, 14 Apr 2015 15:12:48 +0200 |
parents | 62c43fcf5be2 |
children |
comparison
equal
deleted
inserted
replaced
20937:37ea76052733 | 20938:18c0f02fa4d2 |
---|---|
57 TypeMirror baseType = getContext().getTruffleTypes().getNode(); | 57 TypeMirror baseType = getContext().getTruffleTypes().getNode(); |
58 if (foundChild != null) { | 58 if (foundChild != null) { |
59 baseType = foundChild.getOriginalType(); | 59 baseType = foundChild.getOriginalType(); |
60 } | 60 } |
61 | 61 |
62 MethodSpec spec = new MethodSpec(new InheritsParameterSpec("child", baseType)); | 62 MethodSpec spec = new MethodSpec(new ParameterSpec("child", baseType)); |
63 addDefaultFieldMethodSpec(spec); | 63 addDefaultFieldMethodSpec(spec); |
64 ParameterSpec childSpec = new ParameterSpec("castedChild", baseType); | 64 ParameterSpec childSpec = new ParameterSpec("castedChild", baseType); |
65 childSpec.setSignature(true); | 65 childSpec.setSignature(true); |
66 spec.addRequired(childSpec); | 66 spec.addRequired(childSpec); |
67 return spec; | 67 return spec; |
94 } | 94 } |
95 } | 95 } |
96 return cast; | 96 return cast; |
97 } | 97 } |
98 | 98 |
99 private static class InheritsParameterSpec extends ParameterSpec { | |
100 | |
101 public InheritsParameterSpec(String name, TypeMirror... allowedTypes) { | |
102 super(name, Arrays.asList(allowedTypes), null); | |
103 } | |
104 | |
105 @Override | |
106 public boolean matches(VariableElement variable) { | |
107 boolean found = false; | |
108 for (TypeMirror specType : getAllowedTypes()) { | |
109 if (ElementUtils.isAssignable(variable.asType(), specType)) { | |
110 found = true; | |
111 break; | |
112 } | |
113 } | |
114 return found; | |
115 } | |
116 } | |
117 } | 99 } |