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); }
private List<String> getAllImports(Inliner inliner) { List<String> allImports = new ArrayList<>(inliner.getImportsToAdd()); if (inliner.getContext() != null && inliner.getContext().get(JCCompilationUnit.class) != null) { for (JCImport jcImport : inliner.getContext().get(JCCompilationUnit.class).getImports()) { JCFieldAccess qualified = (JCFieldAccess) jcImport.getQualifiedIdentifier(); allImports.add(qualified.toString()); } } return allImports; }
private static String getFullyQualifiedName(JCCompilationUnit tree) { Iterator<JCClassDecl> types = Iterables.filter(tree.getTypeDecls(), JCClassDecl.class).iterator(); if (types.hasNext()) { return Iterators.getOnlyElement(types).sym.getQualifiedName().toString(); } // Fallback: if no class is declared, then assume we're looking at a `package-info.java`. return tree.getPackage().packge.package_info.toString(); }
additionalDiffs.addAll(CasualDiff.diff(getContext(), diffContext, getTreeUtilities(), diffContext.origUnit.getImports(), ncut.getImports(), userInfo, tree2Tag, tree2Doc, tag2Span, oldTrees));
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 originalSource = log.useSource(compilation.getSourceFile()); try { if (shouldExcludeSourceFile(compilation.getSourceFile())) { return;
JCClassDecl classDecl = (JCClassDecl) compilationUnit.getTypeDecls().get(0); JavacTreeMaker treeMaker = annotationNode.getTreeMaker();
JavaFileObject modifiedFile = compilationUnit.getSourceFile(); BasicJavacTask javacTask = (BasicJavacTask) state.context.get(JavacTask.class); if (javacTask == null) {
TokenHierarchy<?> tokens = unit.getSourceFile() instanceof AbstractSourceFileObject ? ((AbstractSourceFileObject) unit.getSourceFile()).getTokenHierarchy() : TokenHierarchy.create(unit.getSourceFile().getCharContent(true), JavaTokenId.language()); TokenSequence<JavaTokenId> seq = tokens.tokenSequence(JavaTokenId.language()); TreePath tp = TreePath.getPath(cut, original);
String path = ASTHelpers.getFileNameFromUri(compilationUnit.getSourceFile().toUri()); if (Pattern.matches(restriction.allowedOnPath(), path)) { return Description.NO_MATCH;
JavaFileObject sourceFile = env.toplevel.getSourceFile(); if( sourceFile instanceof GeneratedJavaStubFileObject )
compilationUnit.accept(new TreeTranslator() {
/** * Parse the specified files returning a list of abstract syntax trees. * * @throws java.io.IOException TODO * @return a list of abstract syntax trees */ public Iterable<? extends CompilationUnitTree> parse() throws IOException { try { prepareCompiler(); List<JCCompilationUnit> units = compiler.parseFiles(fileObjects); for (JCCompilationUnit unit: units) { JavaFileObject file = unit.getSourceFile(); if (notYetEntered.containsKey(file)) notYetEntered.put(file, unit); } return units; } finally { parsed = true; if (compiler != null && compiler.log != null) compiler.log.flush(); } }
public void printImportsBlock(java.util.List<? extends JCTree> imports, boolean maybeAppendNewLine) { boolean hasImports = !imports.isEmpty(); CodeStyle.ImportGroups importGroups = null; if (hasImports) { blankLines(Math.max(cs.getBlankLinesBeforeImports(), diffContext.origUnit.getPackageName() != null ? cs.getBlankLinesAfterPackage() : 0)); if (cs.separateImportGroups()) importGroups = cs.getImportGroups(); } int lastGroup = -1; for (JCTree importStat : imports) { if (importGroups != null) { Name name = fullName(((JCImport)importStat).qualid); int group = name != null ? importGroups.getGroupId(name.toString(), ((JCImport)importStat).staticImport) : -1; if (lastGroup >= 0 && lastGroup != group) blankline(); lastGroup = group; } printStat(importStat); newline(); } if (hasImports && maybeAppendNewLine) { blankLines(cs.getBlankLinesAfterImports()); } }
/** * Parse the specified files returning a list of abstract syntax trees. * * @throws java.io.IOException TODO * @return a list of abstract syntax trees */ public Iterable<? extends CompilationUnitTree> parse() throws IOException { try { prepareCompiler(); List<JCCompilationUnit> units = compiler.parseFiles(fileObjects); for (JCCompilationUnit unit: units) { JavaFileObject file = unit.getSourceFile(); if (notYetEntered.containsKey(file)) notYetEntered.put(file, unit); } return units; } finally { parsed = true; if (compiler != null && compiler.log != null) compiler.log.flush(); } }
/** * Create given tree node at current position. * @param defs a list of ClassDef, Import, and Skip */ public JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations, JCExpression pid, List<JCTree> defs) { assert packageAnnotations != null; for (JCTree node : defs) assert node instanceof JCClassDecl || node instanceof JCImport || node instanceof JCSkip || node instanceof JCErroneous || (node instanceof JCExpressionStatement && ((JCExpressionStatement)node).expr instanceof JCErroneous) : node.getClass().getSimpleName(); JCCompilationUnit tree = new JCCompilationUnit(packageAnnotations, pid, defs, null, null, null, null); tree.pos = pos; return tree; }
/** * Parse the specified files returning a list of abstract syntax trees. * * @throws java.io.IOException TODO * @return a list of abstract syntax trees */ public Iterable<? extends CompilationUnitTree> parse() throws IOException { try { prepareCompiler(); List<JCCompilationUnit> units = compiler.parseFiles(fileObjects); for (JCCompilationUnit unit: units) { JavaFileObject file = unit.getSourceFile(); if (notYetEntered.containsKey(file)) notYetEntered.put(file, unit); } return units; } finally { parsed = true; if (compiler != null && compiler.log != null) compiler.log.flush(); } }
/** * Parse the specified files returning a list of abstract syntax trees. * * @throws java.io.IOException TODO * @return a list of abstract syntax trees */ public Iterable<? extends CompilationUnitTree> parse() throws IOException { try { prepareCompiler(); List<JCCompilationUnit> units = compiler.parseFiles(fileObjects); for (JCCompilationUnit unit: units) { JavaFileObject file = unit.getSourceFile(); if (notYetEntered.containsKey(file)) notYetEntered.put(file, unit); } return units; } finally { parsed = true; if (compiler != null && compiler.log != null) compiler.log.flush(); } }
/** * Create given tree node at current position. * @param defs a list of ClassDef, Import, and Skip */ public JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations, JCExpression pid, List<JCTree> defs) { Assert.checkNonNull(packageAnnotations); for (JCTree node : defs) Assert.check(node instanceof JCClassDecl || node instanceof JCImport || node instanceof JCSkip || node instanceof JCErroneous || (node instanceof JCExpressionStatement && ((JCExpressionStatement)node).expr instanceof JCErroneous), node.getClass().getSimpleName()); JCCompilationUnit tree = new JCCompilationUnit(packageAnnotations, pid, defs, null, null, null, null); tree.pos = pos; return tree; }
/** * Create given tree node at current position. * @param defs a list of ClassDef, Import, and Skip */ public JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations, JCExpression pid, List<JCTree> defs) { assert packageAnnotations != null; for (JCTree node : defs) assert node instanceof JCClassDecl || node instanceof JCImport || node instanceof JCSkip || node instanceof JCErroneous || (node instanceof JCExpressionStatement && ((JCExpressionStatement)node).expr instanceof JCErroneous) : node.getClass().getSimpleName(); JCCompilationUnit tree = new JCCompilationUnit(packageAnnotations, pid, defs, null, null, null, null); tree.pos = pos; return tree; }