本文整理汇总了Java中com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition方法的典型用法代码示例。如果您正苦于以下问题:Java JCDiagnostic.DiagnosticPosition方法的具体用法?Java JCDiagnostic.DiagnosticPosition怎么用?Java JCDiagnostic.DiagnosticPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.util.JCDiagnostic
的用法示例。
在下文中一共展示了JCDiagnostic.DiagnosticPosition方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lambdaParamIsExplicitlyTyped
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
/**
* determines whether a lambda parameter has an explicit type declaration
*
* @param lambdaParameter the parameter
* @return true if there is a type declaration, false otherwise
*/
public static boolean lambdaParamIsExplicitlyTyped(VariableTree lambdaParameter) {
// kind of a hack; the "preferred position" seems to be the position
// of the variable name. if this differs from the start position, it
// means there is an explicit type declaration
JCDiagnostic.DiagnosticPosition diagnosticPosition =
(JCDiagnostic.DiagnosticPosition) lambdaParameter;
return diagnosticPosition.getStartPosition() != diagnosticPosition.getPreferredPosition();
}
示例2: printMessage
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
private void printMessage(Diagnostic.Kind kind, CharSequence msg,
JCDiagnostic.DiagnosticPosition pos,
com.sun.source.tree.CompilationUnitTree root) {
JavaFileObject oldSource = null;
JavaFileObject newSource = null;
newSource = root.getSourceFile();
if (newSource == null) {
pos = null;
} else {
oldSource = log.useSource(newSource);
}
try {
switch (kind) {
case ERROR:
boolean prev = log.multipleErrors;
try {
log.error(pos, "proc.messager", msg.toString());
} finally {
log.multipleErrors = prev;
}
break;
case WARNING:
log.warning(pos, "proc.messager", msg.toString());
break;
case MANDATORY_WARNING:
log.mandatoryWarning(pos, "proc.messager", msg.toString());
break;
default:
log.note(pos, "proc.messager", msg.toString());
}
} finally {
if (oldSource != null)
log.useSource(oldSource);
}
}
示例3: printMessage
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
private void printMessage(Diagnostic.Kind kind, CharSequence msg,
JCDiagnostic.DiagnosticPosition pos,
com.sun.source.tree.CompilationUnitTree root) {
JavaFileObject oldSource = null;
JavaFileObject newSource = null;
newSource = root.getSourceFile();
if (newSource == null) {
pos = null;
} else {
oldSource = log.useSource(newSource);
}
try {
switch (kind) {
case ERROR:
log.error(DiagnosticFlag.MULTIPLE, pos, Errors.ProcMessager(msg.toString()));
break;
case WARNING:
log.warning(pos, Warnings.ProcMessager(msg.toString()));
break;
case MANDATORY_WARNING:
log.mandatoryWarning(pos, Warnings.ProcMessager(msg.toString()));
break;
default:
log.note(pos, Notes.ProcMessager(msg.toString()));
}
} finally {
if (oldSource != null)
log.useSource(oldSource);
}
}
示例4: visitIf
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
public void visitIf(JCTree.JCIf tree) {
JCDiagnostic.DiagnosticPosition nil = null;
// generate dummy messages to exercise the log API
log.error("not.stmt");
log.error(tree.pos, "not.stmt");
log.error(tree.pos(), "not.stmt");
log.error(nil, "not.stmt");
log.warning("div.zero");
log.warning(tree.pos, "div.zero");
log.warning(tree.pos(), "div.zero");
log.warning(nil, "div.zero");
}
示例5: resolveMethod
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
private static Symbol.MethodSymbol resolveMethod( JCDiagnostic.DiagnosticPosition pos, Context ctx, JCTree.JCCompilationUnit compUnit, Name name, Type qual, List<Type> args )
{
Resolve rs = Resolve.instance( ctx );
AttrContext attrContext = new AttrContext();
Env<AttrContext> env = new AttrContextEnv( pos.getTree(), attrContext );
env.toplevel = compUnit;
return rs.resolveInternalMethod( pos, env, qual, name, args, null );
}
示例6: printMessage
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
private void printMessage(Diagnostic.Kind kind, CharSequence msg,
JCDiagnostic.DiagnosticPosition pos,
com.sun.source.tree.CompilationUnitTree root) {
JavaFileObject oldSource = null;
JavaFileObject newSource = null;
newSource = root.getSourceFile();
if (newSource == null) {
pos = null;
} else {
oldSource = log.useSource(newSource);
}
try {
switch (kind) {
case ERROR:
log.error(DiagnosticFlag.MULTIPLE, pos, "proc.messager", msg.toString());
break;
case WARNING:
log.warning(pos, "proc.messager", msg.toString());
break;
case MANDATORY_WARNING:
log.mandatoryWarning(pos, "proc.messager", msg.toString());
break;
default:
log.note(pos, "proc.messager", msg.toString());
}
} finally {
if (oldSource != null)
log.useSource(oldSource);
}
}
示例7: reportSyntaxError
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
/**
* Report a syntax error using the given DiagnosticPosition object and
* arguments, unless one was already reported at the same position.
*/
private void reportSyntaxError(JCDiagnostic.DiagnosticPosition diagPos, String key, Object... args) {
int pos = diagPos.getPreferredPosition();
if (pos > S.errPos() || pos == Position.NOPOS) {
if (S.token() == EOF) {
error(diagPos, "premature.eof");
} else {
error(diagPos, key, args);
}
}
S.errPos(pos);
if (S.pos() == errorPos)
S.nextToken(); // guarantee progress
errorPos = S.pos();
}
示例8: printMessage
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
/**
* Prints a message of the specified kind at the location of the
* tree within the provided compilation unit
*
* @param kind the kind of message
* @param msg the message, or an empty string if none
* @param t the tree to use as a position hint
* @param root the compilation unit that contains tree
*/
public void printMessage(Diagnostic.Kind kind, CharSequence msg,
Tree t,
CompilationUnitTree root) {
JavaFileObject oldSource = null;
JavaFileObject newSource = null;
JCDiagnostic.DiagnosticPosition pos = null;
newSource = root.getSourceFile();
if (newSource != null) {
oldSource = log.useSource(newSource);
pos = ((JCTree) t).pos();
}
try {
switch (kind) {
case ERROR:
boolean prev = log.multipleErrors;
try {
log.error(pos, "proc.messager", msg.toString());
} finally {
log.multipleErrors = prev;
}
break;
case WARNING:
log.warning(pos, "proc.messager", msg.toString());
break;
case MANDATORY_WARNING:
log.mandatoryWarning(pos, "proc.messager", msg.toString());
break;
default:
log.note(pos, "proc.messager", msg.toString());
}
} finally {
if (oldSource != null)
log.useSource(oldSource);
}
}
示例9: pos
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
public JCDiagnostic.DiagnosticPosition pos(DCDocComment dc) {
return new SimpleDiagnosticPosition(dc.comment.getSourcePos(pos));
}
示例10: Opt
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
public Opt() {
JCDiagnostic.DiagnosticPosition pos = null;
List<String> list = new ArrayList<>();
list.forEach(wrapIOConsumer(s -> {}));
}
示例11: printMessage
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
private void printMessage(Diagnostic.Kind kind, CharSequence msg,
JCDiagnostic.DiagnosticPosition pos,
com.sun.source.tree.CompilationUnitTree root) {
JavaFileObject oldSource = null;
JavaFileObject newSource = null;
newSource = root.getSourceFile();
if (newSource == null) {
pos = null;
} else {
oldSource = log.useSource(newSource);
}
try {
switch (kind) {
case ERROR:
boolean prev = log.multipleErrors;
log.multipleErrors = true;
try {
log.error(pos, "proc.messager", msg.toString());
} finally {
log.multipleErrors = prev;
}
break;
case WARNING:
log.warning(pos, "proc.messager", msg.toString());
break;
case MANDATORY_WARNING:
log.mandatoryWarning(pos, "proc.messager", msg.toString());
break;
default:
log.note(pos, "proc.messager", msg.toString());
}
} finally {
if (oldSource != null)
log.useSource(oldSource);
}
}
示例12: printMessage
import com.sun.tools.javac.util.JCDiagnostic; //导入方法依赖的package包/类
/**
* Prints a message of the specified kind at the location of the
* tree within the provided compilation unit
*
* @param kind the kind of message
* @param msg the message, or an empty string if none
* @param t the tree to use as a position hint
* @param root the compilation unit that contains tree
*/
public void printMessage(Diagnostic.Kind kind, CharSequence msg,
com.sun.source.tree.Tree t,
com.sun.source.tree.CompilationUnitTree root) {
JavaFileObject oldSource = null;
JavaFileObject newSource = null;
JCDiagnostic.DiagnosticPosition pos = null;
newSource = root.getSourceFile();
if (newSource != null) {
oldSource = log.useSource(newSource);
pos = ((JCTree) t).pos();
}
try {
switch (kind) {
case ERROR:
boolean prev = log.multipleErrors;
try {
log.error(pos, "proc.messager", msg.toString());
} finally {
log.multipleErrors = prev;
}
break;
case WARNING:
log.warning(pos, "proc.messager", msg.toString());
break;
case MANDATORY_WARNING:
log.mandatoryWarning(pos, "proc.messager", msg.toString());
break;
default:
log.note(pos, "proc.messager", msg.toString());
}
} finally {
if (oldSource != null)
log.useSource(oldSource);
}
}