1 16 package com.google.gwt.dev.cfg; 17 18 import com.google.gwt.core.ext.GeneratorContext; 19 import com.google.gwt.core.ext.TreeLogger; 20 import com.google.gwt.core.ext.UnableToCompleteException; 21 import com.google.gwt.core.ext.typeinfo.JClassType; 22 import com.google.gwt.core.ext.typeinfo.TypeOracle; 23 import com.google.gwt.dev.util.Util; 24 25 29 public class ConditionWhenTypeAssignableTo extends Condition { 30 31 private final String assignableToTypeName; 32 33 public ConditionWhenTypeAssignableTo(String assignableToTypeName) { 34 this.assignableToTypeName = assignableToTypeName; 35 } 36 37 public String getAssignableToTypeName() { 38 return assignableToTypeName; 39 } 40 41 public String toString() { 42 return "<when-assignable class='" + assignableToTypeName + "'/>"; 43 } 44 45 protected boolean doEval(TreeLogger logger, GeneratorContext context, 46 String testType) throws UnableToCompleteException { 47 TypeOracle typeOracle = context.getTypeOracle(); 48 49 JClassType fromType = typeOracle.findType(testType); 50 if (fromType == null) { 51 Util.logMissingTypeErrorWithHints(logger, testType); 52 throw new UnableToCompleteException(); 53 } 54 55 JClassType toType = typeOracle.findType(assignableToTypeName); 56 if (toType == null) { 57 logger.log(TreeLogger.WARN, "Unknown type '" + assignableToTypeName 62 + "' specified in deferred binding rule", null); 63 return false; 64 } 65 66 if (fromType.isAssignableTo(toType)) { 67 return true; 68 } else { 69 return false; 70 } 71 } 72 73 protected String getEvalAfterMessage(String testType, boolean result) { 74 if (result) { 75 return "Yes, the requested type was assignable"; 76 } else { 77 return "No, the requested type was not assignable"; 78 } 79 } 80 81 protected String getEvalBeforeMessage(String testType) { 82 return toString(); 83 } 84 85 } 86 | Popular Tags |