本文整理匯總了Java中com.google.gwt.core.ext.typeinfo.JClassType.isParameterized方法的典型用法代碼示例。如果您正苦於以下問題:Java JClassType.isParameterized方法的具體用法?Java JClassType.isParameterized怎麽用?Java JClassType.isParameterized使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.gwt.core.ext.typeinfo.JClassType
的用法示例。
在下文中一共展示了JClassType.isParameterized方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateMock
import com.google.gwt.core.ext.typeinfo.JClassType; //導入方法依賴的package包/類
/**
* Generates a mock class for {@code interfaceToMock}.
*/
String generateMock(JClassType typeToMock) throws UnableToCompleteException {
JPackage interfacePackage = typeToMock.getPackage();
String packageName = interfacePackage == null ? "" : interfacePackage.getName();
String newClassName = typeToMock.getName().replace(".", "_") + "Mock";
// GenericType<Integer> has to generate a different mock implementation than
// GenericType<String>, that's what we check and do here
if (typeToMock.isParameterized() != null) {
StringBuilder typeList = new StringBuilder();
for (JClassType genericArg : typeToMock.isParameterized().getTypeArgs()) {
typeList.append(genericArg.getParameterizedQualifiedSourceName());
}
newClassName += Integer.toHexString(typeList.toString().hashCode());
}
String fullNewClassName = packageName + "." + newClassName;
PrintWriter printWriter = this.context.tryCreate(this.logger, packageName, newClassName);
if (printWriter == null) {
// We generated this before.
return fullNewClassName;
}
ClassSourceFileComposerFactory composer =
new ClassSourceFileComposerFactory(packageName, newClassName);
composer.addImport(MocksControlBase.class.getCanonicalName());
composer.addImport(Method.class.getCanonicalName());
composer.addImport(Call.class.getCanonicalName());
composer.addImport(UndeclaredThrowableException.class.getCanonicalName());
if (typeToMock.isInterface() != null) {
composer.addImplementedInterface(typeToMock.getParameterizedQualifiedSourceName());
} else {
composer.setSuperclass(typeToMock.getParameterizedQualifiedSourceName());
}
SourceWriter sourceWriter = composer.createSourceWriter(this.context, printWriter);
sourceWriter.println();
JMethod[] overridableMethods = typeToMock.getOverridableMethods();
List<JMethod> methodsToMock = new ArrayList<JMethod>();
Set<String> needsDefaultImplementation = new HashSet<String>();
for (JMethod method : overridableMethods) {
if (isSpecialMethodOfObject(method)) {
needsDefaultImplementation.add(method.getName());
} else if (method.getParameterTypes().length == 0 && method.getName().equals("getClass")) {
// ignore, Bug 5026788 in GWT
} else {
methodsToMock.add(method);
}
}
printFields(sourceWriter, methodsToMock);
printConstructors(sourceWriter, newClassName, typeToMock.getConstructors());
printMockMethods(sourceWriter, methodsToMock, newClassName);
printDefaultMethods(sourceWriter, typeToMock, needsDefaultImplementation);
sourceWriter.commit(this.logger);
return fullNewClassName;
}