Java Code Examples for java.lang.annotation.Annotation#toString()
The following examples show how to use
java.lang.annotation.Annotation#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java From CrepeCake with Apache License 2.0 | 6 votes |
public static String getRawString(Annotation annotation, String key) { String source = annotation.toString(); int start = source.indexOf('('); int end = source.length() - 1; source = source.substring(start + 1, end); String[] tokens = source.split(","); String className = null; for (String token : tokens) { token = token.trim(); String[] parts = token.split("="); if (parts.length == 2 && key.equals(parts[0])) { className = parts[1]; break; } } return className; }
Example 2
Source File: ElementRepAnnoTester.java From hottub with GNU General Public License v2.0 | 5 votes |
private boolean compareArrVals(Annotation[] actualAnnos, String[] expectedAnnos) { // Look if test case was run. if (actualAnnos == specialAnnoArray) { return false; // no testcase matches } if (actualAnnos.length != expectedAnnos.length) { System.out.println("Length not same. " + " actualAnnos length = " + actualAnnos.length + " expectedAnnos length = " + expectedAnnos.length); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { int i = 0; String[] actualArr = new String[actualAnnos.length]; for (Annotation a : actualAnnos) { actualArr[i++] = a.toString(); } List<String> actualList = Arrays.asList(actualArr); List<String> expectedList = Arrays.asList(expectedAnnos); if (!actualList.containsAll(expectedList)) { System.out.println("Array values are not same"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } } return true; }
Example 3
Source File: Key.java From businessworks with Apache License 2.0 | 5 votes |
String getAnnotationName() { Annotation annotation = annotationStrategy.getAnnotation(); if (annotation != null) { return annotation.toString(); } // not test-covered return annotationStrategy.getAnnotationType().toString(); }
Example 4
Source File: ElementRepAnnoTester.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private boolean compareArrVals(Annotation[] actualAnnos, String[] expectedAnnos) { // Look if test case was run. if (actualAnnos == specialAnnoArray) { return false; // no testcase matches } if (actualAnnos.length != expectedAnnos.length) { System.out.println("Length not same. " + " actualAnnos length = " + actualAnnos.length + " expectedAnnos length = " + expectedAnnos.length); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { int i = 0; String[] actualArr = new String[actualAnnos.length]; for (Annotation a : actualAnnos) { actualArr[i++] = a.toString(); } List<String> actualList = Arrays.asList(actualArr); List<String> expectedList = Arrays.asList(expectedAnnos); if (!actualList.containsAll(expectedList)) { System.out.println("Array values are not same"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } } return true; }
Example 5
Source File: PokeHelper.java From AndroidMvc with Apache License 2.0 | 5 votes |
static String makeProviderKey(Class type, Annotation qualifier) { String qualifierStr; if (qualifier == null) { qualifierStr = "@null"; } else { if (qualifier.annotationType() == Named.class) { qualifierStr = qualifier.toString() + ":" + ((Named) qualifier).value(); } else { qualifierStr = qualifier.toString(); } } return type.getName() + qualifierStr; }
Example 6
Source File: Key.java From Elasticsearch with Apache License 2.0 | 5 votes |
String getAnnotationName() { Annotation annotation = annotationStrategy.getAnnotation(); if (annotation != null) { return annotation.toString(); } // not test-covered return annotationStrategy.getAnnotationType().toString(); }
Example 7
Source File: ElementRepAnnoTester.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private boolean compareArrVals(Annotation[] actualAnnos, String[] expectedAnnos) { // Look if test case was run. if (actualAnnos == specialAnnoArray) { return false; // no testcase matches } if (actualAnnos.length != expectedAnnos.length) { System.out.println("Length not same. " + " actualAnnos length = " + actualAnnos.length + " expectedAnnos length = " + expectedAnnos.length); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { int i = 0; String[] actualArr = new String[actualAnnos.length]; for (Annotation a : actualAnnos) { actualArr[i++] = a.toString(); } List<String> actualList = Arrays.asList(actualArr); List<String> expectedList = Arrays.asList(expectedAnnos); if (!actualList.containsAll(expectedList)) { System.out.println("Array values are not same"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } } return true; }
Example 8
Source File: Utils.java From datakernel with Apache License 2.0 | 5 votes |
@NotNull public static String getDisplayString(@NotNull Class<? extends Annotation> annotationType, @Nullable Annotation annotation) { if (annotation == null) { return "@" + ReflectionUtils.getDisplayName(annotationType); } String typeName = annotationType.getName(); String str = annotation.toString(); return str.startsWith("@" + typeName) ? "@" + ReflectionUtils.getDisplayName(annotationType) + str.substring(typeName.length() + 1) : str; }
Example 9
Source File: Key.java From crate with Apache License 2.0 | 5 votes |
String getAnnotationName() { Annotation annotation = annotationStrategy.getAnnotation(); if (annotation != null) { return annotation.toString(); } // not test-covered return annotationStrategy.getAnnotationType().toString(); }
Example 10
Source File: ElementRepAnnoTester.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private boolean compareArrVals(Annotation[] actualAnnos, String[] expectedAnnos) { // Look if test case was run. if (actualAnnos == specialAnnoArray) { return false; // no testcase matches } if (actualAnnos.length != expectedAnnos.length) { System.out.println("Length not same. " + " actualAnnos length = " + actualAnnos.length + " expectedAnnos length = " + expectedAnnos.length); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { int i = 0; String[] actualArr = new String[actualAnnos.length]; for (Annotation a : actualAnnos) { actualArr[i++] = a.toString(); } List<String> actualList = Arrays.asList(actualArr); List<String> expectedList = Arrays.asList(expectedAnnos); if (!actualList.containsAll(expectedList)) { System.out.println("Array values are not same"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } } return true; }
Example 11
Source File: FilterStoreBean.java From db with GNU Affero General Public License v3.0 | 4 votes |
/** * Process a given filter class to check for all criteria required to be a filter * * @param datastore : dsSet name * @param filterClass : Class for the filter * @throws OperationException: * 1. if Interface is not implemented * 2. if the class is not present in Manifest file * 3. if annotation Filter is not present * 4. if more than one Filter annotation is found */ public void processClass(final String datastore, final Class filterClass) throws OperationException{ // checking if interface is implemented or not. if( !Filterable.class.isAssignableFrom(filterClass)) { throw new OperationException(ErrorCode.FILTER_LOAD_ERROR, "Specified filter " + filterClass.getCanonicalName() + " inside dsSet " + datastore + " doesn't implement Filterable interface" ); } logger.trace("processClass({}, {}) as filter", new Object[]{datastore, filterClass.getCanonicalName()}); // checking for filters in Manifest file List<String> filters = manifestParser.getFilters(datastore); if ( !filters.contains(filterClass.getSimpleName()) ){ throw new OperationException(ErrorCode.FILTER_LOAD_ERROR, "No such filter " +filterClass.getSimpleName() + " is defined in Manifest file"); } String filterName = null; // checking for 'filter' annotation final Annotation[] annotations = filterClass.getAnnotations(); for(Annotation annotation: annotations){ if( "com.blobcity.db.annotations.Filter".equals(annotation.annotationType().getCanonicalName()) ){ // name is supplied in annotation or not if(filterName == null){ if(annotation.toString().contains("name")){ String filterAnnotation = annotation.toString(); filterName = filterAnnotation.substring(filterAnnotation.indexOf("name=") + 5, filterAnnotation.length()-1); } else{ filterName = filterClass.getSimpleName(); logger.debug("{} found annotation FilterStoreBean with filter name {}", new Object[]{filterClass.getCanonicalName(), filterName}); } } else{ logger.debug("{} found duplicate annotation FilterName", new Object[]{filterClass.getCanonicalName()}); throw new OperationException(ErrorCode.FILTER_LOAD_ERROR, "Duplicate @Filter " + "annotation found on class " + filterClass.getCanonicalName() + ". A single filter class " + "may have only one @Filter annotation associated with it."); } } } if(!classMap.containsKey(datastore)){ classMap.put(datastore, new HashMap<>()); } classMap.get(datastore).put(filterName, filterClass.getCanonicalName() ); }
Example 12
Source File: Key.java From dagger-reflect with Apache License 2.0 | 4 votes |
@Override public final String toString() { Annotation qualifier = qualifier(); String type = getTypeName(type()); return qualifier != null ? qualifier.toString() + ' ' + type : type; }
Example 13
Source File: ReflectionTest.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private static boolean compareAnnotations(Annotation[] actualAnnos, String[] expectedAnnos) { boolean compOrder = false; // Length is different if (actualAnnos.length != expectedAnnos.length) { error("Length not same, Actual length = " + actualAnnos.length + " Expected length = " + expectedAnnos.length); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { int i = 0; // Length is same and 0 if (actualAnnos.length == 0) { // Expected/actual lengths already checked for // equality; no more checks do to return true; } // Expected annotation should be NULL if (actualAnnos[0] == null) { if (expectedAnnos[0].equals("NULL")) { debugPrint("Arr values are NULL as expected"); return true; } else { error("Array values are not NULL"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } } // Lengths are same, compare array contents String[] actualArr = new String[actualAnnos.length]; for (Annotation a : actualAnnos) { if (a.annotationType().getSimpleName().contains("Expected")) actualArr[i++] = a.annotationType().getSimpleName(); else if (a.annotationType().getName().contains(TESTPKG)) { String replaced = a.toString().replaceAll(Pattern.quote("testpkg."),""); actualArr[i++] = replaced; } else actualArr[i++] = a.toString(); } List<String> actualList = new ArrayList<String>(Arrays.asList(actualArr)); List<String> expectedList = new ArrayList<String>(Arrays.asList(expectedAnnos)); if (!actualList.containsAll(expectedList)) { error("Array values are not same"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { debugPrint("Arr values are same as expected"); if (CHECKORDERING) { debugPrint("Checking if annotation ordering is as expected.."); compOrder = compareOrdering(actualList, expectedList); if (compOrder) debugPrint("Arr values ordering is as expected"); else error("Arr values ordering is not as expected! actual values: " + actualList + " expected values: " + expectedList); } else compOrder = true; } } return compOrder; }
Example 14
Source File: Constraints.java From ldp4j with Apache License 2.0 | 4 votes |
public ConstraintViolationException(String message, Annotation constraint, Member member, List<String> violations) { super(message); this.constraint = constraint.toString(); this.member=member.toString(); this.violations=new ArrayList<String>(violations); }
Example 15
Source File: ReflectionTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private static boolean compareAnnotations(Annotation[] actualAnnos, String[] expectedAnnos) { boolean compOrder = false; // Length is different if (actualAnnos.length != expectedAnnos.length) { error("Length not same, Actual length = " + actualAnnos.length + " Expected length = " + expectedAnnos.length); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { int i = 0; // Length is same and 0 if (actualAnnos.length == 0) { // Expected/actual lengths already checked for // equality; no more checks do to return true; } // Expected annotation should be NULL if (actualAnnos[0] == null) { if (expectedAnnos[0].equals("NULL")) { debugPrint("Arr values are NULL as expected"); return true; } else { error("Array values are not NULL"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } } // Lengths are same, compare array contents String[] actualArr = new String[actualAnnos.length]; for (Annotation a : actualAnnos) { if (a.annotationType().getSimpleName().contains("Expected")) actualArr[i++] = a.annotationType().getSimpleName(); else if (a.annotationType().getName().contains(TESTPKG)) { String replaced = a.toString().replaceAll(Pattern.quote("testpkg."),""); actualArr[i++] = replaced; } else actualArr[i++] = a.toString(); } List<String> actualList = new ArrayList<String>(Arrays.asList(actualArr)); List<String> expectedList = new ArrayList<String>(Arrays.asList(expectedAnnos)); if (!actualList.containsAll(expectedList)) { error("Array values are not same"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { debugPrint("Arr values are same as expected"); if (CHECKORDERING) { debugPrint("Checking if annotation ordering is as expected.."); compOrder = compareOrdering(actualList, expectedList); if (compOrder) debugPrint("Arr values ordering is as expected"); else error("Arr values ordering is not as expected! actual values: " + actualList + " expected values: " + expectedList); } else compOrder = true; } } return compOrder; }
Example 16
Source File: ReflectionTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
private static boolean compareAnnotations(Annotation[] actualAnnos, String[] expectedAnnos) { boolean compOrder = false; // Length is different if (actualAnnos.length != expectedAnnos.length) { error("Length not same, Actual length = " + actualAnnos.length + " Expected length = " + expectedAnnos.length); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { int i = 0; // Length is same and 0 if (actualAnnos.length == 0) { // Expected/actual lengths already checked for // equality; no more checks do to return true; } // Expected annotation should be NULL if (actualAnnos[0] == null) { if (expectedAnnos[0].equals("NULL")) { debugPrint("Arr values are NULL as expected"); return true; } else { error("Array values are not NULL"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } } // Lengths are same, compare array contents String[] actualArr = new String[actualAnnos.length]; for (Annotation a : actualAnnos) { if (a.annotationType().getSimpleName().contains("Expected")) actualArr[i++] = a.annotationType().getSimpleName(); else if (a.annotationType().getName().contains(TESTPKG)) { String replaced = a.toString().replaceAll(Pattern.quote("testpkg."),""); actualArr[i++] = replaced; } else actualArr[i++] = a.toString(); } List<String> actualList = new ArrayList<String>(Arrays.asList(actualArr)); List<String> expectedList = new ArrayList<String>(Arrays.asList(expectedAnnos)); if (!actualList.containsAll(expectedList)) { error("Array values are not same"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { debugPrint("Arr values are same as expected"); if (CHECKORDERING) { debugPrint("Checking if annotation ordering is as expected.."); compOrder = compareOrdering(actualList, expectedList); if (compOrder) debugPrint("Arr values ordering is as expected"); else error("Arr values ordering is not as expected! actual values: " + actualList + " expected values: " + expectedList); } else compOrder = true; } } return compOrder; }
Example 17
Source File: ReflectionTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static boolean compareAnnotations(Annotation[] actualAnnos, String[] expectedAnnos) { boolean compOrder = false; // Length is different if (actualAnnos.length != expectedAnnos.length) { error("Length not same, Actual length = " + actualAnnos.length + " Expected length = " + expectedAnnos.length); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { int i = 0; // Length is same and 0 if (actualAnnos.length == 0) { // Expected/actual lengths already checked for // equality; no more checks do to return true; } // Expected annotation should be NULL if (actualAnnos[0] == null) { if (expectedAnnos[0].equals("NULL")) { debugPrint("Arr values are NULL as expected"); return true; } else { error("Array values are not NULL"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } } // Lengths are same, compare array contents String[] actualArr = new String[actualAnnos.length]; for (Annotation a : actualAnnos) { if (a.annotationType().getSimpleName().contains("Expected")) actualArr[i++] = a.annotationType().getSimpleName(); else if (a.annotationType().getName().contains(TESTPKG)) { String replaced = a.toString().replaceAll(Pattern.quote("testpkg."),""); actualArr[i++] = replaced; } else actualArr[i++] = a.toString(); } List<String> actualList = new ArrayList<String>(Arrays.asList(actualArr)); List<String> expectedList = new ArrayList<String>(Arrays.asList(expectedAnnos)); if (!actualList.containsAll(expectedList)) { error("Array values are not same"); printArrContents(actualAnnos); printArrContents(expectedAnnos); return false; } else { debugPrint("Arr values are same as expected"); if (CHECKORDERING) { debugPrint("Checking if annotation ordering is as expected.."); compOrder = compareOrdering(actualList, expectedList); if (compOrder) debugPrint("Arr values ordering is as expected"); else error("Arr values ordering is not as expected! actual values: " + actualList + " expected values: " + expectedList); } else compOrder = true; } } return compOrder; }
Example 18
Source File: StatePane.java From attic-polygene-java with Apache License 2.0 | 4 votes |
private void reload( CompositeMethodDetailDescriptor descriptor ) { clear(); // mixin type rows.add( new TableRow( 2, "interface", descriptor.descriptor().method().getDeclaringClass().getSimpleName() ) ); StringBuilder str = new StringBuilder(); for( Annotation annotation : descriptor.descriptor().method().getAnnotations() ) { String ann = annotation.toString(); ann = "@" + ann.substring( ann.lastIndexOf( '.' ) + 1 ); str.append( ann ).append( " " ); } str.append( Classes.simpleGenericNameOf( descriptor.descriptor().method().getGenericReturnType() ) ); rows.add( new TableRow( 2, "return", str.toString() ) ); // concern boolean first = true; for( MethodConcernDetailDescriptor concern : descriptor.concerns().concerns() ) { if( first ) { rows.add( new TableRow( 2, "concern", concern.toString() ) ); first = false; } else { rows.add( new TableRow( 2, "", concern.toString() ) ); } } // sideEffect first = false; for( MethodSideEffectDetailDescriptor sideEffect : descriptor.sideEffects().sideEffects() ) { if( first ) { rows.add( new TableRow( 2, "sideEffect", sideEffect.toString() ) ); first = false; } else { rows.add( new TableRow( 2, "", sideEffect.toString() ) ); } } fireTableDataChanged(); }
Example 19
Source File: MethodPane.java From attic-polygene-java with Apache License 2.0 | 4 votes |
private void reload( CompositeMethodDetailDescriptor descriptor ) { Method method = descriptor.descriptor().method(); clear(); // mixin type rows.add( new TableRow( 2, "return", Classes.simpleGenericNameOf( method.getGenericReturnType() ) ) ); // method StringBuilder parameters = new StringBuilder(); for( int idx = 0; idx < method.getGenericParameterTypes().length; idx++ ) { Type type = method.getGenericParameterTypes()[idx]; Annotation[] annotations = method.getParameterAnnotations()[idx]; if( parameters.length() > 0 ) { parameters.append( ", " ); } for( Annotation annotation : annotations ) { String ann = annotation.toString(); ann = "@" + ann.substring( ann.lastIndexOf( '.' ) + 1 ); parameters.append( ann ).append( " " ); } parameters.append( Classes.simpleGenericNameOf( type ) ); } rows.add( new TableRow( 2, "parameters", parameters.toString() ) ); // concern boolean first = true; for( MethodConcernDetailDescriptor concern : descriptor.concerns().concerns() ) { if( first ) { rows.add( new TableRow( 2, "concern", concern.descriptor().modifierClass().getSimpleName() ) ); first = false; } else { rows.add( new TableRow( 2, "", concern.descriptor().modifierClass().getSimpleName() ) ); } } // sideEffect first = false; for( MethodSideEffectDetailDescriptor sideEffect : descriptor.sideEffects().sideEffects() ) { if( first ) { rows.add( new TableRow( 2, "sideEffect", sideEffect.descriptor().modifierClass().getSimpleName() ) ); first = false; } else { rows.add( new TableRow( 2, "", sideEffect.descriptor().modifierClass().getSimpleName() ) ); } } fireTableDataChanged(); }
Example 20
Source File: RobotRequestHandler.java From openAGV with Apache License 2.0 | 4 votes |
private Method getMethod(Class<?> controllerClass, String uri, String controllerName){ if (null == controllerName) { throw new NullPointerException("controller name is empty"); } Method method = SparkMappingFactory.getMethodMap().get(uri); if (null != method) { return method; } else { try { // consoleControllerClass = Class.forName(System.getProperty(ID)); // Injector injector = Guice.createInjector(new Module() { // @Override // public void configure(Binder binder) { // binder.bind(consoleControllerClass).in(Scopes.SINGLETON); // } // }); // consoleControllerObj = injector.getInstance(consoleControllerClass); // 根据请求的URI与method对应的Mapping关联 Method[] methods = controllerClass.getMethods(); for (Method action : methods) { if (!isPublicMethod(action.getModifiers()) || EXCLUDED_METHOD_NAME.contains(action.getName())) { continue; } String key = action.getName(); Annotation[] annotations = action.getAnnotations(); if (null != annotations && annotations.length >= 1) { for (Annotation annotation : annotations) { String annotString = annotation.toString(); if (!Strings.isNullOrEmpty(annotString) && annotString.contains("Mapping")) { annotString = annotString.substring(annotString.indexOf("(") + 1, annotString.indexOf(")")); String[] annStringArray = annotString.split(","); for (String annItem : annStringArray) { String[] annItemArray = annItem.split("="); if ("value".equalsIgnoreCase(annItemArray[0])) { // 以注解的value值为映射路径 key = annItemArray[1].trim().toLowerCase(); key = (controllerName.startsWith("/")?controllerName:"/"+controllerName) + (key.startsWith("/")?key:"/"+key); SparkMappingFactory.getMethodMap().put(key, action); } } } } } else { SparkMappingFactory.getMethodMap().put("/" + controllerName + "/" + key.toLowerCase(), action); } } } catch (Exception e) { e.printStackTrace(); } } return SparkMappingFactory.getMethodMap().get(uri); }