Java Code Examples for java.lang.reflect.Method.getAnnotations()

The following are Jave code examples for showing how to use getAnnotations() of the java.lang.reflect.Method class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Equella   File: SecurityAttributeSource.java   View Source Code Vote up 6 votes
private SecurityAttribute findSecurityAttribute(Method method, Class<?> targetClass)
{
	SecurityAttribute attr = new SecurityAttribute();
	Annotation[] annotations = method.getAnnotations();
	boolean have = addAnnotationAttrs(annotations, attr, targetClass);

	if( !have )
	{
		return null;
	}
	if( DebugSettings.isDebuggingMode() && method.getDeclaringClass().isInterface() )
	{
		LOGGER.error("**************************************************"); //$NON-NLS-1$
		LOGGER.error("Please move these to the implementation:" + method); //$NON-NLS-1$
		LOGGER.error("**************************************************"); //$NON-NLS-1$
	}
	if( attr.getOnCallmode() == OnCallMode.DOMAIN )
	{
		attr.setDomainArg(getDomainObjectParameter(method));
	}
	return attr;
}
 
Example 2
Project: satisfy   File: SatisfyAnnotatedStepDescription.java   View Source Code Vote up 6 votes
private Optional<String> getCompatibleStepNameFrom(Method testMethod) {
    Annotation[] annotations = testMethod.getAnnotations();
    for (Annotation annotation : annotations) {
        if (isACompatibleStep(annotation)) {
            try {
                String annotationType = annotation.annotationType()
                        .getSimpleName();
                String annotatedValue = (String) annotation.getClass()
                        .getMethod("value").invoke(annotation);
                if (StringUtils.isEmpty(annotatedValue)) {
                    return Optional.absent();
                } else {
                    return Optional.of(annotationType + " " + StringUtils
                            .uncapitalize(annotatedValue));
                }

            } catch (Exception ignoredException) {
            }
        }
    }
    return Optional.absent();
}
 
Example 3
Project: Core-Java   File: FrameworkAnnotationResolver.java   View Source Code Vote up 6 votes
private void checkMethodAnnotation(Class clazz, Method method){
    Map<String, AnnotationClazz> urlMap = (Map<String, AnnotationClazz>) annotationObjectMap.get(AnnotationObjectType.URL);
    if(urlMap == null){
        urlMap = new HashMap<>();
    }
    Annotation[] annotations = method.getAnnotations();
    for (int i=0;i<annotations.length;i++){
        if (annotations[i].annotationType().equals(RequestMapping.class)){
            String uri = ((RequestMapping)annotations[i]).uri();
            HttpMethod.Type type = ((RequestMapping)annotations[i]).method();
            String URI = getURIKey(type, uri);
            AnnotationClazz annotationClazz = AnnotationClazz.builder().clazzName(clazz.getName()).methodName(method.getName()).build();
            urlMap.put(URI, annotationClazz);
        }
    }
    annotationObjectMap.put(AnnotationObjectType.URL, urlMap);
}
 
Example 4
Project: febit   File: AnnotationUtil.java   View Source Code Vote up 6 votes
public static String getActionAnnoValue(Method method) {
    Action actionAnno;
    actionAnno = method.getAnnotation(Action.class);
    if (actionAnno != null) {
        return actionAnno.value();
    }
    Annotation[] annotations = method.getAnnotations();
    for (int i = annotations.length - 1; i >= 0; i--) {
        Annotation anno = annotations[i];
        if (!AnnotationUtil.isActionAnnotation(anno)) {
            continue;
        }
        actionAnno = anno.annotationType().getAnnotation(Action.class);
        if (actionAnno != null) {
            return actionAnno.value();
        }
    }
    return null;
}
 
Example 5
Project: febit   File: AnnotationUtil.java   View Source Code Vote up 6 votes
public static List<String> getHttpMethods(Method method) {
    List<String> httpMethods = new ArrayList<>();
    String httpMethod = getHttpMethod(method.getAnnotation(HttpMethod.class));
    if (httpMethod != null) {
        httpMethods.add(httpMethod);
    }
    for (Annotation anno : method.getAnnotations()) {
        httpMethod = getHttpMethod(anno);
        if (httpMethod != null) {
            httpMethods.add(httpMethod);
        }
        if (AnnotationUtil.isActionAnnotation(anno)) {
            for (Annotation interAnnotation : anno.annotationType().getAnnotations()) {
                httpMethod = getHttpMethod(interAnnotation);
                if (httpMethod != null) {
                    httpMethods.add(httpMethod);
                }
            }
        }
    }
    return httpMethods;
}
 
