本文整理汇总了Java中org.checkerframework.checker.nullness.qual.NonNull类的典型用法代码示例。如果您正苦于以下问题:Java NonNull类的具体用法?Java NonNull怎么用?Java NonNull使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NonNull类属于org.checkerframework.checker.nullness.qual包,在下文中一共展示了NonNull类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
void add(@NonNull Class<? extends Annotation> annotationClass, @NonNull AnnotatedMethod method)
throws ProcessingException {
Map<Class, AnnotatedMethod> annotationMap = mItemsMap.get(method.getSensorType());
if (annotationMap == null) {
annotationMap = new HashMap<>();
}
if (annotationMap.get(annotationClass) != null) {
String error =
String.format("@%s is already annotated on a different method in class %s",
annotationClass.getSimpleName(), method.getExecutableElement().getSimpleName());
throw new ProcessingException(method.getExecutableElement(), error);
}
annotationMap.put(annotationClass, method);
mItemsMap.put(method.getSensorType(), annotationMap);
}
示例2: createTriggerListenerWrapper
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
/**
* Create an {@code EventListenerWrapper} that contains the {@code TriggerEventListener} and
* calls the annotated methods on our target.
*
* @param triggerAnnotatedMethod Method annotated with {@link OnTrigger}.
* @return {@link CodeBlock} of the {@code EventListenerWrapper}.
*/
@NonNull
private static CodeBlock createTriggerListenerWrapper(
@NonNull AnnotatedMethod triggerAnnotatedMethod) throws ProcessingException {
checkAnnotatedMethodForErrors(triggerAnnotatedMethod.getExecutableElement(),
OnTrigger.class);
CodeBlock listenerBlock = CodeBlock.builder()
.add("new $T() {\n", TRIGGER_EVENT_LISTENER)
.indent()
.add(createOnTriggerListenerMethod(triggerAnnotatedMethod).toString())
.unindent()
.add("}")
.build();
return CodeBlock.builder()
.addStatement("this.$N.add(new $T($L))", LISTENER_WRAPPERS_FIELD,
TRIGGER_EVENT_LISTENER_WRAPPER, listenerBlock)
.build();
}
示例3: createOnSensorChangedListenerMethod
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
/**
* Creates the implementation of {@code SensorEventListener#onSensorChanged(SensorEvent)} which
* calls the annotated method on our target class.
*
* @param annotatedMethod Method annotated with {@code OnSensorChanged}.
* @return {@link MethodSpec} of {@code SensorEventListener#onSensorChanged(SensorEvent)}.
*/
@NonNull
private static MethodSpec createOnSensorChangedListenerMethod(
@Nullable AnnotatedMethod annotatedMethod) {
ParameterSpec sensorEventParameter = ParameterSpec.builder(SENSOR_EVENT, "event").build();
Builder methodBuilder =
getBaseMethodBuilder("onSensorChanged").addParameter(sensorEventParameter);
if (annotatedMethod != null) {
ExecutableElement sensorChangedExecutableElement =
annotatedMethod.getExecutableElement();
methodBuilder.addStatement("target.$L($N)",
sensorChangedExecutableElement.getSimpleName(), sensorEventParameter);
}
return methodBuilder.build();
}
示例4: createOnAccuracyChangedListenerMethod
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
/**
* Creates the implementation of {@code SensorEventListener#onAccuracyChanged(Sensor, int)}
* which calls the annotated method on our target class.
*
* @param annotatedMethod Method annotated with {@link OnAccuracyChanged}.
* @return {@link MethodSpec} of {@code SensorEventListener#onAccuracyChanged(Sensor, int)}.
*/
@NonNull
private static MethodSpec createOnAccuracyChangedListenerMethod(
@Nullable AnnotatedMethod annotatedMethod) {
ParameterSpec sensorParameter = ParameterSpec.builder(SENSOR, "sensor").build();
ParameterSpec accuracyParameter = ParameterSpec.builder(TypeName.INT, "accuracy").build();
Builder methodBuilder =
getBaseMethodBuilder("onAccuracyChanged").addParameter(sensorParameter)
.addParameter(accuracyParameter);
if (annotatedMethod != null) {
ExecutableElement accuracyChangedExecutableElement =
annotatedMethod.getExecutableElement();
methodBuilder.addStatement("target.$L($N, $N)",
accuracyChangedExecutableElement.getSimpleName(), sensorParameter,
accuracyParameter);
}
return methodBuilder.build();
}
示例5: processAnnotation
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
private void processAnnotation(Class<? extends Annotation> annotationClass,
@NonNull RoundEnvironment roundEnv) throws ProcessingException {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotationClass);
warn(null, "Processing %d elements annotated with @%s", elements.size(), elements);
for (Element element : elements) {
if (element.getKind() != ElementKind.METHOD) {
throw new ProcessingException(element,
String.format("Only methods can be annotated with @%s",
annotationClass.getSimpleName()));
} else {
ExecutableElement executableElement = (ExecutableElement) element;
try {
processMethod(executableElement, annotationClass);
} catch (IllegalArgumentException e) {
throw new ProcessingException(executableElement, e.getMessage());
}
}
}
}
示例6: checkMethodValidity
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
private void checkMethodValidity(@NonNull AnnotatedMethod item) throws ProcessingException {
ExecutableElement methodElement = item.getExecutableElement();
Set<Modifier> modifiers = methodElement.getModifiers();
// The annotated method needs to be accessible by the generated class which will have
// the same package. Public or "package private" (default) methods are required.
if (modifiers.contains(Modifier.PRIVATE) || modifiers.contains(Modifier.PROTECTED)) {
throw new ProcessingException(methodElement,
String.format("The method %s can not be private or protected.",
methodElement.getSimpleName().toString()));
}
// We cannot annotate abstract methods, we need to annotate the actual implementation of
// the method on the implementing class.
if (modifiers.contains(Modifier.ABSTRACT)) {
throw new ProcessingException(methodElement, String.format(
"The method %s is abstract. You can't annotate abstract methods with @%s",
methodElement.getSimpleName().toString(), AnnotatedMethod.class.getSimpleName()));
}
}
示例7: readFile
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
protected List<HostJobState> readFile() {
try {
val inputStream = new FileInputStream(file);
val inputStreamReader = new InputStreamReader(inputStream, defaultCharset());
val fileReader = new BufferedReader(inputStreamReader);
try {
return fileReader.lines().map(line -> {
final String[] data = line.split(",");
final String location = data[0].trim();
final long jobId = Long.parseLong(data[1].trim());
final String state = data[2].trim();
return new HostJobState(URI.create(location), jobId, JobState.valueOf(state));
}).collect(Collectors.<@NonNull HostJobState>toList());
}
finally {
Utils.close(fileReader);
}
}
catch (FileNotFoundException e) {
throw softened(e);
}
}
示例8: execute
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
@NonNull
public Set<ValidationError> execute(@NonNull final Path basePath) throws IOException {
// Init Context ...
Context.getInstance(basePath);
// Process rules ...
final Stream<Path> filesToProgress = Files.walk(basePath, FileVisitOption.FOLLOW_LINKS).map(path -> basePath.relativize(path))
.filter(childPath -> !exclusions.stream().anyMatch(exc -> childPath.toString().startsWith(exc)));
final Set<Set<ValidationError>> result = filesToProgress.map(relativePath -> {
logger.debug("Processing file -> '{}' '{}'", basePath, relativePath);
// Filter rules ...
final Stream<Rule> filteredRules = rules.stream().filter(rule -> rule.accepts(basePath, relativePath));
// Apply rules ..
return filteredRules.map(rule -> rule.verify(basePath, relativePath)).collect(Collectors.toSet());
}).filter(set -> !set.isEmpty()).flatMap(Collection::stream).collect(Collectors.toSet());
final Stream<ValidationError> errors = result.stream().flatMap(Collection::stream);
// Filter ignored errors ....
return errors.filter(e -> ignore.get(e.getUUID()) == null).collect(Collectors.toSet());
}
示例9: verify
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
@Override
public Set<ValidationError> verify(@NonNull Path basePath, @NonNull Path childPath) throws DevKitSonarRuntimeException {
final Set<VelocityContext> contexts = this.buildContexts(basePath);
final List<String> msgs = new ArrayList<>();
for (VelocityContext context : contexts) {
final StringWriter sw = new StringWriter();
template.merge(context, sw);
// Does the file exist?
final String child = sw.toString();
if (!Files.exists(basePath.resolve(child))) {
msgs.add("File '" + child + "' does not exist.");
}
}
return buildError(msgs);
}
示例10: permute
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
@NonNull
static public List<List<String>> permute(@NonNull final List<List<String>> lists, int level) {
List<List<String>> result = new ArrayList<>();
if (level == lists.size() - 1) {
result = lists.get(level).stream().map(Collections::singletonList).collect(Collectors.toList());
} else {
List<List<String>> children = new ArrayList<>();
if (level < lists.size()) {
children = DirectoryStructureRule.permute(lists, level + 1);
}
final List<String> parents = lists.get(level);
for (String parent : parents) {
for (List<String> child : children) {
final List<String> item = new ArrayList<>();
item.add(parent);
item.addAll(child);
result.add(item);
}
}
}
return result;
}
示例11: createSensorListenerWrapper
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
/**
* Create an {@code EventListenerWrapper} that contains the {@code
* SensorEventListener} and calls the annotated methods on our target.
*
* @param sensorType The {@code Sensor} type.
* @param sensorChangedAnnotatedMethod Method annotated with {@link OnSensorChanged}.
* @param accuracyChangedAnnotatedMethod Method annotated with {@link OnAccuracyChanged}.
* @return {@link CodeBlock} of the {@code EventListenerWrapper}.
*/
@NonNull
private static CodeBlock createSensorListenerWrapper(int sensorType,
@Nullable AnnotatedMethod sensorChangedAnnotatedMethod,
@Nullable AnnotatedMethod accuracyChangedAnnotatedMethod) throws ProcessingException {
if (sensorChangedAnnotatedMethod != null) {
checkAnnotatedMethodForErrors(sensorChangedAnnotatedMethod.getExecutableElement(),
OnSensorChanged.class);
}
if (accuracyChangedAnnotatedMethod != null) {
checkAnnotatedMethodForErrors(accuracyChangedAnnotatedMethod.getExecutableElement(),
OnAccuracyChanged.class);
}
CodeBlock listenerBlock = CodeBlock.builder()
.add("new $T() {\n", SENSOR_EVENT_LISTENER)
.indent()
.add(createOnSensorChangedListenerMethod(sensorChangedAnnotatedMethod).toString())
.add(createOnAccuracyChangedListenerMethod(accuracyChangedAnnotatedMethod).toString())
.unindent()
.add("}")
.build();
int delay =
getDelayForListener(sensorChangedAnnotatedMethod, accuracyChangedAnnotatedMethod);
if (delay == INVALID_DELAY) {
String error =
String.format("@%s or @%s needs a delay value specified in the annotation",
OnSensorChanged.class.getSimpleName(), OnAccuracyChanged.class.getSimpleName());
throw new ProcessingException(null, error);
}
return CodeBlock.builder()
.addStatement("this.$N.add(new $T($L, $L, $L))", LISTENER_WRAPPERS_FIELD,
SENSOR_EVENT_LISTENER_WRAPPER, sensorType, delay, listenerBlock)
.build();
}
示例12: createOnTriggerListenerMethod
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
/**
* Creates the implementation of {@code TriggerEventListener#onTrigger(TriggerEvent)} which
* calls the annotated method on our target class.
*
* @param annotatedMethod Method annotated with {@code OnTrigger}.
* @return {@link MethodSpec} of {@code TriggerEventListener#onTrigger(TriggerEvent)}.
*/
@NonNull
private static MethodSpec createOnTriggerListenerMethod(
@NonNull AnnotatedMethod annotatedMethod) {
ParameterSpec triggerEventParameter = ParameterSpec.builder(TRIGGER_EVENT, "event").build();
ExecutableElement triggerExecutableElement = annotatedMethod.getExecutableElement();
return getBaseMethodBuilder("onTrigger").addParameter(triggerEventParameter)
.addStatement("target.$L($N)", triggerExecutableElement.getSimpleName(),
triggerEventParameter)
.build();
}
示例13: getBaseMethodBuilder
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
/**
* Return a {@link Builder} with the given method name and default properties.
*
* @param name The name of the method.
* @return A base {@link Builder} to use for methods.
*/
@NonNull
private static Builder getBaseMethodBuilder(@NonNull String name) {
return MethodSpec.methodBuilder(name)
.addModifiers(Modifier.PUBLIC)
.returns(void.class)
.addAnnotation(Override.class);
}
示例14: AnnotatedMethod
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
AnnotatedMethod(@NonNull ExecutableElement methodElement,
@NonNull Class<? extends Annotation> annotationClass) throws IllegalArgumentException {
Annotation annotation = methodElement.getAnnotation(annotationClass);
mAnnotatedMethodElement = methodElement;
mDelay = getDelayFromAnnotation(annotation);
mSensorType = getSensorTypeFromAnnotation(annotation);
if (mSensorType == INVALID_SENSOR) {
throw new IllegalArgumentException(String.format(
"No sensor type specified in @%s for method %s."
+ " Set a sensor type such as Sensor.TYPE_ACCELEROMETER.",
annotationClass.getSimpleName(), methodElement.getSimpleName().toString()));
}
}
示例15: getSensorTypeFromAnnotation
import org.checkerframework.checker.nullness.qual.NonNull; //导入依赖的package包/类
/**
* Return the sensor type set on the annotation.
*
* @param annotation The annotation we want to inspect for the sensor type.
* @return The sensor type or {@link #INVALID_SENSOR}.
*/
private int getSensorTypeFromAnnotation(@NonNull Annotation annotation) {
if (annotation instanceof OnSensorChanged) {
return ((OnSensorChanged) annotation).value();
} else if (annotation instanceof OnAccuracyChanged) {
return ((OnAccuracyChanged) annotation).value();
} else if (annotation instanceof OnSensorNotAvailable) {
return ((OnSensorNotAvailable) annotation).value();
} else if (annotation instanceof OnTrigger) {
return TYPE_SIGNIFICANT_MOTION;
}
return INVALID_SENSOR;
}