KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > apt > pluggable > core > dispatch > IdeMessagerImpl


1 /*******************************************************************************
2  * Copyright (c) 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * wharley@bea.com - initial API and implementation
10  *
11  *******************************************************************************/

12
13 package org.eclipse.jdt.internal.apt.pluggable.core.dispatch;
14
15 import javax.annotation.processing.Messager;
16 import javax.lang.model.element.AnnotationMirror;
17 import javax.lang.model.element.AnnotationValue;
18 import javax.lang.model.element.Element;
19 import javax.tools.Diagnostic.Kind;
20
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.Status;
23 import org.eclipse.jdt.internal.apt.pluggable.core.Apt6Plugin;
24 import org.eclipse.jdt.internal.compiler.CompilationResult;
25 import org.eclipse.jdt.internal.compiler.apt.dispatch.AptProblem;
26 import org.eclipse.jdt.internal.compiler.apt.dispatch.BatchMessagerImpl;
27
28 /**
29  *
30  * @since 3.3
31  */

32 public class IdeMessagerImpl implements Messager {
33     
34     private final IdeAnnotationProcessorManager _manager;
35     private final IdeProcessingEnvImpl _env;
36
37     public IdeMessagerImpl(IdeAnnotationProcessorManager manager,
38             IdeProcessingEnvImpl env) {
39         _manager = manager;
40         _env = env;
41         // This check is just here so the compiler doesn't complain about unread fields:
42
if (null == _manager || null == _env) {
43             throw new NullPointerException JavaDoc();
44         }
45     }
46
47     /* (non-Javadoc)
48      * @see javax.annotation.processing.Messager#printMessage(javax.tools.Diagnostic.Kind, java.lang.CharSequence)
49      */

50     public void printMessage(Kind kind, CharSequence JavaDoc msg) {
51         printMessage(kind, msg, null, null, null);
52     }
53
54     /* (non-Javadoc)
55      * @see javax.annotation.processing.Messager#printMessage(javax.tools.Diagnostic.Kind, java.lang.CharSequence, javax.lang.model.element.Element)
56      */

57     public void printMessage(Kind kind, CharSequence JavaDoc msg, Element e) {
58         printMessage(kind, msg, e, null, null);
59     }
60
61     /* (non-Javadoc)
62      * @see javax.annotation.processing.Messager#printMessage(javax.tools.Diagnostic.Kind, java.lang.CharSequence, javax.lang.model.element.Element, javax.lang.model.element.AnnotationMirror)
63      */

64     public void printMessage(Kind kind, CharSequence JavaDoc msg, Element e,
65             AnnotationMirror a) {
66         printMessage(kind, msg, e, a, null);
67
68     }
69
70     /* (non-Javadoc)
71      * @see javax.annotation.processing.Messager#printMessage(javax.tools.Diagnostic.Kind, java.lang.CharSequence, javax.lang.model.element.Element, javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationValue)
72      */

73     public void printMessage(Kind kind, CharSequence JavaDoc msg, Element e, AnnotationMirror a,
74             AnnotationValue v) {
75         AptProblem problem = BatchMessagerImpl.createProblem(kind, msg, e);
76         if (kind == Kind.NOTE) {
77             Apt6Plugin.log(new Status(IStatus.INFO, Apt6Plugin.PLUGIN_ID, Apt6Plugin.STATUS_EXCEPTION, problem.getMessage(), null));
78         }
79         else if (null != problem._referenceContext) {
80             CompilationResult result = problem._referenceContext.compilationResult();
81             result.record(problem, problem._referenceContext);
82         }
83         else {
84             // Unknown reference context; e.g., reported against an element not being compiled.
85
// TODO: report against project?? log??
86
Apt6Plugin.log(new Status(IStatus.INFO, Apt6Plugin.PLUGIN_ID, Apt6Plugin.STATUS_EXCEPTION, problem.getMessage(), null));
87         }
88     }
89
90 }
91
Popular Tags