本文整理汇总了Java中com.sun.tools.javac.code.Lint.LintCategory类的典型用法代码示例。如果您正苦于以下问题:Java LintCategory类的具体用法?Java LintCategory怎么用?Java LintCategory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LintCategory类属于com.sun.tools.javac.code.Lint包,在下文中一共展示了LintCategory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accepts
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
boolean accepts(AttributeKind kind) {
if (kinds.contains(kind)) {
if (majorVersion > version.major || (majorVersion == version.major && minorVersion >= version.minor))
return true;
if (lintClassfile && !warnedAttrs.contains(name)) {
JavaFileObject prev = log.useSource(currentClassFile);
try {
log.warning(LintCategory.CLASSFILE, (DiagnosticPosition) null, "future.attr",
name, version.major, version.minor, majorVersion, minorVersion);
} finally {
log.useSource(prev);
}
warnedAttrs.add(name);
}
}
return false;
}
示例2: checkUnsafeVarargsConversion
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
private void checkUnsafeVarargsConversion(Type t, Type s, Warner warn) {
if (t.tag != ARRAY || isReifiable(t)) return;
ArrayType from = (ArrayType)t;
boolean shouldWarn = false;
switch (s.tag) {
case ARRAY:
ArrayType to = (ArrayType)s;
shouldWarn = from.isVarargs() &&
!to.isVarargs() &&
!isReifiable(from);
break;
case CLASS:
shouldWarn = from.isVarargs();
break;
}
if (shouldWarn) {
warn.warn(LintCategory.VARARGS);
}
}
示例3: visitArrayType
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
switch (s.tag) {
case ERROR:
case BOT:
return true;
case TYPEVAR:
if (isCastable(s, t, Warner.noWarnings)) {
warnStack.head.warn(LintCategory.UNCHECKED);
return true;
} else {
return false;
}
case CLASS:
return isSubtype(t, s);
case ARRAY:
if (elemtype(t).tag <= lastBaseTag ||
elemtype(s).tag <= lastBaseTag) {
return elemtype(t).tag == elemtype(s).tag;
} else {
return visit(elemtype(t), elemtype(s));
}
default:
return false;
}
}
示例4: visitTypeVar
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
@Override
public Boolean visitTypeVar(TypeVar t, Type s) {
switch (s.tag) {
case ERROR:
case BOT:
return true;
case TYPEVAR:
if (isSubtype(t, s)) {
return true;
} else if (isCastable(t.bound, s, Warner.noWarnings)) {
warnStack.head.warn(LintCategory.UNCHECKED);
return true;
} else {
return false;
}
default:
return isCastable(t.bound, s, warnStack.head);
}
}
示例5: warn
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
@Override
public void warn(LintCategory lint) {
boolean warned = this.warned;
super.warn(lint);
if (warned) return; // suppress redundant diagnostics
switch (lint) {
case UNCHECKED:
Check.this.warnUnchecked(pos(), "prob.found.req", diags.fragment(uncheckedKey), found, expected);
break;
case VARARGS:
if (method != null &&
method.attribute(syms.trustMeType.tsym) != null &&
isTrustMeAllowedOnMethod(method) &&
!types.isReifiable(method.type.getParameterTypes().last())) {
Check.this.warnUnsafeVararg(pos(), "varargs.unsafe.use.varargs.param", method.params.last());
}
break;
default:
throw new AssertionError("Unexpected lint: " + lint);
}
}
示例6: isSubtypeUncheckedInternal
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
private boolean isSubtypeUncheckedInternal(Type t, Type s, Warner warn) {
if (t.hasTag(ARRAY) && s.hasTag(ARRAY)) {
t = t.unannotatedType();
s = s.unannotatedType();
if (((ArrayType)t).elemtype.isPrimitive()) {
return isSameType(elemtype(t), elemtype(s));
} else {
return isSubtypeUnchecked(elemtype(t), elemtype(s), warn);
}
} else if (isSubtype(t, s)) {
return true;
} else if (t.hasTag(TYPEVAR)) {
return isSubtypeUnchecked(t.getUpperBound(), s, warn);
} else if (!s.isRaw()) {
Type t2 = asSuper(t, s.tsym);
if (t2 != null && t2.isRaw()) {
if (isReifiable(s)) {
warn.silentWarn(LintCategory.UNCHECKED);
} else {
warn.warn(LintCategory.UNCHECKED);
}
return true;
}
}
return false;
}
示例7: visitArrayType
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
@Override
public Boolean visitArrayType(ArrayType t, Type s) {
switch (s.getTag()) {
case ERROR:
case BOT:
return true;
case TYPEVAR:
if (isCastable(s, t, noWarnings)) {
warnStack.head.warn(LintCategory.UNCHECKED);
return true;
} else {
return false;
}
case CLASS:
return isSubtype(t, s);
case ARRAY:
if (elemtype(t).isPrimitive() || elemtype(s).isPrimitive()) {
return elemtype(t).hasTag(elemtype(s).getTag());
} else {
return visit(elemtype(t), elemtype(s));
}
default:
return false;
}
}
示例8: visitTypeVar
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
@Override
public Boolean visitTypeVar(TypeVar t, Type s) {
switch (s.getTag()) {
case ERROR:
case BOT:
return true;
case TYPEVAR:
if (isSubtype(t, s)) {
return true;
} else if (isCastable(t.bound, s, noWarnings)) {
warnStack.head.warn(LintCategory.UNCHECKED);
return true;
} else {
return false;
}
default:
return isCastable(t.bound, s, warnStack.head);
}
}
示例9: returnTypeSubstitutable
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
public boolean returnTypeSubstitutable(Type r1,
Type r2, Type r2res,
Warner warner) {
if (isSameType(r1.getReturnType(), r2res))
return true;
if (r1.getReturnType().isPrimitive() || r2res.isPrimitive())
return false;
if (hasSameArgs(r1, r2))
return covariantReturnType(r1.getReturnType(), r2res, warner);
if (!allowCovariantReturns)
return false;
if (isSubtypeUnchecked(r1.getReturnType(), r2res, warner))
return true;
if (!isSubtype(r1.getReturnType(), erasure(r2res)))
return false;
warner.warn(LintCategory.UNCHECKED);
return true;
}
示例10: JCDiagnostic
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
/**
* Create a diagnostic object.
* @param formatter the formatter to use for the diagnostic
* @param diagnosticInfo the diagnostic key
* @param lc the lint category for the diagnostic
* @param source the name of the source file, or null if none.
* @param pos the character offset within the source file, if given.
*/
protected JCDiagnostic(DiagnosticFormatter<JCDiagnostic> formatter,
DiagnosticInfo diagnosticInfo,
LintCategory lc,
Set<DiagnosticFlag> flags,
DiagnosticSource source,
DiagnosticPosition pos) {
if (source == null && pos != null && pos.getPreferredPosition() != Position.NOPOS)
throw new IllegalArgumentException();
this.defaultFormatter = formatter;
this.diagnosticInfo = diagnosticInfo;
this.lintCategory = lc;
this.flags = flags;
this.source = source;
this.position = pos;
}
示例11: checkClassOverrideEqualsAndHash
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
private void checkClassOverrideEqualsAndHash(DiagnosticPosition pos,
ClassSymbol someClass) {
if (lint.isEnabled(LintCategory.OVERRIDES)) {
MethodSymbol equalsAtObject = (MethodSymbol)syms.objectType
.tsym.members().findFirst(names.equals);
MethodSymbol hashCodeAtObject = (MethodSymbol)syms.objectType
.tsym.members().findFirst(names.hashCode);
boolean overridesEquals = types.implementation(equalsAtObject,
someClass, false, equalsHasCodeFilter).owner == someClass;
boolean overridesHashCode = types.implementation(hashCodeAtObject,
someClass, false, equalsHasCodeFilter) != hashCodeAtObject;
if (overridesEquals && !overridesHashCode) {
log.warning(LintCategory.OVERRIDES, pos,
Warnings.OverrideEqualsButNotHashcode(someClass));
}
}
}
示例12: checkDeprecatedAnnotation
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
void checkDeprecatedAnnotation(DiagnosticPosition pos, Symbol s) {
if (lint.isEnabled(LintCategory.DEP_ANN) && s.isDeprecatableViaAnnotation() &&
(s.flags() & DEPRECATED) != 0 &&
!syms.deprecatedType.isErroneous() &&
s.attribute(syms.deprecatedType.tsym) == null) {
log.warning(LintCategory.DEP_ANN,
pos, Warnings.MissingDeprecatedAnnotation);
}
// Note: @Deprecated has no effect on local variables, parameters and package decls.
if (lint.isEnabled(LintCategory.DEPRECATION) && !s.isDeprecatableViaAnnotation()) {
if (!syms.deprecatedType.isErroneous() && s.attribute(syms.deprecatedType.tsym) != null) {
log.warning(LintCategory.DEPRECATION, pos,
Warnings.DeprecatedAnnotationHasNoEffect(Kinds.kindName(s)));
}
}
}
示例13: checkAutoCloseable
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
void checkAutoCloseable(DiagnosticPosition pos, Env<AttrContext> env, Type resource) {
if (!resource.isErroneous() &&
types.asSuper(resource, syms.autoCloseableType.tsym) != null &&
!types.isSameType(resource, syms.autoCloseableType)) { // Don't emit warning for AutoCloseable itself
Symbol close = syms.noSymbol;
Log.DiagnosticHandler discardHandler = new Log.DiscardDiagnosticHandler(log);
try {
close = rs.resolveQualifiedMethod(pos,
env,
resource,
names.close,
List.<Type>nil(),
List.<Type>nil());
}
finally {
log.popDiagnosticHandler(discardHandler);
}
if (close.kind == MTH &&
close.overrides(syms.autoCloseableClose, resource.tsym, types, true) &&
chk.isHandled(syms.interruptedExceptionType, types.memberType(resource, close).getThrownTypes()) &&
env.info.lint.isEnabled(LintCategory.TRY)) {
log.warning(LintCategory.TRY, pos, "try.resource.throws.interrupted.exc", resource);
}
}
}
示例14: checkRedundantCast
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
/** Check for redundant casts (i.e. where source type is a subtype of target type)
* The problem should only be reported for non-292 cast
*/
public void checkRedundantCast(Env<AttrContext> env, final JCTypeCast tree) {
if (!tree.type.isErroneous()
&& types.isSameType(tree.expr.type, tree.clazz.type)
&& !(ignoreAnnotatedCasts && TreeInfo.containsTypeAnnotation(tree.clazz))
&& !is292targetTypeCast(tree)) {
deferredLintHandler.report(new DeferredLintHandler.LintLogger() {
@Override
public void report() {
if (lint.isEnabled(Lint.LintCategory.CAST))
log.warning(Lint.LintCategory.CAST,
tree.pos(), "redundant.cast", tree.expr.type);
}
});
}
}
示例15: checkClassOverrideEqualsAndHash
import com.sun.tools.javac.code.Lint.LintCategory; //导入依赖的package包/类
private void checkClassOverrideEqualsAndHash(DiagnosticPosition pos,
ClassSymbol someClass) {
if (lint.isEnabled(LintCategory.OVERRIDES)) {
MethodSymbol equalsAtObject = (MethodSymbol)syms.objectType
.tsym.members().lookup(names.equals).sym;
MethodSymbol hashCodeAtObject = (MethodSymbol)syms.objectType
.tsym.members().lookup(names.hashCode).sym;
boolean overridesEquals = types.implementation(equalsAtObject,
someClass, false, equalsHasCodeFilter).owner == someClass;
boolean overridesHashCode = types.implementation(hashCodeAtObject,
someClass, false, equalsHasCodeFilter) != hashCodeAtObject;
if (overridesEquals && !overridesHashCode) {
log.warning(LintCategory.OVERRIDES, pos,
"override.equals.but.not.hashcode", someClass);
}
}
}