org.objectweb.asm.commons.EmptyVisitor Java Examples

The following examples show how to use org.objectweb.asm.commons.EmptyVisitor. 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: CyclicReferencesTestTest.java    From development with Apache License 2.0 6 votes vote down vote up
private void assertFiledTypes(final Class<?> type, String... expected)
        throws IOException {
    final ClassReader reader = new ClassReader(type.getName());
    final Set<String> actual = new HashSet<String>();
    reader.accept(new EmptyVisitor() {
        @Override
        public FieldVisitor visitField(int access, String name,
                String desc, String signature, Object value) {
            if ((access & Opcodes.ACC_SYNTHETIC) == 0) {
                if (signature == null) {
                    signature = desc;
                }
                cyclicRefsTest.getTypesFromSignature(signature, actual);
            }
            return null;
        }
    }, 0);
    assertEquals(new HashSet<String>(Arrays.asList(expected)), actual);
}
 
Example #2
Source File: AnnotationMetadataReadingVisitor.java    From thinking-in-spring-boot-samples with Apache License 2.0 5 votes vote down vote up
public AnnotationVisitor visitAnnotation(final String desc, boolean visible) {
    final String className = Type.getType(desc).getClassName();
    final Map<String, Object> attributes = new LinkedHashMap<String, Object>();
    return new EmptyVisitor() {
        public void visit(String name, Object value) {
            // Explicitly defined annotation attribute value.
            attributes.put(name, value);
        }
        public void visitEnd() {
            try {
                Class annotationClass = classLoader.loadClass(className);
                // Check declared default values of attributes in the annotation type.
                Method[] annotationAttributes = annotationClass.getMethods();
                for (int i = 0; i < annotationAttributes.length; i++) {
                    Method annotationAttribute = annotationAttributes[i];
                    String attributeName = annotationAttribute.getName();
                    Object defaultValue = annotationAttribute.getDefaultValue();
                    if (defaultValue != null && !attributes.containsKey(attributeName)) {
                        attributes.put(attributeName, defaultValue);
                    }
                }
                // Register annotations that the annotation type is annotated with.
                Annotation[] metaAnnotations = annotationClass.getAnnotations();
                Set<String> metaAnnotationTypeNames = new HashSet<String>();
                for (Annotation metaAnnotation : metaAnnotations) {
                    metaAnnotationTypeNames.add(metaAnnotation.annotationType().getName());
                }
                metaAnnotationMap.put(className, metaAnnotationTypeNames);
            }
            catch (ClassNotFoundException ex) {
                // Class not found - can't determine meta-annotations.
            }
            attributesMap.put(className, attributes);
        }
    };
}
 
Example #3
Source File: RetroWeaverGui.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private Thread createWeaverThread() {
	return new Thread(new Runnable() {
		public void run() {
			Cursor oldCursor = getTopLevelAncestor().getCursor();
			getTopLevelAncestor().setCursor(
					Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

			try {
				status.setText("Running");
				RetroWeaver weaver = new RetroWeaver(version);
				messages.setText("");
				weaver.setListener(RetroWeaverGui.this);

				String refCp = refClassPath.getText();

				if (refCp.length() != 0) {
					java.util.List<String> classpath = new ArrayList<String>();
					StringTokenizer st = new StringTokenizer(refCp,
							File.pathSeparator);
					while (st.hasMoreTokens()) {
						classpath.add(st.nextToken());
					}
					RefVerifier verifier = new RefVerifier(version, new EmptyVisitor(), classpath,
							RetroWeaverGui.this);
					weaver.setVerifier(verifier);
				}

				weaver.weave(path);

				status.setText("Done");
			} catch (Exception ex) {
				status.setText("Error: " + ex.getMessage());
			} finally {
				getTopLevelAncestor().setCursor(oldCursor);
			}
		}
	});
}