Created
May 23, 2017 15:01
-
-
Save fermopili/5e72c243dfec51d1b66a8cb05a1b9cfb to your computer and use it in GitHub Desktop.
com.javarush.task.task38.task3812 Обработка аннотаций
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task38.task3812; | |
public class Fox { | |
String name = "fox"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task38.task3812; | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target(ElementType.TYPE) | |
//@PrepareForTest | |
public @interface PrepareMyTest { | |
Class<?>[] value() default Solution.class; | |
String[] fullyQualifiedNames() default ""; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task38.task3812; | |
/* | |
Обработка аннотаций | |
*/ | |
public class Solution | |
{ | |
public static void main(String[] args) | |
{ | |
printFullyQualifiedNames ( Solution.class ); | |
printFullyQualifiedNames ( SomeTest.class ); | |
printValues ( Solution.class ); | |
printValues ( SomeTest.class ); | |
} | |
public static boolean printFullyQualifiedNames(Class c) | |
{ | |
if (c.isAnnotationPresent ( PrepareMyTest.class )) | |
{ | |
PrepareMyTest prepareMyTest = (PrepareMyTest) c.getAnnotation ( PrepareMyTest.class ); | |
for (String string : prepareMyTest.fullyQualifiedNames ( )) | |
System.out.println ( string ); | |
return true; | |
} | |
return false; | |
// return true; | |
} | |
public static boolean printValues(Class c) | |
{ | |
if (c.isAnnotationPresent ( PrepareMyTest.class )) | |
{ | |
PrepareMyTest prepareMyTest = (PrepareMyTest) c.getAnnotation ( PrepareMyTest.class ); | |
for (Class clazz : prepareMyTest.value ( )) | |
System.out.println ( clazz.getSimpleName ( ) ); | |
return true; | |
} | |
return false; | |
// return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task38.task3812; | |
@PrepareMyTest(value = {Solution.class, SomeTest.class}, fullyQualifiedNames = {"com.javarush.task.task38.task3812.Fox"}) | |
public class SomeTest { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
taskKey="com.javarush.task.task38.task3812" | |
Обработка аннотаций | |
В классе Solution необходимо реализовать простейшую обработку аннотаций. | |
В методы printFullyQualifiedNames и printValues приходит класс. Если этот класс отмечен аннотацией | |
PrepareMyTest, необходимо вывести на экран fullyQualifiedNames и values в соответствующих методах и вернуть | |
true. Если же аннотация PrepareMyTest отсутствует - вернуть false. | |
Для вывода на экран классов из массива value используй сокращенное имя (getSimpleName). | |
Требования: | |
1. Метод printFullyQualifiedNames должен возвращать false в случае, если переданный в качестве параметра класс не отмечен аннотацией @PrepareMyTest. | |
2. Метод printValues должен возвращать false в случае, если переданный в качестве параметра класс не отмечен аннотацией @PrepareMyTest. | |
3. Метод printFullyQualifiedNames должен выводить на экран все элементы массива fullyQualifiedValues, и возвращать true, если полученный класс отмечен аннотацией @PrepareMyTest. | |
4. Метод printValues должен выводить на экран все элементы массива value используя их сокращенное имя, и возвращать true, если полученный класс отмечен аннотацией @PrepareMyTest. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment