31
31
import com .gwtplatform .mvp .client .Bootstrapper ;
32
32
import com .gwtplatform .mvp .client .DelayedBindRegistry ;
33
33
import com .gwtplatform .mvp .client .PreBootstrapper ;
34
+ import com .gwtplatform .mvp .client .fallback .ApplicationControllerFallback ;
35
+ import com .gwtplatform .mvp .client .fallback .BootstrapperFallback ;
36
+ import com .gwtplatform .mvp .client .fallback .PreBootstrapperFallback ;
34
37
35
38
/**
36
39
* Will generate a {@link com.gwtplatform.mvp.client.ApplicationController}. If the user wants his Generator to be
37
40
* generated by GWTP, this Application controller will make sure that the Ginjector is used to trigger the initial
38
41
* revealCurrentPlace() from the place manager.
39
42
*/
40
43
public class ApplicationControllerGenerator extends AbstractGenerator {
44
+ private static final String PROBLEM_GENERATING = "There was a problem generating the ApplicationController," +
45
+ " this can be caused by bad GWT module configuration or compile errors in your source code." ;
41
46
private static final String PROPERTY_BOOTSTRAPPER_EMPTY =
42
47
"Required configuration property 'gwtp.bootstrapper' can not be empty!." ;
43
48
private static final String PROPERTY_NOT_FOUND = "Undefined configuration property '%s'." ;
44
- private static final String TYPE_NOT_FOUND = "The type '%s' was not found." ;
49
+ private static final String TYPE_NOT_FOUND = "The type '%s' was not found, either the class name is " +
50
+ "wrong or there are compile errors in your code." ;
45
51
private static final String HINT_URL = "https://github.com/ArcBees/GWTP/wiki/Bootstrapping" ;
46
52
private static final String DOES_NOT_EXTEND_INTERFACE = "'%s' doesn't implement the '%s' interface. See "
47
53
+ HINT_URL ;
@@ -73,7 +79,6 @@ public String generate(TreeLogger treeLogger, GeneratorContext generatorContext,
73
79
return typeName + SUFFIX ;
74
80
}
75
81
try {
76
-
77
82
JClassType preBootstrapper = getPreBootstrapper ();
78
83
79
84
ClassSourceFileComposerFactory composer = initComposer (preBootstrapper );
@@ -89,6 +94,15 @@ public String generate(TreeLogger treeLogger, GeneratorContext generatorContext,
89
94
closeDefinition (sw );
90
95
91
96
return getPackageName () + "." + getClassName ();
97
+ } catch (UnableToCompleteException e ) {
98
+ // Java compile errors can cause problems during compilation
99
+ // for tasks like TypeOracle#findType will return null if there
100
+ // are compile errors, we should at least hint this possibility.
101
+ getTreeLogger ().log (TreeLogger .ERROR , PROBLEM_GENERATING );
102
+
103
+ // Return ApplicationControllerFallback class to avoid
104
+ // swallowing the actual compiler issues if there are any.
105
+ return ApplicationControllerFallback .class .getName ();
92
106
} finally {
93
107
printWriter .close ();
94
108
}
@@ -117,12 +131,17 @@ private ClassSourceFileComposerFactory initComposer(JClassType preBootstrapper)
117
131
private JClassType getBootstrapper () throws UnableToCompleteException {
118
132
String typeName = lookupTypeNameByProperty (PROPERTY_NAME_BOOTSTRAPPER );
119
133
if (typeName == null ) {
120
- getTreeLogger ()
121
- .log (TreeLogger .ERROR , PROPERTY_BOOTSTRAPPER_EMPTY );
122
- throw new UnableToCompleteException ();
134
+
135
+ getTreeLogger ().log (TreeLogger .ERROR , PROPERTY_BOOTSTRAPPER_EMPTY );
123
136
}
124
137
125
- return findAndVerifyType (typeName , Bootstrapper .class );
138
+ JClassType type ;
139
+ try {
140
+ type = findAndVerifyType (typeName , Bootstrapper .class );
141
+ } catch (UnableToCompleteException ex ) {
142
+ type = findAndVerifyType (typeName , BootstrapperFallback .class );
143
+ }
144
+ return type ;
126
145
}
127
146
128
147
/**
@@ -134,7 +153,13 @@ private JClassType getPreBootstrapper() throws UnableToCompleteException {
134
153
return null ;
135
154
}
136
155
137
- return findAndVerifyType (typeName , PreBootstrapper .class );
156
+ JClassType type ;
157
+ try {
158
+ type = findAndVerifyType (typeName , PreBootstrapper .class );
159
+ } catch (UnableToCompleteException ex ) {
160
+ type = findAndVerifyType (typeName , PreBootstrapperFallback .class );
161
+ }
162
+ return type ;
138
163
}
139
164
140
165
/**
@@ -162,7 +187,8 @@ private String lookupTypeNameByProperty(String propertyName) throws UnableToComp
162
187
/**
163
188
* Find the Java type by the given class name and verify that it extends the given interface.
164
189
*/
165
- private JClassType findAndVerifyType (String typeName , Class <?> interfaceClass ) throws UnableToCompleteException {
190
+ private JClassType findAndVerifyType (String typeName , Class <?> interfaceClass )
191
+ throws UnableToCompleteException {
166
192
JClassType type = getTypeOracle ().findType (typeName );
167
193
if (type == null ) {
168
194
getTreeLogger ().log (TreeLogger .ERROR , String .format (TYPE_NOT_FOUND , typeName ));
0 commit comments