javax.tools.Diagnostic.Kind Java Examples
The following examples show how to use
javax.tools.Diagnostic.Kind.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NodeIntrinsicVerifier.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private ExecutableElement findConstructor(TypeElement nodeClass, TypeMirror[] signature, ExecutableElement intrinsicMethod, AnnotationMirror intrinsicAnnotation) { List<ExecutableElement> constructors = ElementFilter.constructorsIn(nodeClass.getEnclosedElements()); List<String> failureReasons = new ArrayList<>(); for (ExecutableElement constructor : constructors) { String failureReason = matchSignature(0, constructor, signature); if (failureReason == null) { // found return constructor; } failureReasons.add(failureReason); } // not found if (failureReasons.isEmpty()) { env.getMessager().printMessage(Kind.ERROR, "Could not find matching constructor for node intrinsic.", intrinsicMethod, intrinsicAnnotation); } else { for (String reason : failureReasons) { env.getMessager().printMessage(Kind.ERROR, reason, intrinsicMethod, intrinsicAnnotation); } } return null; }
Example #2
Source File: ShellProcessor.java From karaf-boot with Apache License 2.0 | 6 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { Set<String> packages = new TreeSet<>(); for (Element elem : roundEnv.getElementsAnnotatedWith(Service.class)) { packages.add(elem.getEnclosingElement().toString()); } if (!packages.isEmpty()) { if (!hasRun) { hasRun = true; // Add the Karaf embedded package try (PrintWriter w = appendResource("META-INF/org.apache.karaf.boot.bnd")) { w.println("Karaf-Commands: " + String.join(",", packages)); } catch (Exception e) { processingEnv.getMessager().printMessage(Kind.ERROR, "Error writing to META-INF/org.apache.karaf.boot.bnd: " + e.getMessage()); } } } return true; }
Example #3
Source File: WatchPanel.java From netbeans with Apache License 2.0 | 6 votes |
@Override public TypeMirror getTypeMirror(TreePath arg0) { Tree tree = arg0.getLeaf(); if (tree.getKind() == Tree.Kind.IDENTIFIER) { Map<String, ObjectVariable> map = null; try { // [TODO] add JPDADebuggerImpl.getAllLabels() to API Method method = debugger.getClass().getMethod("getAllLabels"); // NOI18N map = (Map<String, ObjectVariable>) method.invoke(debugger); } catch (Exception ex) { Exceptions.printStackTrace(ex); } if (map != null) { String name = ((IdentifierTree)tree).getName().toString(); ObjectVariable var = map.get(name); if (var != null) { Elements elements = controller.getElements(); TypeElement typeElem = elements.getTypeElement(var.getClassType().getName()); if (typeElem != null) { return typeElem.asType(); } } } } return trees.getTypeMirror(arg0); }
Example #4
Source File: MixinObfuscationProcessorTargets.java From Mixin with MIT License | 6 votes |
/** * Searches for {@link Invoker} annotations and registers them with their * parent mixins */ private void processInvokers(RoundEnvironment roundEnv) { for (Element elem : roundEnv.getElementsAnnotatedWith(Invoker.class)) { Element parent = elem.getEnclosingElement(); if (!(parent instanceof TypeElement)) { this.mixins.printMessage(Kind.ERROR, "Unexpected parent with type " + TypeUtils.getElementType(parent), elem); continue; } if (elem.getKind() == ElementKind.METHOD) { this.mixins.registerInvoker((TypeElement)parent, (ExecutableElement)elem); } else { this.mixins.printMessage(Kind.ERROR, "Element is not a method", elem); } } }
Example #5
Source File: AssociationReader.java From droitatedDB with Apache License 2.0 | 6 votes |
private String getUsedType(final VariableElement association, final String fieldType, final boolean isCollectionType) { if (!isCollectionType) { if (entityNames.contains(fieldType)) { return fieldType; } else { messager.printMessage(Kind.ERROR, "The @Relationship has to be another @Entity or Collection of another @Entity", association); return ""; } } else { Matcher matcher = Pattern.compile("<(.*?)>").matcher(fieldType); if (matcher.find()) { String type = matcher.group(1); if (!entityNames.contains(type)) { messager.printMessage(Kind.ERROR, "The collection type has to be an @Entity", association); return ""; } return type; } else { messager.printMessage(Kind.ERROR, "No raw type is allowed when using @Relationship on a Collection", association); return ""; } } }
Example #6
Source File: AnnotatedMixinElementHandler.java From Mixin with MIT License | 6 votes |
private void validateMethodVisibility(ExecutableElement method, AnnotationHandle annotation, String type, TypeHandle target, MethodHandle targetMethod) { Visibility visTarget = targetMethod.getVisibility(); if (visTarget == null) { return; } Visibility visMethod = TypeUtils.getVisibility(method); String visibility = "visibility of " + visTarget + " method in " + target; if (visTarget.ordinal() > visMethod.ordinal()) { this.printMessage(Kind.WARNING, visMethod + " " + type + " method cannot reduce " + visibility, method, annotation, SuppressedBy.VISIBILITY); } else if (visTarget == Visibility.PRIVATE && visMethod.ordinal() > visTarget.ordinal()) { this.printMessage(Kind.WARNING, visMethod + " " + type + " method will upgrade " + visibility, method, annotation, SuppressedBy.VISIBILITY); } }
Example #7
Source File: AbstractAnnotationProcessorTest.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 6 votes |
protected void checkValidCompilation(Class<?>... compilationUnits) { assert (compilationUnits != null); String[] compilationUnitPaths = new String[compilationUnits.length]; for (int i = 0; i < compilationUnitPaths.length; i++) { assert (compilationUnits[i] != null); compilationUnitPaths[i] = toResourcePath(compilationUnits[i]); } List<Diagnostic<? extends JavaFileObject>> diagnostics = new ArrayList<Diagnostic<? extends JavaFileObject>>(); Assert.assertTrue(compileTestCase(compilationUnitPaths, getDefaultArguments(), diagnostics)); for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) { assertFalse(diagnostic.getMessage(Locale.ENGLISH), diagnostic.getKind().equals(Kind.ERROR)); } }
Example #8
Source File: ResolveHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public VerboseCandidateSubdiagProcessor(boolean mostSpecific, Phase phase, boolean success) { super(Kind.OTHER, "compiler.misc.applicable.method.found", "compiler.misc.applicable.method.found.1", "compiler.misc.not.applicable.method.found"); this.mostSpecific = mostSpecific; this.phase = phase; this.success = success; }
Example #9
Source File: JsonDoclet.java From ghidra with Apache License 2.0 | 5 votes |
@Override public Set<? extends Option> getSupportedOptions() { Option[] options = { new Option() { @Override public int getArgumentCount() { return 1; } @Override public String getDescription() { return "the destination directory"; } @Override public Kind getKind() { return Option.Kind.STANDARD; } @Override public List<String> getNames() { return Arrays.asList("-d"); } @Override public String getParameters() { return "directory"; } @Override public boolean process(String option, List<String> arguments) { destDir = new File(arguments.get(0)); return true; } } }; return new HashSet<>(Arrays.asList(options)); }
Example #10
Source File: BasicPropertyGenerator.java From squidb with Apache License 2.0 | 5 votes |
/** * @return the full column definition for this Property as a SQL string */ protected String getColumnDefinition() { StringBuilder toReturn = new StringBuilder(); String constraints = extras != null ? extras.constraints() : ColumnSpec.DEFAULT_NONE; if (!ColumnSpec.DEFAULT_NONE.equals(constraints)) { toReturn.append(constraints); } if (!ColumnSpec.DEFAULT_NONE.equals(getColumnDefault())) { String columnDefaultValue = getColumnDefinitionDefaultValue(); if (!toReturn.toString().toUpperCase().contains("DEFAULT")) { toReturn.append(" DEFAULT ").append(columnDefaultValue); } else { utils.getMessager().printMessage(Kind.WARNING, "Duplicate default value definitions", field); } } if (field != null && field.getAnnotation(PrimaryKey.class) != null) { PrimaryKey primaryKeyAnnotation = field.getAnnotation(PrimaryKey.class); if (!toReturn.toString().toUpperCase().contains("PRIMARY KEY")) { toReturn.append(" PRIMARY KEY "); if (TypeConstants.isIntegerType(getTypeForAccessors()) && primaryKeyAnnotation.autoincrement()) { toReturn.append("AUTOINCREMENT"); } } else { utils.getMessager().printMessage(Kind.WARNING, "Duplicate primary key definition in column constraints." + " Use the @PrimaryKey annotation instead of declaring the constraint in ColumnSpec."); } } String toReturnString = toReturn.toString().trim(); if (!AptUtils.isEmpty(toReturnString)) { return "\"" + toReturnString + "\""; } return null; }
Example #11
Source File: AnnotatedMixins.java From Mixin with MIT License | 5 votes |
/** * Print a message to the AP messager */ @Override public void printMessage(Kind kind, CharSequence msg, Element element, SuppressedBy suppressedBy) { if (kind != Kind.WARNING || !AnnotatedMixins.shouldSuppress(element, suppressedBy)) { this.processingEnv.getMessager().printMessage(kind, msg, element); } }
Example #12
Source File: CompilationInfoImpl.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void report(Diagnostic<? extends JavaFileObject> message) { if (partialReparseErrors != null) { if (this.jfo != null && this.jfo == message.getSource()) { partialReparseErrors.add(message); if (message.getKind() == Kind.ERROR) { partialReparseRealErrors = true; } } } else { Diagnostics errors = getErrors(message.getSource()); errors.add((int) message.getPosition(), message); } }
Example #13
Source File: AnnotationProcessor.java From EasyMPermission with MIT License | 5 votes |
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (!delayedWarnings.isEmpty()) { Set<? extends Element> rootElements = roundEnv.getRootElements(); if (!rootElements.isEmpty()) { Element firstRoot = rootElements.iterator().next(); for (String warning : delayedWarnings) processingEnv.getMessager().printMessage(Kind.WARNING, warning, firstRoot); delayedWarnings.clear(); } } for (ProcessorDescriptor proc : active) proc.process(annotations, roundEnv); return false; }
Example #14
Source File: Checker.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void checkAllowsText(DocTree tree) { TagStackItem top = tagStack.peek(); if (top != null && top.tree.getKind() == DocTree.Kind.START_ELEMENT && !top.tag.acceptsText()) { if (top.flags.add(Flag.REPORTED_BAD_INLINE)) { env.messages.error(HTML, tree, "dc.text.not.allowed", ((StartElementTree) top.tree).getName()); } } }
Example #15
Source File: Compilation.java From compile-testing with Apache License 2.0 | 5 votes |
/** * Source files generated during compilation. * * @throws IllegalStateException for {@linkplain #status() failed compilations}, since the state * of the generated files is undefined in that case */ public ImmutableList<JavaFileObject> generatedSourceFiles() { return generatedFiles() .stream() .filter(generatedFile -> generatedFile.getKind().equals(JavaFileObject.Kind.SOURCE)) .collect(toImmutableList()); }
Example #16
Source File: GraphNodeProcessor.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void message(Kind kind, Element element, String format, Object... args) { if (scope != null && !isEnclosedIn(element, scope)) { // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=428357#c1 List<Element> elementHierarchy = getElementHierarchy(element); reverse(elementHierarchy); String loc = elementHierarchy.stream().filter(e -> e.getKind() != ElementKind.PACKAGE).map(Object::toString).collect(Collectors.joining(".")); processingEnv.getMessager().printMessage(kind, String.format(loc + ": " + format, args), scope); } else { processingEnv.getMessager().printMessage(kind, String.format(format, args), element); } }
Example #17
Source File: ShowTypePlugin.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public void finished(TaskEvent taskEvent) { if (taskEvent.getKind().equals(TaskEvent.Kind.ANALYZE)) { CompilationUnitTree compilationUnit = taskEvent.getCompilationUnit(); visitor.scan(compilationUnit, null); } }
Example #18
Source File: Log.java From Akatsuki with Apache License 2.0 | 5 votes |
private static void print(ProcessorContext context, String message, Element element, LoggingLevel level) { // if we don't have config yet, print everything LoggingLevel loggingLevel = context.config() != null ? context.config().loggingLevel() : null; if (loggingLevel == null || level.ordinal() <= loggingLevel.ordinal()) { String msg = level.name() + ":" + message; if (element == null) { context.messager().printMessage(Kind.OTHER, msg); } else { context.messager().printMessage(Kind.OTHER, msg, element); } } }
Example #19
Source File: ResolveHarness.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { fm.setLocation(SOURCE_PATH, Arrays.asList(new File(System.getProperty("test.src"), "tests"))); for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) { new ResolveHarness(jfo).check(); } if (nerrors > 0) { throw new AssertionError("Errors were found"); } }
Example #20
Source File: CompilerJavacForked.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
public void addMessage(String path, int line, int column, String message, Kind kind) { try { writer.write('M'); writer.write(URLEncoder.encode(path, ENCODING)); writer.write(' '); writer.write(Integer.toString(line)); writer.write(' '); writer.write(Integer.toString(column)); writer.write(' '); switch (kind) { case ERROR: writer.write('E'); break; case NOTE: writer.write('I'); break; default: writer.write('W'); break; } writer.write(' '); writer.write(URLEncoder.encode(message, ENCODING)); writer.write(EOL); } catch (IOException e) { handleException(e); } }
Example #21
Source File: Messager.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public void print(Kind kind, DocTreePath path, String msg) { switch (kind) { case ERROR: printError(path, msg); return; case WARNING: case MANDATORY_WARNING: printWarning(path, msg); return; default: printWarning(path, msg); return; } }
Example #22
Source File: MethodSubstitutionVerifier.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private TypeMirror[] originalSignature(TypeElement originalType, ExecutableElement method, AnnotationMirror annotation, boolean isStatic) { AnnotationValue signatureValue = findAnnotationValue(annotation, ORIGINAL_SIGNATURE); String signatureString = resolveAnnotationValue(String.class, signatureValue); List<TypeMirror> parameters = new ArrayList<>(); if (signatureString.equals(ORIGINAL_SIGNATURE_DEFAULT)) { for (int i = 0; i < method.getParameters().size(); i++) { parameters.add(method.getParameters().get(i).asType()); } if (!isStatic) { if (parameters.isEmpty()) { env.getMessager().printMessage(Kind.ERROR, "Method signature must be a static method with the 'this' object as its first parameter", method, annotation); return null; } else { TypeMirror thisParam = parameters.remove(0); if (!isSubtype(originalType.asType(), thisParam)) { Name thisName = method.getParameters().get(0).getSimpleName(); env.getMessager().printMessage(Kind.ERROR, String.format("The type of %s must assignable from %s", thisName, originalType), method, annotation); } } } parameters.add(0, method.getReturnType()); } else { try { APHotSpotSignature signature = new APHotSpotSignature(signatureString); parameters.add(signature.getReturnType(env)); for (int i = 0; i < signature.getParameterCount(false); i++) { parameters.add(signature.getParameterType(env, i)); } } catch (Exception e) { /* * That's not good practice and should be changed after APHotSpotSignature has * received a cleanup. */ env.getMessager().printMessage(Kind.ERROR, String.format("Parsing the signature failed: %s", e.getMessage() != null ? e.getMessage() : e.toString()), method, annotation, signatureValue); return null; } } return parameters.toArray(new TypeMirror[parameters.size()]); }
Example #23
Source File: ResolveHarness.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { fm.setLocation(SOURCE_PATH, Arrays.asList(new File(System.getProperty("test.src"), "tests"))); for (JavaFileObject jfo : fm.list(SOURCE_PATH, "", Collections.singleton(JavaFileObject.Kind.SOURCE), true)) { new ResolveHarness(jfo).check(); } if (nerrors > 0) { throw new AssertionError("Errors were found"); } }
Example #24
Source File: Util.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private Diagnostic<JavaFileObject> createDiagnostic( final Diagnostic.Kind kind, final String code, final Object... args) { return new Diagnostic<JavaFileObject>() { public String getCode() { return code; } public long getColumnNumber() { return Diagnostic.NOPOS; } public long getEndPosition() { return Diagnostic.NOPOS; } public Kind getKind() { return kind; } public long getLineNumber() { return Diagnostic.NOPOS; } public String getMessage(Locale locale) { if (code.length() == 0) return (String) args[0]; return getText(code, args); // FIXME locale } public long getPosition() { return Diagnostic.NOPOS; } public JavaFileObject getSource() { return null; } public long getStartPosition() { return Diagnostic.NOPOS; } }; }
Example #25
Source File: JavaXToolsCompiler.java From astor with GNU General Public License v2.0 | 5 votes |
private void copyErrors(List<String> errors, DiagnosticCollector<JavaFileObject> diagnostics2) { for (Diagnostic d : diagnostics2.getDiagnostics()) { if (d.getKind() == Kind.ERROR || d.getKind() == Kind.MANDATORY_WARNING) { errors.add(d.toString()); } } }
Example #26
Source File: AnnotatedMixinElementHandlerAccessor.java From Mixin with MIT License | 5 votes |
/** * Register a new accessor * * @param elem accessor element */ public void registerAccessor(AnnotatedElementAccessor elem) { if (elem.getAccessorType() == null) { elem.printMessage(this.ap, Kind.WARNING, "Unsupported accessor type"); return; } String targetName = this.getAccessorTargetName(elem); if (targetName == null) { elem.printMessage(this.ap, Kind.WARNING, "Cannot inflect accessor target name"); return; } elem.setTargetName(targetName); for (TypeHandle target : this.mixin.getTargets()) { try { elem.attach(target); } catch (Exception ex) { elem.printMessage(this.ap, Kind.ERROR, ex.getMessage()); continue; } if (elem.getAccessorType() == AccessorType.OBJECT_FACTORY) { this.registerFactoryForTarget((AnnotatedElementInvoker)elem, target); } else if (elem.getAccessorType() == AccessorType.METHOD_PROXY) { this.registerInvokerForTarget((AnnotatedElementInvoker)elem, target); } else { this.registerAccessorForTarget(elem, target); } } }
Example #27
Source File: Processor.java From immutables with Apache License 2.0 | 5 votes |
@Override public Filer getFiler() { final Filer filer = super.getFiler(); if (incrementalRestrictions) { if (restrictedFiler == null) { restrictedFiler = new ForwardingFiler() { @Override protected Filer delegate() { return filer; } @Override public FileObject createResource( Location location, CharSequence pkg, CharSequence relativeName, Element... originatingElements) throws IOException { String message = String.format("Suppressed writing of resource %s/%s/%s (triggered by enabling -A%s)", location, pkg, relativeName, GRADLE_INCREMENTAL); getMessager().printMessage(Kind.MANDATORY_WARNING, message); throw new FileNotFoundException(message); } }; } return restrictedFiler; } return filer; }
Example #28
Source File: Util.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private Diagnostic<JavaFileObject> createDiagnostic( final Diagnostic.Kind kind, final String code, final Object... args) { return new Diagnostic<JavaFileObject>() { public String getCode() { return code; } public long getColumnNumber() { return Diagnostic.NOPOS; } public long getEndPosition() { return Diagnostic.NOPOS; } public Kind getKind() { return kind; } public long getLineNumber() { return Diagnostic.NOPOS; } public String getMessage(Locale locale) { if (code.length() == 0) return (String) args[0]; return getText(code, args); // FIXME locale } public long getPosition() { return Diagnostic.NOPOS; } public JavaFileObject getSource() { return null; } public long getStartPosition() { return Diagnostic.NOPOS; } }; }
Example #29
Source File: Checker.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public Void visitLink(LinkTree tree, Void ignore) { markEnclosingTag(Flag.HAS_INLINE_TAG); // simulate inline context on tag stack HtmlTag t = (tree.getKind() == DocTree.Kind.LINK) ? HtmlTag.CODE : HtmlTag.SPAN; tagStack.push(new TagStackItem(tree, t)); try { return super.visitLink(tree, ignore); } finally { tagStack.pop(); } }
Example #30
Source File: Checker.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public Void visitLiteral(LiteralTree tree, Void ignore) { markEnclosingTag(Flag.HAS_INLINE_TAG); if (tree.getKind() == DocTree.Kind.CODE) { for (TagStackItem tsi: tagStack) { if (tsi.tag == HtmlTag.CODE) { env.messages.warning(HTML, tree, "dc.tag.code.within.code"); break; } } } return super.visitLiteral(tree, ignore); }