use of com.google.gwt.core.ext.UnableToCompleteException in project ovirt-engine by oVirt.
the class ElementIdTypeParserTest method setUp.
@Before
public void setUp() throws UnableToCompleteException {
when(logger.branch(any(), any(), any(), any())).thenReturn(logger);
tested = new ElementIdTypeParser(logger, interfaceType) {
@Override
JClassType resolveOwnerType(JClassType interfaceToImplement) throws UnableToCompleteException {
return ownerType;
}
};
// $NON-NLS-1$
stubPassingField(field, mock(JClassType.class), "field");
JClassType ownerTypeParent = mock(JClassType.class);
Set<? extends JClassType> ownerTypeFlattenedSupertypeHierarchy = new HashSet<>(Arrays.asList(ownerType, ownerTypeParent));
doReturn(ownerTypeFlattenedSupertypeHierarchy).when(ownerType).getFlattenedSupertypeHierarchy();
when(ownerType.getFields()).thenReturn(new JField[] { ownerTypeField1, ownerTypeField2 });
when(ownerTypeParent.getFields()).thenReturn(new JField[] { ownerTypeParentField });
// $NON-NLS-1$
when(ownerType.getName()).thenReturn("OwnerTypeName");
// $NON-NLS-1$
JClassType ownerTypeParentFieldType = mock(JClassType.class, "ownerTypeParentFieldType");
// $NON-NLS-1$
stubPassingField(ownerTypeField1, mock(JClassType.class), "ownerTypeField1");
// $NON-NLS-1$
stubPassingField(ownerTypeField2, mock(JClassType.class), "ownerTypeField2");
// $NON-NLS-1$
stubPassingField(ownerTypeParentField, ownerTypeParentFieldType, "ownerTypeParentField");
Set<? extends JClassType> ownerTypeParentFieldTypeFlattenedSupertypeHierarchy = Collections.singleton(ownerTypeParentFieldType);
doReturn(ownerTypeParentFieldTypeFlattenedSupertypeHierarchy).when(ownerTypeParentFieldType).getFlattenedSupertypeHierarchy();
when(ownerTypeParentFieldType.getFields()).thenReturn(new JField[] { ownerTypeParentFieldTypeSubField1, ownerTypeParentFieldTypeSubField2 });
stubPassingField(ownerTypeParentFieldTypeSubField1, ownerTypeParentFieldTypeSubField1Type, // $NON-NLS-1$
"ownerTypeParentFieldTypeSubField1");
stubPassingField(ownerTypeParentFieldTypeSubField2, mock(JClassType.class), // $NON-NLS-1$
"ownerTypeParentFieldTypeSubField2");
}
use of com.google.gwt.core.ext.UnableToCompleteException in project gwtphonegap by dankurka.
the class PhoneGapLogValueGenerator method generate.
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
PropertyOracle propertyOracle = context.getPropertyOracle();
ConfigurationProperty property = null;
int value = 100;
try {
property = propertyOracle.getConfigurationProperty("phonegap.logging.maxentries");
List<String> values = property.getValues();
if (values.size() < 1) {
logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100");
} else {
String stringValue = values.get(0);
try {
value = Integer.parseInt(stringValue);
} catch (Exception e) {
logger.log(TreeLogger.WARN, "can not prase phonegap.logging.maxentries variable - value: '" + stringValue + "' - defaulting to 100");
}
}
} catch (BadPropertyValueException e) {
logger.log(TreeLogger.WARN, "can not resolve phonegap.logging.maxentries variable - defaulting to 100", e);
}
JClassType classType = null;
try {
classType = context.getTypeOracle().getType(typeName);
} catch (NotFoundException e) {
logger.log(TreeLogger.ERROR, "can not find type: '" + typeName + "'", e);
throw new UnableToCompleteException();
}
String packageName = classType.getPackage().getName();
String simpleName = classType.getSimpleSourceName() + "_" + value;
String fullName = packageName + "." + simpleName;
ClassSourceFileComposerFactory composer = new ClassSourceFileComposerFactory(packageName, simpleName);
composer.addImplementedInterface(typeName);
composer.addImport(typeName);
PrintWriter printWriter = context.tryCreate(logger, packageName, simpleName);
if (printWriter == null) {
return fullName;
}
SourceWriter writer = composer.createSourceWriter(context, printWriter);
writer.println("public int getMaxEntries() {");
writer.println("return " + value + ";");
writer.println("}");
writer.commit(logger);
return fullName;
}
use of com.google.gwt.core.ext.UnableToCompleteException in project pentaho-platform by pentaho.
the class EventBusUtilGenerator method generate.
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
this.logger = logger;
typeOracle = context.getTypeOracle();
try {
// get classType and save instance variables
JClassType classType = typeOracle.getType(typeName);
packageName = classType.getPackage().getName();
className = classType.getSimpleSourceName() + "Impl";
// Generate class source code
generateClass(logger, context);
} catch (Exception e) {
// record to logger that Map generation threw an exception
logger.log(TreeLogger.ERROR, "PropertyMap ERROR!!!", e);
}
// return the fully qualified name of the class generated
return packageName + "." + className;
}
use of com.google.gwt.core.ext.UnableToCompleteException in project pentaho-platform by pentaho.
the class CommandExecGenerator method generate.
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
this.logger = logger;
typeOracle = context.getTypeOracle();
try {
// get classType and save instance variables
JClassType classType = typeOracle.getType(typeName);
packageName = classType.getPackage().getName();
className = classType.getSimpleSourceName() + "Impl";
// Generate class source code
generateClass(logger, context);
} catch (Exception e) {
// record to logger that Map generation threw an exception
logger.log(TreeLogger.ERROR, "PropertyMap ERROR!!!", e);
}
// return the fully qualified name of the class generated
return packageName + "." + className;
}
Aggregations