org.springframework.core.annotation.MissingMergedAnnotation Maven / Gradle / Ivy
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.annotation;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import org.springframework.lang.Nullable;
/**
* An {@link AbstractMergedAnnotation} used as the implementation of
* {@link MergedAnnotation#missing()}.
*
* @author Phillip Webb
* @author Juergen Hoeller
* @since 5.2
* @param the annotation type
*/
final class MissingMergedAnnotation extends AbstractMergedAnnotation {
private static final MissingMergedAnnotation INSTANCE = new MissingMergedAnnotation<>();
private MissingMergedAnnotation() {
}
@Override
public Class getType() {
throw new NoSuchElementException("Unable to get type for missing annotation");
}
@Override
public boolean isPresent() {
return false;
}
@Override
@Nullable
public Object getSource() {
return null;
}
@Override
@Nullable
public MergedAnnotation getMetaSource() {
return null;
}
@Override
public MergedAnnotation getRoot() {
return this;
}
@Override
public List> getMetaTypes() {
return Collections.emptyList();
}
@Override
public int getDistance() {
return -1;
}
@Override
public int getAggregateIndex() {
return -1;
}
@Override
public boolean hasNonDefaultValue(String attributeName) {
throw new NoSuchElementException(
"Unable to check non-default value for missing annotation");
}
@Override
public boolean hasDefaultValue(String attributeName) {
throw new NoSuchElementException(
"Unable to check default value for missing annotation");
}
@Override
public Optional getValue(String attributeName, Class type) {
return Optional.empty();
}
@Override
public Optional getDefaultValue(@Nullable String attributeName, Class type) {
return Optional.empty();
}
@Override
public MergedAnnotation filterAttributes(Predicate predicate) {
return this;
}
@Override
public MergedAnnotation withNonMergedAttributes() {
return this;
}
@Override
public AnnotationAttributes asAnnotationAttributes(Adapt... adaptations) {
return new AnnotationAttributes();
}
@Override
public Map asMap(Adapt... adaptations) {
return Collections.emptyMap();
}
@Override
public > T asMap(Function, T> factory, Adapt... adaptations) {
return factory.apply(this);
}
@Override
public String toString() {
return "(missing)";
}
@Override
public MergedAnnotation getAnnotation(String attributeName,
Class type) throws NoSuchElementException {
throw new NoSuchElementException(
"Unable to get attribute value for missing annotation");
}
@Override
public MergedAnnotation[] getAnnotationArray(
String attributeName, Class type) throws NoSuchElementException {
throw new NoSuchElementException(
"Unable to get attribute value for missing annotation");
}
@Override
protected T getAttributeValue(String attributeName, Class type) {
throw new NoSuchElementException(
"Unable to get attribute value for missing annotation");
}
@Override
protected A createSynthesized() {
throw new NoSuchElementException("Unable to synthesize missing annotation");
}
@SuppressWarnings("unchecked")
static MergedAnnotation getInstance() {
return (MergedAnnotation) INSTANCE;
}
}