@Override public Types getTypes() { return classParser.getContext().getTypes(); }
/** * Build the final ParsingContext with the provided configuration. * * @return the @{link ParsingContext} instance */ public ParsingContext build() { return new ParsingContext(this); }
@Override public void on(ArchiveAdapter.Entry entry, InputStream is) throws IOException { if (logger.isLoggable(Level.FINER)) { logger.log(Level.FINER, "Parsing class " + entry.name); } try { ClassReader cr = new ClassReader(is); cr.accept(context.getClassVisitor(uri, entry.name, true), ClassReader.SKIP_DEBUG); } catch (Throwable e) { logger.log(Level.SEVERE, "Exception while visiting " + entry.name + " of size " + entry.size, e); } } },
/** * Given the set of annotations that comprise Hk2, as well as the provided classpath / files to * introspect, return the set of URIs that actually reference something of "significant value" * pertaining to habitat creation. */ private Set<URI> getSignificantURIReferences() { LinkedHashSet<URI> result = new LinkedHashSet<URI>(); Types types = context.getTypes(); for (String annotation : context.getConfig().getTypesOfInterest()) { AnnotationType atype = (AnnotationType) types.getBy(annotation); if (null != atype) { Collection<AnnotatedElement> coll = atype.allAnnotatedTypes(); for (AnnotatedElement ae : coll) { Type type = types.getBy(ae.getName()); if (null != type) { for (URI uri : type.getDefiningURIs()) { try { result.add(new File(uri).getCanonicalFile().toURI()); } catch (IOException e) { throw new RuntimeException(e); } } } } } } return Collections.unmodifiableSet(result); }
public ModelClassVisitor(ParsingContext ctx, URI definingURI, String entryName, boolean isApplicationClass) { super(Opcodes.ASM6); this.ctx = ctx; this.definingURI = definingURI; this.entryName = entryName; typeBuilder = ctx.getTypeBuilder(definingURI); classContext = new ClassVisitingContext(); visitingContext = new MemberVisitingContext(ctx.getConfig().modelUnAnnotatedMembers()); fieldVisitor = new ModelFieldVisitor(visitingContext); methodVisitor = new ModelMethodVisitor(visitingContext); annotationVisitor = new ModelAnnotationVisitor(); defaultAnnotationVisitor = new ModelDefaultAnnotationVisitor(methodVisitor.getContext()); this.isApplicationClass = isApplicationClass; }
@Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { desc = unwrap(desc); final AnnotationTypeImpl at = (AnnotationTypeImpl) typeBuilder.getType(Opcodes.ACC_ANNOTATION, desc, null); final AnnotationModelImpl am = new AnnotationModelImpl(type, at); // reverse index at.getAnnotatedElements().add(type); // forward index type.addAnnotation(am); if (ctx.getConfig().getAnnotationsOfInterest().contains(desc)) { logger.log(Level.FINER, "Inspecting fields of {0}", type.getName()); deepVisit =true; } annotationVisitor.getContext().annotation=am; return annotationVisitor; }
/** * Given the set of annotations that comprise Hk2, as well as the provided classpath / files to * introspect, return the set of URIs that actually reference something of "significant value" * pertaining to habitat creation. */ private Set<URI> getSignificantURIReferences() { LinkedHashSet<URI> result = new LinkedHashSet<URI>(); Types types = context.getTypes(); for (String annotation : context.getConfig().getTypesOfInterest()) { AnnotationType atype = (AnnotationType) types.getBy(annotation); if (null != atype) { Collection<AnnotatedElement> coll = atype.allAnnotatedTypes(); for (AnnotatedElement ae : coll) { Type type = types.getBy(ae.getName()); if (null != type) { for (URI uri : type.getDefiningURIs()) { try { result.add(new File(uri).getCanonicalFile().toURI()); } catch (IOException e) { throw new RuntimeException(e); } } } } } } return Collections.unmodifiableSet(result); }
public ModelClassVisitor(ParsingContext ctx, URI definingURI, String entryName, boolean isApplicationClass) { super(Opcodes.ASM6); this.ctx = ctx; this.definingURI = definingURI; this.entryName = entryName; typeBuilder = ctx.getTypeBuilder(definingURI); classContext = new ClassVisitingContext(); visitingContext = new MemberVisitingContext(ctx.getConfig().modelUnAnnotatedMembers()); fieldVisitor = new ModelFieldVisitor(visitingContext); methodVisitor = new ModelMethodVisitor(visitingContext); annotationVisitor = new ModelAnnotationVisitor(); defaultAnnotationVisitor = new ModelDefaultAnnotationVisitor(methodVisitor.getContext()); this.isApplicationClass = isApplicationClass; }
@Override public AnnotationVisitor visitAnnotation(String desc, boolean visible) { desc = unwrap(desc); final AnnotationTypeImpl at = (AnnotationTypeImpl) typeBuilder.getType(Opcodes.ACC_ANNOTATION, desc, null); final AnnotationModelImpl am = new AnnotationModelImpl(type, at); // reverse index at.getAnnotatedElements().add(type); // forward index type.addAnnotation(am); if (ctx.getConfig().getAnnotationsOfInterest().contains(desc)) { logger.log(Level.FINER, "Inspecting fields of {0}", type.getName()); deepVisit =true; } annotationVisitor.getContext().annotation=am; return annotationVisitor; }
@Override public Types getTypes() { return classParser.getContext().getTypes(); } }
type = ctx.getTypeBuilder(classDefURI).getType(access, className, parent); type.setApplicationClass(isApplicationClass); type.getProxy().visited(); type.addDefiningURI(classDefURI); deepVisit = ctx.getConfig().getAnnotationsOfInterest().isEmpty();
/** * Build the final ParsingContext with the provided configuration. * * @return the @{link ParsingContext} instance */ public ParsingContext build() { return new ParsingContext(this); }
@Override public void on(ArchiveAdapter.Entry entry, InputStream is) throws IOException { if (logger.isLoggable(Level.FINER)) { logger.log(Level.FINER, "Parsing class " + entry.name); } try { ClassReader cr = new ClassReader(is); cr.accept(context.getClassVisitor(uri, entry.name, true), ClassReader.SKIP_DEBUG); } catch (Throwable e) { logger.log(Level.SEVERE, "Exception while visiting " + entry.name + " of size " + entry.size, e); } } },
@SuppressWarnings("unchecked") public InhabitantIntrospectionScanner(ParsingContext context) { types = context.getTypes(); AnnotationType am = types.getBy(AnnotationType.class, InhabitantAnnotation.class.getName()); if (am==null) { inhabitantAnnotations = Collections.EMPTY_LIST.iterator(); } else { Collection<AnnotatedElement> ccc = am.allAnnotatedTypes(); inhabitantAnnotations = ccc.iterator(); } fetch(); }
type = ctx.getTypeBuilder(classDefURI).getType(access, className, parent); type.setApplicationClass(isApplicationClass); type.getProxy().visited(); type.addDefiningURI(classDefURI); deepVisit = ctx.getConfig().getAnnotationsOfInterest().isEmpty();
//Define log4j properties Properties p = new Properties(); p.put("type", "log4j"); p.put("pattern", "TIMESTAMP LEVEL [THREAD] MESSAGE"); p.put("dateFormat", "yyyy-MM-dd HH:mm:ss,SSS"); Log4jPatternMultilineLogParser logParser = new Log4jPatternMultilineLogParser(); LogImporterUsingParser importerUsingParser = new LogImporterUsingParser(logParser); importerUsingParser.init(p); // ParsingContext context = new ParsingContext(); //Create log collector, it capture all parsed log events ProxyLogDataCollector dataCollector = new ProxyLogDataCollector(); //Create input stream from file InputStream in = new FileInputStream("log4j/log4j.txt"); //parse log file importerUsingParser.importLogs(in, dataCollector, context);
cr.accept(ctx.getClassVisitor(url.toURI(), className), ClassReader.SKIP_DEBUG);
@SuppressWarnings("unchecked") public InhabitantIntrospectionScanner(ParsingContext context) { types = context.getTypes(); AnnotationType am = types.getBy(AnnotationType.class, InhabitantAnnotation.class.getName()); if (am==null) { inhabitantAnnotations = Collections.EMPTY_LIST.iterator(); } else { Collection<AnnotatedElement> ccc = am.allAnnotatedTypes(); inhabitantAnnotations = ccc.iterator(); } fetch(); }
cr.accept(ctx.getClassVisitor(url.toURI(), className), ClassReader.SKIP_DEBUG);
logger ); saveResult(uri, context.getTypes());