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


Java Constructor.isAnnotationPresent方法代碼示例

本文整理匯總了Java中java.lang.reflect.Constructor.isAnnotationPresent方法的典型用法代碼示例。如果您正苦於以下問題:Java Constructor.isAnnotationPresent方法的具體用法?Java Constructor.isAnnotationPresent怎麽用?Java Constructor.isAnnotationPresent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.Constructor的用法示例。


在下文中一共展示了Constructor.isAnnotationPresent方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractFromConstructors

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
protected final void extractFromConstructors()
{
    if (builderType == null) {
        // struct class must have a valid constructor
        addConstructors(structType);
    }
    else {
        // builder class must have a valid constructor
        addConstructors(builderType);

        // builder class must have a build method annotated with @ThriftConstructor
        addBuilderMethods();

        // verify struct class does not have @ThriftConstructors
        for (Constructor<?> constructor : getStructClass().getConstructors()) {
            if (constructor.isAnnotationPresent(ThriftConstructor.class)) {
                metadataErrors.addWarning(
                        "Thrift class '%s' has a builder class, but constructor '%s' annotated with @ThriftConstructor",
                        getStructClass().getName(),
                        constructor);
            }
        }
    }
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:25,代碼來源:AbstractThriftMetadataBuilder.java

示例2: init

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
public static void init(Object object) throws IllegalAccessException, InvocationTargetException, InstantiationException {
    if (object instanceof User) {
        Class clz = object.getClass();
        Constructor [] constructors = clz.getConstructors();
        for (Constructor constructor : constructors) {
            if (constructor.isAnnotationPresent(AConstructor.class)) {
                AConstructor aConstructor = (AConstructor) constructor.getAnnotation(AConstructor.class);
                String name = aConstructor.initName();
                int age = aConstructor.initAge();
                ((User) object).name = name;
                ((User) object).age = age;
            }
        }
    }else{
        throw new RuntimeException("無法向下轉型到指定類");
    }

}
 
開發者ID:byhieg,項目名稱:JavaTutorial,代碼行數:19,代碼來源:AConstructorProcess.java

示例3: parseConstructAnnotation

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
/**
   * 簡單打印出UserAnnotation 類中所使用到的構造方法注解
   * 該方法隻打印了 構造方法 類型的注解
   * @throws ClassNotFoundException
   */
  @SuppressWarnings("rawtypes")
  public static void parseConstructAnnotation()  throws ClassNotFoundException{
Constructor[] constructors = UserAnnotation.class.getConstructors();
      for (Constructor constructor : constructors) {
          /* 
           * 判斷構造方法中是否有指定注解類型的注解 
           */  
          boolean hasAnnotation = constructor.isAnnotationPresent(TestA.class);
          if(hasAnnotation){
               /* 
               * 根據注解類型返回方法的指定類型注解 
               */
              @SuppressWarnings("unchecked")
		TestA annotation = (TestA) constructor.getAnnotation(TestA.class);
              System.out.println("constructor = " + constructor.getName()  
                      + "   |   id = " + annotation.id() + "  |  description = "  
                      + annotation.name() + "  |   gid= "+annotation.gid());
          }
      }
  }
 
開發者ID:MinsxCloud,項目名稱:minsx-java-example,代碼行數:26,代碼來源:ParseAnnotation.java

示例4: updateFactoryData

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
private void updateFactoryData(Class<? extends T> clazz, DeveloperData data){
	this.data=data;
	variableSetters=new ArrayList<>();
	Constructor<? extends T> myCtor=null;
	Constructor<? extends T>[] ctors=(Constructor<? extends T>[]) clazz.getConstructors();
	for(Constructor<? extends T> constructor:ctors){
		if(constructor.isAnnotationPresent(ConstructorForDeveloper.class)){
			ctor=constructor;
			break;
		}
	}	
	if(ctor==null){
		AlertHandler.showError("Constructor not found");//Throw exception
		return;
	}
	parameters=ctor.getParameters();
	setterFactory=new VariableSetterFactory(data);
}
 
開發者ID:LtubSalad,項目名稱:voogasalad-ltub,代碼行數:19,代碼來源:DefaultObjectSetter.java

示例5: Select

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
public Constructor Select(Class type) throws NoSuchMethodException {
    Constructor[] constructors = type.getConstructors();
    if (constructors.length == 0) {
        throw new NoSuchMethodException("No constructor was found in " + type.getName());
    }
    for (Constructor<?> constructor : constructors) {
        if (constructor.isAnnotationPresent(Inject.class)) {
            return constructor;
        }
    }
    return constructors[0];
}
 
開發者ID:lemon-project,項目名稱:DependencyInjection,代碼行數:13,代碼來源:DefaultConstructorSelector.java

示例6: getConstructor

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private static <T> Constructor<T> getConstructor(final Key<T> key) {
    final boolean staticClass = Modifier.isStatic(key.getType().getModifiers());
    final Class<?> parentClass = key.getType().getDeclaringClass();
    final boolean innerClass = !staticClass && parentClass != null;

    Constructor<T> inject = null;
    Constructor<T> noarg = null;

    for (final Constructor<T> c : ((Constructor<T>[]) key.getType().getDeclaredConstructors())) {
        if (c.isAnnotationPresent(Inject.class)) {
            if (inject == null) {
                inject = c;
            } else {
                throw new InjectException(String.format("%s has multiple @Inject constructors", key.getType()));
            }
        } else if (c.getParameterTypes().length == 0) {
            noarg = c;
        } else if (innerClass && c.getParameterTypes().length == 1) {
            noarg = c;
        }
    }

    final Constructor<T> constructor = inject != null ? inject : noarg;
    if (constructor == null) {
        throw new InjectException(String.format("%s doesn't have an @Inject or no-arg constructor, or a module provider", key.getType().getName()));
    }

    constructor.setAccessible(true);
    return constructor;
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:32,代碼來源:ConstructorProviderBuilder.java

示例7: injectFieldsIntoClass

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
private Object injectFieldsIntoClass(final Class<?> classToInject)
        throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    for (final Constructor<?> constructor : classToInject.getConstructors()) {
        if (constructor.isAnnotationPresent(OwnInject.class)) {
            return injectFieldsViaConstructor(classToInject, constructor);
        } else {
            return injectFields(classToInject);
        }
    }
    return null;
}
 
開發者ID:zeldan,項目名稱:your-own-dependency-injection-framework,代碼行數:12,代碼來源:OwnDiFramework.java

示例8: findMatchingConstructor

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
/**
 * Finds a constructor suitable for the method. If the implementation contained any constructors marked with {@link AssistedInject}, this requires all
 * {@link Assisted} parameters to exactly match the parameters (in any order) listed in the method. Otherwise, if no {@link AssistedInject} constructors
 * exist, this will default to looking for a {@literal @}{@link Inject} constructor.
 */
private Constructor findMatchingConstructor(Method method, TypeLiteral<?> implementation, List<Key<?>> paramList, Errors errors) throws ErrorsException {
    Constructor<?> matchingConstructor = null;
    boolean anyAssistedInjectConstructors = false;

    // Look for AssistedInject constructors...
    for (Constructor<?> constructor : implementation.getRawType().getDeclaredConstructors()) {
        if (constructor.isAnnotationPresent(AssistedInject.class)) {
            anyAssistedInjectConstructors = true;

            if (constructorHasMatchingParams(implementation, constructor, paramList, errors)) {
                if (matchingConstructor != null) {
                    errors.addMessage(PrettyPrinter.format("%s has more than one constructor annotated with @AssistedInject "
                            + "that matches the parameters in method %s.", implementation, method));
                    return null;
                } else {
                    matchingConstructor = constructor;
                }
            }
        }
    }

    if (matchingConstructor != null) {
        return matchingConstructor;
    }

    if (anyAssistedInjectConstructors) {
        errors.addMessage(PrettyPrinter.format("%s has @AssistedInject constructors, but none of them match the " + "parameters in method %s.",
                implementation, method));
        return null;
    }

    // Look for @Inject constructors...
    Constructor<?> injectConstructor = (Constructor) InjectionPoint.forConstructorOf(implementation).getMember();

    if (injectConstructorHasMatchingParams(implementation, injectConstructor, paramList, errors)) {
        return injectConstructor;
    }

    // No matching constructor exists, complain.
    errors.addMessage(PrettyPrinter.format("%s has no constructors matching the parameters in method %s.", implementation, method));
    return null;
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:48,代碼來源:FactoryBinding.java

示例9: hasAtInject

import java.lang.reflect.Constructor; //導入方法依賴的package包/類
/** Returns true if the inject annotation is on the constructor. */
private static boolean hasAtInject(Constructor cxtor) {
  return cxtor.isAnnotationPresent(Inject.class)
      || cxtor.isAnnotationPresent(javax.inject.Inject.class);
}
 
開發者ID:maetrive,項目名稱:businessworks,代碼行數:6,代碼來源:ConstructorBindingImpl.java


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