private DescriptionBasedDiff( JCCompilationUnit compilationUnit, boolean ignoreOverlappingFixes, ImportOrganizer importOrganizer) { this.compilationUnit = checkNotNull(compilationUnit); URI sourceFileUri = compilationUnit.getSourceFile().toUri(); this.sourcePath = (sourceFileUri.isAbsolute() && Objects.equals(sourceFileUri.getScheme(), "file")) ? Paths.get(sourceFileUri).toAbsolutePath().toString() : sourceFileUri.getPath(); this.ignoreOverlappingFixes = ignoreOverlappingFixes; this.importsToAdd = new LinkedHashSet<>(); this.importsToRemove = new LinkedHashSet<>(); this.endPositions = compilationUnit.endPositions; this.importOrganizer = importOrganizer; }
@Override public String getRange(JCCompilationUnit unit) { try { CharSequence sequence = unit.getSourceFile().getCharContent(true); JCTree firstStatement = statements.get(0); JCTree lastStatement = Iterables.getLast(statements); return sequence .subSequence( firstStatement.getStartPosition(), lastStatement.getEndPosition(unit.endPositions)) .toString(); } catch (IOException e) { throw new RuntimeException(e); } } }
public String getRange(JCCompilationUnit unit) { try { CharSequence sequence = unit.getSourceFile().getCharContent(true); return sequence .subSequence(location.getStartPosition(), location.getEndPosition(unit.endPositions)) .toString(); } catch (IOException e) { throw new RuntimeException(e); } } }
str = str.substring(0, Math.min(str.length() - 1, 30)); System.err.print(" [" + stack.get(i).getClass().getSimpleName() + "] " + str + (str.length() < intialLength ? "..." : "") + " (" + compilationUnit.getSourceFile().getName() + ":"); if (diagnosticSource == null) {
JCCompilationUnit target = typesToCompilationUnits.get(classdecl.extending.type.tsym); if (target != null && getGraph().contains(target)) { logger.debug("adding inheritance dependency: " + currentTopLevel.getSourceFile() + " -> " + target.getSourceFile()); getGraph().addEdge(target, currentTopLevel);
/** * Gets the Java source code for the given compilation unit. */ protected String[] getGetSource(JCCompilationUnit compilationUnit) { if (sourceCache != null && sourceCache.getKey().equals(compilationUnit.getSourceFile().getName())) { return sourceCache.getValue(); } else { try { sourceCache = new AbstractMap.SimpleEntry<>(compilationUnit.getSourceFile().getName(), FileUtils.readFileToString(new File(compilationUnit.getSourceFile().getName())).split("\\n")); } catch (Exception e) { return null; } return sourceCache.getValue(); } }
/** * Adds an exported element for a module. */ public void addExportedElement(String moduleName, Symbol exportedElement, JCCompilationUnit compilationUnit) { List<Symbol> exportedNamesForModule = exportedElements.get(moduleName); if (exportedNamesForModule == null) { exportedNamesForModule = new ArrayList<Symbol>(); exportedElements.put(moduleName, exportedNamesForModule); } exportedNames.put(exportedElement, getRootRelativeName( useModules ? getImportedElements(compilationUnit.getSourceFile().getName()) : null, exportedElement)); exportedNamesForModule.add(exportedElement); }
private void acceptReferences(JCTree tree) { ReferenceGrabber refGrabber = new ReferenceGrabber(); refGrabber.scan(tree); for (TypeSymbol type : refGrabber.referencedTypes) { if (!context.useModules || currentTopLevel.packge.equals(type.packge())) { JCCompilationUnit target = typesToCompilationUnits.get(type); if (target != null && !currentTopLevel.equals(target) && getGraph().contains(target)) { logger.debug("adding static initializer dependency: " + currentTopLevel.getSourceFile() + " -> " + target.getSourceFile()); getGraph().addEdge(target, currentTopLevel); } } } }
private boolean isModuleDefsFile(JCCompilationUnit cu) { return cu.getSourceFile().getName().equals("module_defs.java") || cu.getSourceFile().getName().endsWith("/module_defs.java"); }
public String getRootRelativeName(Symbol symbol, boolean useJavaNames) { return context.getRootRelativeName( context.useModules ? context.getImportedElements(compilationUnit.getSourceFile().getName()) : null, symbol, useJavaNames); }
public String getRootRelativeName(Symbol symbol) { return context.getRootRelativeName( context.useModules ? context.getImportedElements(compilationUnit.getSourceFile().getName()) : null, symbol); }
private void initSourceFileJavaPaths(SourceFile file, JCCompilationUnit cu) { String[] s = cu.getSourceFile().getName().split(File.separator.equals("\\") ? "\\\\" : File.separator); String cuName = s[s.length - 1]; s = cuName.split("\\."); cuName = s[0]; String javaSourceFileRelativeFullName = (cu.packge.getQualifiedName().toString().replace(".", File.separator) + File.separator + cuName + ".java"); file.javaSourceDirRelativeFile = new File(javaSourceFileRelativeFullName); file.javaSourceDir = new File(cu.getSourceFile().getName().substring(0, cu.getSourceFile().getName().length() - javaSourceFileRelativeFullName.length())); }
private void generateModuleDefs(JCCompilationUnit moduleDefs) throws IOException { StringBuilder out = new StringBuilder(); for (String line : FileUtils.readLines(new File(moduleDefs.getSourceFile().getName()))) { if (line.startsWith("///")) { out.append(line.substring(3)); } } FileUtils.write(new File(tsOutputDir, "module_defs.d.ts"), out, false); }
protected static Pretty pretty(Context context, final Writer writer) { final JCCompilationUnit unit = context.get(JCCompilationUnit.class); try { final String unitContents = unit.getSourceFile().getCharContent(false).toString(); return new Pretty(writer, true) {
JavaFileObject modifiedFile = compilationUnit.getSourceFile(); BasicJavacTask javacTask = (BasicJavacTask) state.context.get(JavacTask.class); if (javacTask == null) {
JavaFileObject originalSource = log.useSource(compilation.getSourceFile()); try { if (shouldExcludeSourceFile(compilation)) {
Iterables.filter( Iterables.filter(trees, JCCompilationUnit.class), compilationUnit -> compilationUnit.getSourceFile() == input)); Iterable<Diagnostic<? extends JavaFileObject>> errorDiagnostics = Iterables.filter(
@Override public DescriptionListener getDescriptionListener(Log log, JCCompilationUnit compilation) { URI sourceFile = compilation.getSourceFile().toUri(); DelegatingDescriptionListener delegate = new DelegatingDescriptionListener( descriptionsFactory.getDescriptionListener(log, compilation), DescriptionBasedDiff.createIgnoringOverlaps(compilation, importOrganizer)); foundSources.put(sourceFile, delegate); return delegate; }
static Factory providerForRefactoring(Context context) { return (log, compilation) -> new JavacErrorDescriptionListener( log, compilation.endPositions, compilation.getSourceFile(), context, true); } }
static Factory provider(Context context) { return (log, compilation) -> new JavacErrorDescriptionListener( log, compilation.endPositions, compilation.getSourceFile(), context, false); }