import com.jcabi.aspects.Immutable; //导入依赖的package包/类
/**
* This class is immutable?
* @param type The class to check
* @throws ImmutabilityChecker.Violation If it is mutable
*/
private void check(final Class> type)
throws ImmutabilityChecker.Violation {
synchronized (this.immutable) {
if (!this.ignore(type)) {
if (type.isInterface()
&& !type.isAnnotationPresent(Immutable.class)) {
throw new ImmutabilityChecker.Violation(
String.format(
"Interface '%s' is not annotated with @Immutable",
type.getName()
)
);
}
if (!type.isInterface()
&& !Modifier.isFinal(type.getModifiers())) {
throw new Violation(
String.format(
"Class '%s' is not final",
type.getName()
)
);
}
try {
this.fields(type);
} catch (final ImmutabilityChecker.Violation ex) {
throw new ImmutabilityChecker.Violation(
String.format("Class '%s' is mutable", type.getName()),
ex
);
}
this.immutable.add(type);
Logger.debug(this, "#check(%s): immutability checked", type);
}
}
}