Example 6
Project: saluki   File: ReflectUtils.java   View Source Code Vote up 5 votes
public static Annotation findAnnotationFromMethod(Method method,
    Class<? extends Annotation> annotation) {
  for (Annotation targetAnnotation : method.getAnnotations()) {
    if (annotation.isAssignableFrom(targetAnnotation.annotationType())) {
      return targetAnnotation;
    } else {
      continue;
    }
  }
  return null;
}
 
Example 7
Project: dataset-lib   File: AppServer.java   View Source Code Vote up 5 votes
@Hidden
public void recieve(int port,int paramBufferSize,int maxFileSize) {
    ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
    serverSocketChannel.socket().bind(new InetSocketAddress(port));
    ByteBuffer parameters = ByteBuffer.allocate(paramBufferSize);
    ByteBuffer content = ByteBuffer.allocate(maxFileSize);
    CharBuffer buffer = CharBuffer.allocate(paramBufferSize);
    List < ScheduledFuture > futures = new ArrayList < ScheduledFuture > ();
    ExecutorService executorService = Executors.newFixedThreadPool(maxAgents);
    int currentConnections;
    Method[] methods=servlet.class.getDeclaredMethods();
    List<String> methodNames=new ArrayList<String>();
    ConcurrentHashMap<String,Method> hashMap=new ConcurrentHashMap<String,Method>();
    SocketChannel[] sections;
    for(Method method:methods){
        Annotation[] annotations=method.getAnnotations();
        if(Arrays.asList(annotations).contains(Hidden.class)){
            continue;
        }
        else{
        hashMap.put(method.getName(),method);
        methodNames.add(method.getName());
        }
    }
    Runnable serverThread = () -> {
       /* socketChannel.read(parameters);
        if (params[0].equals("put")) {
            socketChannel.read(content);
            
        }
        buffer = buff.asCharBuffer();
        String str = buffer.toString();
        String[] params = str.split(":");
        if (params[0].equals("put")) {       
            java.nio.file.Path p = Paths.get(tempPath + params[2]);
            Files.write(p, content.array());
            this.put(params);
            Files.delete(p);
        } else if (params[0].equals("get")) {
            ByteBuffer b = this.get(params);
            socketChannel.write(b);
        } else if (params[0].equals("remove")) {
            this.remove(params);
        }
        futures.remove(i);*/
        
    };
    while (acceptingConnections) {
        socketChannel[0] = serverSocketChannel.accept();
        if (socketChannel != null) {
            ScheduledFuture future = executorService.submit(serverThread);
            i = futures.size();
            futures.add(future);
        }
    }
}
 
Example 8
Project: super-volley   File: ServiceMethod.java   View Source Code Vote up 5 votes
Builder(SuperVolley volley, Method method) {
    this.volley = volley;
    this.method = method;
    this.methodAnnotations = method.getAnnotations();
    this.parameterTypes = method.getGenericParameterTypes();
    this.parameterAnnotationsArray = method.getParameterAnnotations();
}
 
Example 9
Project: vogar   File: Junit4.java   View Source Code Vote up 5 votes
private void invokeMethodWithAnnotation(Object testCase, Class<?> annotation)
        throws IllegalAccessException, InvocationTargetException {
    for (Method m : testCase.getClass().getDeclaredMethods()) {
        for (Annotation a : m.getAnnotations()) {
            if (annotation.isAssignableFrom(a.annotationType())) {
                m.invoke(testCase);
            }
        }
    }
}
 
Example 10
Project: hadoop-oss   File: MetricsSourceBuilder.java   View Source Code Vote up 5 votes
/** Add {@link MutableMetric} for a method annotated with {@link Metric} */
private void add(Object source, Method method) {
  for (Annotation annotation : method.getAnnotations()) {
    if (!(annotation instanceof Metric)) {
      continue;
    }
    factory.newForMethod(source, method, (Metric) annotation, registry);
    hasAtMetric = true;
  }
}
 
Example 11
Project: AgentWebX5   File: JsBaseInterfaceHolder.java   View Source Code Vote up 5 votes
@Override
public boolean checkObject(Object v) {

    if(Build.VERSION.SDK_INT<Build.VERSION_CODES.JELLY_BEAN_MR1)
        return true;
    if(AgentWebX5Config.WEBVIEW_TYPE== AgentWebX5Config.WEBVIEW_AGENTWEB_SAFE_TYPE)
        return true;
    boolean tag=false;
    Class clazz=v.getClass();

    Method[] mMethods= clazz.getMethods();

    for(Method mMethod:mMethods){

        Annotation[]mAnnotations= mMethod.getAnnotations();

        for(Annotation mAnnotation:mAnnotations){

            if(mAnnotation instanceof JavascriptInterface){
                tag=true;
                break;
            }

        }
        if(tag)
            break;
    }

    return tag;
}
 
