]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/deriving/DerivingUtils.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / deriving / DerivingUtils.java
1 package org.simantics.scl.compiler.internal.deriving;
2
3 import org.simantics.scl.compiler.internal.parsing.types.TApplyAst;
4 import org.simantics.scl.compiler.internal.parsing.types.TTupleAst;
5 import org.simantics.scl.compiler.internal.parsing.types.TVarAst;
6 import org.simantics.scl.compiler.internal.parsing.types.TypeAst;
7
8 class DerivingUtils {
9     
10     static TVarAst getHeadType(TypeAst typeAst) {
11         while(true) {
12             if(typeAst instanceof TApplyAst)
13                 typeAst = ((TApplyAst)typeAst).function;
14             else if(typeAst instanceof TVarAst)
15                 return (TVarAst)typeAst;
16             else if(typeAst instanceof TTupleAst) {
17                 TTupleAst tuple = (TTupleAst)typeAst;
18                 if(tuple.components.length == 1)
19                     typeAst = tuple.components[0];
20                 else
21                     return null;
22             }
23             else
24                 return null;
25         }
26     }
27     
28 }