use of org.immutables.value.processor.meta.Proto.DeclaringType in project immutables by immutables.
the class Constitution method typeImmutableEnclosingSimpleName.
/**
* Walks to the enclosing type's simple names and applies naming convention.
* This shortcut/fix shows deficiency of model (it's probably more complicated than needed).
* @return enclosing immutable name
*/
@Value.Lazy
String typeImmutableEnclosingSimpleName() {
DeclaringType declaringType = protoclass().enclosingOf().get();
String enclosingSimpleName = declaringType.element().getSimpleName().toString();
String enclosingRawName = names().rawFromAbstract(enclosingSimpleName);
// Here we checking for having both enclosing and value
// if we had protoclass it would be kind().isEnclosing() && kind().isValue()
Naming naming = declaringType.isImmutable() ? names().namings.typeImmutable : names().namings.typeImmutableEnclosing;
return naming.apply(enclosingRawName);
}
use of org.immutables.value.processor.meta.Proto.DeclaringType in project immutables by immutables.
the class Generics method computeParameters.
private static Parameter[] computeParameters(final Protoclass protoclass, final Element element) {
if (!(element instanceof Parameterizable)) {
return NO_PARAMETERS;
}
final List<? extends TypeParameterElement> typeParameters = ((Parameterizable) element).getTypeParameters();
if (typeParameters.isEmpty()) {
return NO_PARAMETERS;
}
class Creator {
final String[] vars = collectVars(typeParameters);
final DeclaringType declaringType = protoclass.environment().round().inferDeclaringTypeFor(element);
Parameter[] create() {
final Parameter[] parameters = new Parameter[typeParameters.size()];
int i = 0;
for (TypeParameterElement e : typeParameters) {
parameters[i] = new Parameter(i, e.getSimpleName().toString(), boundsFrom(e));
i++;
}
return parameters;
}
String[] boundsFrom(TypeParameterElement e) {
List<? extends TypeMirror> boundMirrors = e.getBounds();
if (boundMirrors.isEmpty()) {
return NO_STRINGS;
}
String[] bounds = new String[boundMirrors.size()];
int c = 0;
for (TypeMirror m : boundMirrors) {
TypeStringProvider provider = newProvider(m);
provider.process();
bounds[c++] = provider.returnTypeName();
}
if (bounds.length == 1 && bounds[0].equals(Object.class.getName())) {
return NO_STRINGS;
}
return bounds;
}
TypeStringProvider newProvider(TypeMirror type) {
return new TypeStringProvider(protoclass.report(), element, type, new ImportsTypeStringResolver(declaringType, declaringType), vars, null);
}
}
return new Creator().create();
}
use of org.immutables.value.processor.meta.Proto.DeclaringType in project immutables by immutables.
the class Round method collectValues.
public Multimap<DeclaringPackage, ValueType> collectValues() {
ImmutableList<Protoclass> protoclasses = collectProtoclasses();
Map<DeclaringType, ValueType> enclosingTypes = Maps.newHashMap();
ImmutableMultimap.Builder<DeclaringPackage, ValueType> builder = ImmutableMultimap.builder();
// Collect enclosing
for (Protoclass protoclass : protoclasses) {
if (protoclass.kind().isEnclosing()) {
ValueType type = composeValue(protoclass);
enclosingTypes.put(protoclass.declaringType().get(), type);
}
}
// Collect remaining and attach if nested
for (Protoclass protoclass : protoclasses) {
@Nullable ValueType current = null;
if (protoclass.kind().isNested()) {
@Nullable ValueType enclosing = enclosingTypes.get(protoclass.enclosingOf().get());
if (enclosing != null) {
current = composeValue(protoclass);
// Attach nested to enclosing
enclosing.addNested(current);
}
}
// getting the ValueType if it was alredy created and put into enclosingTypes
if (current == null && protoclass.kind().isEnclosing()) {
current = enclosingTypes.get(protoclass.declaringType().get());
}
// If none then we just create it
if (current == null) {
current = composeValue(protoclass);
}
// We put all enclosing and nested values by the package
builder.put(protoclass.packageOf(), current);
}
return builder.build();
}
Aggregations