本文整理汇总了Java中javax.tools.Diagnostic.getKind方法的典型用法代码示例。如果您正苦于以下问题:Java Diagnostic.getKind方法的具体用法?Java Diagnostic.getKind怎么用?Java Diagnostic.getKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.Diagnostic
的用法示例。
在下文中一共展示了Diagnostic.getKind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findPositionForErrors
import javax.tools.Diagnostic; //导入方法依赖的package包/类
private Diagnostic<?> findPositionForErrors() throws Exception {
Set<String> supportedErrorKeys = getSupportedErrorKeys();
Diagnostic<?> found = null;
for (Diagnostic<?> d : info.getDiagnostics()) {
if (d.getKind() == Diagnostic.Kind.ERROR && (supportedErrorKeys == null || supportedErrorKeys.contains(d.getCode()))) {
if (found == null) {
found = d;
} else {
throw new IllegalStateException("More than one error: " + diagnosticsToString(info.getDiagnostics()));
}
}
}
if (found == null) {
throw new IllegalStateException("No error found: " + diagnosticsToString(info.getDiagnostics()));
}
return found;
}
示例2: report
import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == javax.tools.Diagnostic.Kind.ERROR) {
String message = diagnostic.toString() + " (" + diagnostic.getCode() + ")";
logger.error(message);
Location loc = new Location( //
diagnostic.getSource().toString(), //
(short) diagnostic.getLineNumber(), //
(short) diagnostic.getColumnNumber() //
);
// Wrap the exception in a RuntimeException, because "report()"
// does not declare checked exceptions.
throw new RuntimeException(new CompileException(message, loc));
} else if (logger.isTraceEnabled()) {
logger.trace(diagnostic.toString() + " (" + diagnostic.getCode() + ")");
}
}
示例3: getDiagnosticListenerForWriter
import javax.tools.Diagnostic; //导入方法依赖的package包/类
private DiagnosticListener<JavaFileObject> getDiagnosticListenerForWriter(Writer w) {
final PrintWriter pw = getPrintWriterForWriter(w);
return new DiagnosticListener<JavaFileObject> () {
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
switch (diagnostic.getKind()) {
case ERROR:
pw.print(getMessage("err.prefix"));
break;
case WARNING:
pw.print(getMessage("warn.prefix"));
break;
case NOTE:
pw.print(getMessage("note.prefix"));
break;
}
pw.print(" ");
pw.println(diagnostic.getMessage(null));
}
};
}
示例4: javap
import javax.tools.Diagnostic; //导入方法依赖的package包/类
private String javap(List<String> args, List<String> classes) {
DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
JavaFileManager fm = JavapFileManager.create(dc, pw);
JavapTask t = new JavapTask(pw, fm, dc, args, classes);
if (t.run() != 0)
throw new Error("javap failed unexpectedly");
List<Diagnostic<? extends JavaFileObject>> diags = dc.getDiagnostics();
for (Diagnostic<? extends JavaFileObject> d: diags) {
if (d.getKind() == Diagnostic.Kind.ERROR)
throw new Error(d.getMessage(Locale.ENGLISH));
}
return sw.toString();
}
示例5: findLogLevel
import javax.tools.Diagnostic; //导入方法依赖的package包/类
private static Level findLogLevel(Diagnostic<? extends JavaFileObject> d) {
if (d.getKind() == Diagnostic.Kind.ERROR) {
return Level.FINE;
} else {
return Level.FINER;
}
}
示例6: report
import javax.tools.Diagnostic; //导入方法依赖的package包/类
@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);
}
}
示例7: getErrors
import javax.tools.Diagnostic; //导入方法依赖的package包/类
/** Obtains errors created during compilation.
*/
public List<Diagnostic<? extends JavaFileObject>> getErrors() {
List<Diagnostic<? extends JavaFileObject>> err;
err = new ArrayList<Diagnostic<? extends JavaFileObject>>();
for (Diagnostic<? extends JavaFileObject> diagnostic : errors) {
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
err.add(diagnostic);
}
}
return err;
}
示例8: main
import javax.tools.Diagnostic; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
throw new RuntimeException("can't get javax.tools.JavaCompiler!");
}
DiagnosticCollector<JavaFileObject> diagColl =
new DiagnosticCollector<JavaFileObject>();
try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
List<String> options = new ArrayList<String>();
options.add("-processor");
options.add("MyProcessor");
options.add("-proc:only");
List<File> files = new ArrayList<File>();
files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
final CompilationTask task = compiler.getTask(null, fm, diagColl,
options, null, fm.getJavaFileObjectsFromFiles(files));
task.call();
int diagCount = 0;
for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
if (diag.getKind() != Diagnostic.Kind.WARNING) {
throw new AssertionError("Only warnings expected");
}
System.out.println(diag);
if (diag.getPosition() == Diagnostic.NOPOS) {
throw new AssertionError("No position info in message");
}
if (diag.getSource() == null) {
throw new AssertionError("No source info in message");
}
diagCount++;
}
if (diagCount != 2) {
throw new AssertionError("unexpected number of warnings: " +
diagCount + ", expected: 2");
}
}
}
示例9: onBindViewHolder
import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(ErrorHolder holder, int position) {
final Diagnostic diagnostic = mDiagnostics.get(position);
holder.line.setText(SpanUtil.createSrcSpan(mContext.getResources(), diagnostic));
switch (diagnostic.getKind()) {
case ERROR:
holder.icon.setImageResource(R.drawable.ic_error_red);
break;
case WARNING:
holder.icon.setImageResource(R.drawable.ic_warning_yellow);
break;
case MANDATORY_WARNING:
holder.icon.setImageResource(R.drawable.ic_warning_yellow);
break;
case NOTE:
holder.icon.setImageResource(R.drawable.ic_note_organe_24dp);
break;
case OTHER:
holder.icon.setImageResource(R.drawable.ic_warning_yellow);
break;
}
holder.message.setTypeface(FontManager.getFontFromAsset(mContext, "Roboto-Light.ttf"));
holder.message.setText(diagnostic.getMessage(null));
holder.root.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) listener.onClick(diagnostic);
}
});
String code = diagnostic.getCode();
}
示例10: report
import javax.tools.Diagnostic; //导入方法依赖的package包/类
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.WARNING &&
diagnostic.getCode().contains("try.resource.not.referenced")) {
String varName = unwrap(diagnostic).getArgs()[0].toString();
if (varName.equals(TwrStmt.TWR1.resourceName)) {
unused_r1 = true;
} else if (varName.equals(TwrStmt.TWR2.resourceName)) {
unused_r2 = true;
} else if (varName.equals(TwrStmt.TWR3.resourceName)) {
unused_r3 = true;
}
}
}
示例11: diag
import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public Diag diag(final Diagnostic<? extends JavaFileObject> d) {
return new Diag() {
@Override
public boolean isError() {
return d.getKind() == Diagnostic.Kind.ERROR;
}
@Override
public long getPosition() {
return d.getPosition();
}
@Override
public long getStartPosition() {
return d.getStartPosition();
}
@Override
public long getEndPosition() {
return d.getEndPosition();
}
@Override
public String getCode() {
return d.getCode();
}
@Override
public String getMessage(Locale locale) {
return expunge(d.getMessage(locale));
}
};
}
示例12: report
import javax.tools.Diagnostic; //导入方法依赖的package包/类
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
errorFound = true;
} else if (statProcessor.matches(diagnostic)) {
statProcessor.process(diagnostic);
}
}
示例13: getKind
import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public ErrorKind getKind(Diagnostic<?> t) {
return t.getKind() == Kind.ERROR ? errorKind : ErrorKind.WARNING;
}
示例14: BiAnalyser
import javax.tools.Diagnostic; //导入方法依赖的package包/类
/** Creates Bean Info analyser which contains all patterns from PatternAnalyser
*/
BiAnalyser ( PatternAnalyser pa, CompilationInfo javac ) throws GenerateBeanException {
int index;
this.isBeanBroken = false;
for (Diagnostic d : javac.getDiagnostics()) {
isBeanBroken |= d.getKind() == Diagnostic.Kind.ERROR;
}
// Try to find and analyse existing bean info
bis = new BeanInfoSource( pa.getFileObject() );
olderVersion = (bis.isNbBeanInfo() && bis.getMethodsSection() == null);
superClassVersion = (bis.isNbSuperclass() || !bis.exists());
TypeElement classElement = pa.getClassElementHandle().resolve(javac);
this.classfqn = classElement.getQualifiedName().toString();
// Fill Descriptor list (only in case we have new templates)
descriptor = new ArrayList<BiFeature.Descriptor>();
descriptor.add(new BiFeature.Descriptor(classElement, this));
// Fill methods list (only in case we have new templates)
methods = new ArrayList<BiFeature.Method>();
if (!olderVersion) {
for (ExecutableElement method : BeanUtils.methodsIn(classElement, javac)) {
methods.add(new BiFeature.Method(method, pa, javac, this));
}
}
// Fill properties list
List<PropertyPattern> propertyPatterns = pa.getPropertyPatterns();
properties = new ArrayList<BiFeature.Property>(propertyPatterns.size());
for (PropertyPattern pp : propertyPatterns) {
properties.add(new BiFeature.Property(pp, javac, this));
removeMethods(methods, pp.getGetterMethod(), pp.getSetterMethod());
}
// Fill indexed properties list
List<IdxPropertyPattern> idxPropertyPatterns = pa.getIdxPropertyPatterns();
idxProperties = new ArrayList<BiFeature.IdxProperty>(idxPropertyPatterns.size());
for (IdxPropertyPattern ipp : idxPropertyPatterns) {
TypeMirror type = ipp.getType().resolve(javac);
TypeMirror idxtype = ipp.getIndexedType().resolve(javac);
if (type.getKind() != TypeKind.ARRAY || !javac.getTypes().isSameType(((ArrayType) type).getComponentType(), idxtype)) {
continue;
}
idxProperties.add(new BiFeature.IdxProperty(ipp, javac, this));
removeMethods(methods, ipp.getGetterMethod(), ipp.getSetterMethod(), ipp.getIndexedGetterMethod(), ipp.getIndexedSetterMethod());
}
// Fill event sets list
List<EventSetPattern> eventSetPatterns = pa.getEventSetPatterns();
eventSets = new ArrayList<BiFeature.EventSet>(eventSetPatterns.size());
for (EventSetPattern esp : eventSetPatterns) {
eventSets.add(new BiFeature.EventSet(esp, javac, this));
removeMethods(methods, esp.getAddListenerMethod(), esp.getRemoveListenerMethod());
}
Collections.sort(methods);
try {
isUpdateMode = false;
analyzeBeanInfoSource();
} finally {
isUpdateMode = true;
}
}
示例15: report
import javax.tools.Diagnostic; //导入方法依赖的package包/类
@Override
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
if (diagnostic.getKind() == Diagnostic.Kind.ERROR) {
errorFound = true;
}
}