Search in sources :

Example 26 with UnableToCompleteException

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");
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 27 with UnableToCompleteException

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;
}
Also used : ConfigurationProperty(com.google.gwt.core.ext.ConfigurationProperty) ClassSourceFileComposerFactory(com.google.gwt.user.rebind.ClassSourceFileComposerFactory) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) SourceWriter(com.google.gwt.user.rebind.SourceWriter) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException) JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) BadPropertyValueException(com.google.gwt.core.ext.BadPropertyValueException) PropertyOracle(com.google.gwt.core.ext.PropertyOracle) PrintWriter(java.io.PrintWriter)

Example 28 with UnableToCompleteException

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;
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException) NotFoundException(com.google.gwt.core.ext.typeinfo.NotFoundException)

Example 29 with UnableToCompleteException

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;
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) UnableToCompleteException(com.google.gwt.core.ext.UnableToCompleteException)

Aggregations

UnableToCompleteException (com.google.gwt.core.ext.UnableToCompleteException)29 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)14 TypeOracle (com.google.gwt.core.ext.typeinfo.TypeOracle)8 SourceWriter (com.google.gwt.user.rebind.SourceWriter)6 ClassSourceFileComposerFactory (com.google.gwt.user.rebind.ClassSourceFileComposerFactory)4 IOException (java.io.IOException)4 PrintWriter (java.io.PrintWriter)4 NotFoundException (com.google.gwt.core.ext.typeinfo.NotFoundException)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 GWT (com.google.gwt.core.client.GWT)2 TreeLogger (com.google.gwt.core.ext.TreeLogger)2 JMethod (com.google.gwt.core.ext.typeinfo.JMethod)2 JType (com.google.gwt.core.ext.typeinfo.JType)2 Resource (com.google.gwt.dev.resource.Resource)2 GinModule (com.google.gwt.inject.client.GinModule)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2