@Override public void handle( AnnotationValues<EqualsAndHashCode> annotation, JCAnnotation ast, JavacNode annotationNode) { deleteAnnotationIfNeccessary(annotationNode, EqualsAndHashCode.class); EqualsAndHashCode ann = annotation.getInstance(); List<String> excludes = List.from(ann.exclude()); List<String> includes = List.from(ann.of()); JavacNode typeNode = annotationNode.up(); checkForBogusFieldNames(typeNode, annotation); Boolean callSuper = ann.callSuper(); if (!annotation.isExplicit("callSuper")) callSuper = null; if (!annotation.isExplicit("exclude")) excludes = null; if (!annotation.isExplicit("of")) includes = null; if (excludes != null && includes != null) { excludes = null; annotation.setWarning( "exclude", "exclude and of are mutually exclusive; the 'exclude' parameter will be ignored."); } FieldAccess fieldAccess = ann.doNotUseGetters() ? FieldAccess.PREFER_FIELD : FieldAccess.GETTER; generateMethods(typeNode, annotationNode, excludes, includes, callSuper, true, fieldAccess); }
public void checkForBogusFieldNames( JavacNode type, AnnotationValues<EqualsAndHashCode> annotation) { if (annotation.isExplicit("exclude")) { for (int i : createListOfNonExistentFields( List.from(annotation.getInstance().exclude()), type, true, true)) { annotation.setWarning( "exclude", "This field does not exist, or would have been excluded anyway.", i); } } if (annotation.isExplicit("of")) { for (int i : createListOfNonExistentFields( List.from(annotation.getInstance().of()), type, false, false)) { annotation.setWarning("of", "This field does not exist.", i); } } }
public static MethodSymbol resolveMethod( VisitorState state, TypeSymbol base, Name name, Iterable<Type> argTypes, Iterable<Type> tyargTypes) { Resolve resolve = Resolve.instance(state.context); Enter enter = Enter.instance(state.context); Log log = Log.instance(state.context); DeferredDiagnosticHandler handler = new DeferredDiagnosticHandler(log); try { return resolve.resolveInternalMethod( /*pos*/ null, enter.getEnv(base), base.type, name, com.sun.tools.javac.util.List.from(argTypes), com.sun.tools.javac.util.List.from(tyargTypes)); } finally { log.popDiagnosticHandler(handler); } }
@Override public void visitApply(JCMethodInvocation node) { if (node.args != null && node.args.size() > 0) { changeNode = (lm, ne) -> { // メソッドの引数を置換 if (node.args.contains(lm)) { Stream<JCExpression> newArgs = node.args.stream().map(a -> (a == lm) ? ne : a); node.args = com.sun.tools.javac.util.List.from(newArgs::iterator); } }; } super.visitApply(node); }
public void print(Writer out) throws IOException { if (!changed) { JavaFileObject sourceFile = compilationUnit.getSourceFile(); if (sourceFile != null) { out.write(sourceFile.getCharContent(true).toString()); return; } } out.write("// Generated by delombok at "); out.write(String.valueOf(new Date())); out.write(System.getProperty("line.separator")); com.sun.tools.javac.util.List<Comment> comments_; if (comments instanceof com.sun.tools.javac.util.List) comments_ = (com.sun.tools.javac.util.List<Comment>) comments; else comments_ = com.sun.tools.javac.util.List.from(comments.toArray(new Comment[0])); compilationUnit.accept(new PrettyCommentsPrinter(out, compilationUnit, comments_)); }
/** * Programmatic interface for main function. * * @param args The command line parameters. */ int compile(String[] args, Context context) { boolean assertionsEnabled = false; assert assertionsEnabled = true; if (!assertionsEnabled) { // Bark.printLines(out, "fatal error: assertions must be enabled when running javac"); // return EXIT_ABNORMAL; } int exitCode = EXIT_OK; JavaCompiler comp = null; try { context.put(Bark.outKey, out); comp = JavaCompiler.instance(context); if (comp == null) return EXIT_SYSERR; java.util.List<String> nameList = new java.util.LinkedList<String>(); nameList.addAll(sourceFileNames); if (options.get("-XclassesAsDecls") != null) nameList.addAll(classFileNames); List<Symbol.ClassSymbol> cs = comp.compile( List.from(nameList.toArray(new String[0])), origOptions, aptCL, providedFactory, productiveFactories, aggregateGenFiles); /* * If there aren't new source files, we shouldn't bother * running javac if there were errors. * * If there are new files, we should try running javac in * case there were typing errors. * */ if (comp.errorCount() != 0 || options.get("-Werror") != null && comp.warningCount() != 0) return EXIT_ERROR; } catch (IOException ex) { ioMessage(ex); return EXIT_SYSERR; } catch (OutOfMemoryError ex) { resourceMessage(ex); return EXIT_SYSERR; } catch (StackOverflowError ex) { resourceMessage(ex); return EXIT_SYSERR; } catch (FatalError ex) { feMessage(ex); return EXIT_SYSERR; } catch (UsageMessageNeededException umne) { help(); return EXIT_CMDERR; // will cause usage message to be printed } catch (AnnotationProcessingError ex) { apMessage(ex); return EXIT_ABNORMAL; } catch (sun.misc.ServiceConfigurationError sce) { sceMessage(sce); return EXIT_ABNORMAL; } catch (Throwable ex) { bugMessage(ex); return EXIT_ABNORMAL; } finally { if (comp != null) { comp.close(); genSourceFileNames.addAll(comp.getSourceFileNames()); genClassFileNames.addAll(comp.getClassFileNames()); } sourceFileNames = new java.util.LinkedList<String>(); classFileNames = new java.util.LinkedList<String>(); } return exitCode; }
private TypeConfiguration(TypeKind... typeKindList) { this.typeKindList = List.from(typeKindList); expressionListStr = asExpressionList(); parameterListStr = asParameterList(); bytecodeSigStr = asBytecodeString(); }