本文整理匯總了Java中com.google.gwt.core.ext.typeinfo.JClassType.isAnnotationPresent方法的典型用法代碼示例。如果您正苦於以下問題:Java JClassType.isAnnotationPresent方法的具體用法?Java JClassType.isAnnotationPresent怎麽用?Java JClassType.isAnnotationPresent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.gwt.core.ext.typeinfo.JClassType
的用法示例。
在下文中一共展示了JClassType.isAnnotationPresent方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generate
import com.google.gwt.core.ext.typeinfo.JClassType; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
throws UnableToCompleteException {
TypeOracle typeOracle = context.getTypeOracle();
JClassType extensionManager = typeOracle.findType(typeName);
if (extensionManager == null) {
logger.log(TreeLogger.ERROR, "Can't find interface type '" + typeName + "'", null);
throw new UnableToCompleteException();
}
if (extensionManager.isInterface() == null) {
logger.log(
TreeLogger.ERROR,
extensionManager.getQualifiedSourceName() + " is not an interface",
null);
throw new UnableToCompleteException();
}
List<JClassType> extensions = new ArrayList<>();
for (JClassType type : typeOracle.getTypes()) {
if (type.isAnnotationPresent(Extension.class)) {
extensions.add(type);
}
}
String packageName = extensionManager.getPackage().getName();
String className = extensionManager.getSimpleSourceName() + "Impl";
generateClass(logger, context, packageName, className, extensions);
return packageName + "." + className;
}
示例2: generateDependenciesForExtension
import com.google.gwt.core.ext.typeinfo.JClassType; //導入方法依賴的package包/類
/**
* Writes dependency gathering code, like:
*
* <p>Array<DependencyDescription> deps = Collections.<DependencyDescription> createArray();
* deps.add(new DependencyDescription("ide.api.ui.menu", "")); deps.add(new
* DependencyDescription("extension.demo", "1.0.0-alpha"));
*
* @param sw
* @param extension
* @throws UnableToCompleteException
*/
private void generateDependenciesForExtension(SourceWriter sw, JClassType extension)
throws UnableToCompleteException {
// expected code
/*
Array<DependencyDescription> deps = Collections.<DependencyDescription> createArray();
deps.add(new DependencyDescription("ide.api.ui.menu", ""));
*/
if (extension.getConstructors().length == 0) {
throw new UnableToCompleteException();
}
sw.println("List<DependencyDescription> deps = new ArrayList<>();");
JConstructor jConstructor = extension.getConstructors()[0];
JType[] parameterTypes = jConstructor.getParameterTypes();
for (JType jType : parameterTypes) {
JClassType argType = jType.isClassOrInterface();
if (argType != null
&& (argType.isAnnotationPresent(SDK.class)
|| argType.isAnnotationPresent(Extension.class))) {
String id = "";
String version = "";
if (argType.isAnnotationPresent(SDK.class)) {
id = argType.getAnnotation(SDK.class).title();
} else if (argType.isAnnotationPresent(Extension.class)) {
id = argType.getQualifiedSourceName();
version = argType.getAnnotation(Extension.class).version();
}
sw.println(
"deps.add(new DependencyDescription(\"%s\", \"%s\"));", escape(id), escape(version));
}
}
}
示例3: generate
import com.google.gwt.core.ext.typeinfo.JClassType; //導入方法依賴的package包/類
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
throws UnableToCompleteException {
TypeOracle typeOracle = context.getTypeOracle();
JClassType subsystemExtensionManager = typeOracle.findType(typeName);
if (subsystemExtensionManager == null) {
logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
throw new UnableToCompleteException();
}
if (subsystemExtensionManager.isInterface() == null) {
logger.log(TreeLogger.ERROR, subsystemExtensionManager.getQualifiedSourceName() + " is not an interface",
null);
throw new UnableToCompleteException();
}
List<SubsystemExtension> subsystemExtensions = new ArrayList<SubsystemExtension>();
for (JClassType type : typeOracle.getTypes()) {
if (type.isAnnotationPresent(SubsystemExtension.class)) {
subsystemExtensions.add(type.getAnnotation(SubsystemExtension.class));
}
}
String packageName = subsystemExtensionManager.getPackage().getName();
String className = subsystemExtensionManager.getSimpleSourceName() + "Impl";
generateClass(logger, context, packageName, className, subsystemExtensions);
return packageName + "." + className;
}
示例4: generate
import com.google.gwt.core.ext.typeinfo.JClassType; //導入方法依賴的package包/類
@Override
public String generate(TreeLogger logger, GeneratorContext context, String typeName)
throws UnableToCompleteException {
TypeOracle typeOracle = context.getTypeOracle();
JClassType componentExtensionManager = typeOracle.findType(typeName);
if (componentExtensionManager == null) {
logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + typeName + "'", null);
throw new UnableToCompleteException();
}
if (componentExtensionManager.isInterface() == null) {
logger.log(TreeLogger.ERROR, componentExtensionManager.getQualifiedSourceName() + " is not an interface",
null);
throw new UnableToCompleteException();
}
JClassType componentProvider = typeOracle.findType(ComponentProvider.class.getCanonicalName());
if (componentProvider == null) {
logger.log(TreeLogger.ERROR, "Unable to find metadata for type 'ComponentProvider'", null);
throw new UnableToCompleteException();
}
List<JClassType> componentExtensionClasses = new ArrayList<JClassType>();
for (JClassType type : typeOracle.getTypes()) {
if (type.isAnnotationPresent(ComponentExtension.class)) {
if (type.isClass() == null || type.isAbstract()) {
// type must be a class that can be instantiated
logger.log(TreeLogger.ERROR, "ComponentExtension type '" + type.getQualifiedSourceName()
+ "' cannot be instantiated.", null);
throw new UnableToCompleteException();
} else if (!type.isDefaultInstantiable()) {
// type must have default constructor
logger.log(TreeLogger.ERROR, "ComponentExtension type '" + type.getQualifiedSourceName()
+ "' does not provide a default constructor.", null);
throw new UnableToCompleteException();
} else if (!type.isAssignableTo(componentProvider)) {
// type must implement ComponentProvider
logger.log(TreeLogger.ERROR, "ComponentExtension type '" + type.getQualifiedSourceName()
+ "' does not implement ComponentProvider.", null);
throw new UnableToCompleteException();
}
componentExtensionClasses.add(type);
}
}
String packageName = componentExtensionManager.getPackage().getName();
String className = componentExtensionManager.getSimpleSourceName() + "Impl";
generateClass(logger, context, packageName, className, componentExtensionClasses);
return packageName + "." + className;
}