Example 12
Project: avaire   File: Model.java   View Source Code Vote up 5 votes
public Model with(String... fields) {
    List<String> methods = new ArrayList<>();
    methods.addAll(Arrays.asList(fields));

    Class<? extends Model> iClass = instance().getClass();

    for (Method method : iClass.getMethods()) {
        if (!methods.contains(method.getName())) {
            continue;
        }

        if (method.getAnnotations().length == 0) {
            continue;
        }

        boolean isQueryHandler = false;
        for (Annotation an : method.getAnnotations()) {
            if (an.annotationType().getName().equals(QueryScope.class.getName())) {
                isQueryHandler = true;
                break;
            }
        }

        if (isQueryHandler) {
            try {
                method.setAccessible(true);
                method.invoke(instance(), builder);
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                Logger.getLogger(Model.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    return this;
}
 
Example 13
Project: Samurai   File: AnnotationUtil.java   View Source Code Vote up 5 votes
public static Annotation[] getAnnotations(Method method) {
    Method originMethod = null;
    try {
        originMethod = getOriginMethod(method);
        return originMethod.getAnnotations();
    } catch (NoSuchMethodException e) {
         throw new RuntimeException(e);
    }
}
 
Example 14
Project: febit   File: AnnotationUtil.java   View Source Code Vote up 5 votes
public static boolean hasAnnotation(Method method, Class<? extends Annotation> annoClass) {
    if (method.getAnnotation(annoClass) != null) {
        return true;
    }
    for (Annotation anno : method.getAnnotations()) {
        if (!isActionAnnotation(anno)) {
            continue;
        }
        if (anno.annotationType().getAnnotation(annoClass) != null) {
            return true;
        }
    }
    return false;
}
 
Example 15
Project: minijax   File: MinijaxGetterDescriptor.java   View Source Code Vote up 4 votes
public MinijaxGetterDescriptor(final Method getter) {
    super(getter.getDeclaringClass(), getter.getAnnotatedReturnType(), getter.getAnnotations());
    this.getter = getter;
    propertyName = getter.getName().substring(3, 4).toLowerCase() + getter.getName().substring(4);
}
 
Example 16
Project: rest.vertx   File: RouteDefinitionTest.java   View Source Code Vote up 4 votes
@Test
public void getDefinitionTest() throws NoSuchMethodException {

	RouteDefinition base = new RouteDefinition(TestRest.class);

	assertEquals("/test", base.getPath());

	assertNotNull(base.getProduces());
	assertEquals(1, base.getProduces().length);

	assertNull(base.getMethod());
	assertNull(base.getConsumes());

	// 2.
	Method method = TestRest.class.getMethod("echo");
	RouteDefinition def = new RouteDefinition(base, method.getAnnotations());

	assertEquals("/test/echo", def.getPath());

	assertNotNull(def.getProduces());
	assertEquals(1, def.getProduces().length);

	assertEquals(HttpMethod.GET, def.getMethod());

	assertNull(def.getConsumes());
}
 
Example 17
Project: irked   File: RouteConfigurationMethod.java   View Source Code Vote up 4 votes
public RouteConfigurationMethod(Controller impl, Method m) {
	super(impl, m.getAnnotations());
	method = m;
}
 
Example 18
Project: OpenJSharp   File: ReflectAnnotationReader.java   View Source Code Vote up 4 votes
public Annotation[] getAnnotations(Method m) {
        return m.getAnnotations();
}
 
Example 19
Project: martini-core   File: AmbiguousStepException.java   View Source Code Vote up 4 votes
protected String getDetail(StepImplementation match) {
	Method method = match.getMethod();
	Annotation[] annotations = method.getAnnotations();
	String joinedAnnotations = Joiner.on("\n\t").join(annotations);
	return String.format("%s\nwith annotations\n\t%s", method, joinedAnnotations);
}
 
Example 20
Project: SwiftModule   File: IntentMethod.java   View Source Code Vote up 4 votes
public Builder(Method method){
  this.method = method;
  this.methodAnnotations = method.getAnnotations();
  this.parameterTypes = method.getGenericParameterTypes();
  this.parameterAnnotationsArray = method.getParameterAnnotations();
}