]> gerrit.simantics Code Review - simantics/platform.git/blob
fb7334cd2b2cf52cdbd1faf85dc266b762af9bc8
[simantics/platform.git] /
1 package org.simantics.scl.compiler.elaboration.expressions.annotations;
2
3 import org.simantics.scl.compiler.constants.StringConstant;
4 import org.simantics.scl.compiler.elaboration.expressions.ELiteral;
5 import org.simantics.scl.compiler.elaboration.expressions.EStringLiteral;
6 import org.simantics.scl.compiler.elaboration.expressions.EVar;
7 import org.simantics.scl.compiler.elaboration.expressions.Expression;
8
9 public class AnnotationUtils {
10     public static String extractString(Expression expression) {
11         if(expression instanceof EVar)
12             return ((EVar)expression).name;
13         else if(expression instanceof EStringLiteral) {
14             EStringLiteral literal = (EStringLiteral)expression;
15             if(literal.strings.length == 1)
16                 return literal.strings[0];
17         }
18         else if(expression instanceof ELiteral) {
19             ELiteral literal = (ELiteral)expression;
20             if(literal.getValue() instanceof StringConstant) {
21                 StringConstant constant = (StringConstant)literal.getValue();
22                 return constant.getValue();
23             }
24         }
25         return null;
26     }
27 }