private void reset() { printer.reset(); context = new PrintingContext(); if (env.isAutoImports()) { this.importsContext = new ImportScannerImpl(); } else { this.importsContext = new MinimalImportScanner(); } }
/** * Creates a new code generator visitor. */ public DefaultJavaPrettyPrinter(Environment env) { this.env = env; this.imports = new HashSet<>(); setPrinterTokenWriter(new DefaultTokenWriter(new PrinterHelper(env))); if (env.isAutoImports()) { this.importsContext = new ImportScannerImpl(); } else { this.importsContext = new MinimalImportScanner(); } }
@Deprecated public static Set<CtType> getImport(CtType type) { if (!AmplificationHelper.importByClass.containsKey(type)) { ImportScanner importScanner = new ImportScannerImpl(); try { importScanner.computeImports(type); Set<CtType> set = importScanner.getAllImports() .stream() .map(CtImport::getReference) .filter(Objects::nonNull) .filter(ctElement -> ctElement instanceof CtType) .map(ctElement -> (CtType) ctElement) .collect(Collectors.toSet()); AmplificationHelper.importByClass.put(type, set); } catch (Exception e) { AmplificationHelper.importByClass.put(type, new HashSet<>(0)); } } return AmplificationHelper.importByClass.get(type); }
public void analyzeLib() { String sourcefile=this.faultyClass.getPosition().getFile().getAbsolutePath(); sourcefile = sourcefile.substring(0,sourcefile.lastIndexOf("/")); parseDirSingle(new File(sourcefile)); ImportScanner importContext = new ImportScannerImpl(); importContext.computeImports(this.faultyClass); Collection<CtImport> imports = importContext.getAllImports(); for (CtImport certainimport : imports) { String importedlibname=certainimport.getReference().toString(); if(importedlibname.indexOf(".")==-1) continue; if(certainimport.getImportKind()==CtImportKind.FIELD) { log.info("do not need to consider this case"); importedlibname=""; } else if(certainimport.getImportKind()==CtImportKind.TYPE) { importedlibname=importedlibname; } else if(certainimport.getImportKind()==CtImportKind.METHOD ||certainimport.getImportKind()==CtImportKind.ALL_TYPES) { importedlibname=importedlibname.substring(0,importedlibname.lastIndexOf(".")); } else if (certainimport.getImportKind()==CtImportKind.ALL_STATIC_MEMBERS) { log.info("temporily ignore this case"); importedlibname=""; } parseImportFile(importedlibname); } }