io.helidon.service.codegen.RoundContextImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helidon-service-codegen Show documentation
Show all versions of helidon-service-codegen Show documentation
Code generation implementation for Helidon Service, to be used from annotation processing and from maven plugin
The newest version!
/*
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
*
* 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
*
* http://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 io.helidon.service.codegen;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import io.helidon.common.types.TypeInfo;
import io.helidon.common.types.TypeName;
import io.helidon.common.types.TypedElementInfo;
class RoundContextImpl implements RegistryRoundContext {
private final Map> annotationToTypes;
private final List types;
private final Collection annotations;
RoundContextImpl(Set annotations,
Map> annotationToTypes,
List types) {
this.annotations = annotations;
this.annotationToTypes = annotationToTypes;
this.types = types;
}
@Override
public Collection availableAnnotations() {
return annotations;
}
@Override
public Collection types() {
return types;
}
@Override
public Collection annotatedElements(TypeName annotationType) {
List typeInfos = annotationToTypes.get(annotationType);
if (typeInfos == null) {
return Set.of();
}
List result = new ArrayList<>();
for (TypeInfo typeInfo : typeInfos) {
typeInfo.elementInfo()
.stream()
.filter(it -> it.hasAnnotation(annotationType))
.forEach(result::add);
}
return result;
}
@Override
public Collection annotatedTypes(TypeName annotationType) {
List typeInfos = annotationToTypes.get(annotationType);
if (typeInfos == null) {
return Set.of();
}
List result = new ArrayList<>();
for (TypeInfo typeInfo : typeInfos) {
if (typeInfo.hasAnnotation(annotationType)) {
result.add(typeInfo);
}
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy