當前位置: 首頁>>代碼示例>>Java>>正文


Java JClassType.isParameterized方法代碼示例

本文整理匯總了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;
}
 
開發者ID:google,項目名稱:easy-gwt-mock,代碼行數:66,代碼來源:MocksGenerator.java


注:本文中的com.google.gwt.core.ext.typeinfo.JClassType.isParameterized方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。