-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9ea65a
commit 5c6df5c
Showing
30 changed files
with
530 additions
and
266 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
...utable-collections/src/main/java/pl/com/labaj/autorecord/extension/compact/Component.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...-collections/src/main/java/pl/com/labaj/autorecord/extension/compact/RecordComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package pl.com.labaj.autorecord.extension.compact; | ||
|
||
/*- | ||
* Copyright © 2023 Auto Record | ||
* | ||
* 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. | ||
*/ | ||
|
||
import javax.annotation.Nullable; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.type.DeclaredType; | ||
import javax.lang.model.type.TypeMirror; | ||
import javax.lang.model.util.Types; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static java.util.stream.Collectors.joining; | ||
import static javax.lang.model.type.TypeKind.DECLARED; | ||
import static pl.com.labaj.autorecord.extension.compact.ImmutableCollectionsExtension.COLLECTION_SUPER_TYPES; | ||
|
||
record RecordComponent(String name, boolean isNullable, String declaredType, boolean shouldBeProcessed) { | ||
|
||
static RecordComponent toExtensionRecordComponent(Types typeUtils, | ||
Set<String> knownImmutableTypes, | ||
pl.com.labaj.autorecord.context.RecordComponent component) { | ||
var isNullable = component.isAnnotatedWith(Nullable.class); | ||
|
||
var componentType = component.type(); | ||
|
||
var declaredType = getQualifiedName((DeclaredType) componentType); | ||
|
||
var shouldBeProcessed = shouldBeProcessed(typeUtils, knownImmutableTypes, componentType, declaredType); | ||
|
||
return new RecordComponent(component.name(), isNullable, declaredType, shouldBeProcessed); | ||
} | ||
|
||
private static boolean shouldBeProcessed(Types typeUtils, Set<String> knownImmutableTypes, TypeMirror componentType, String declaredClass) { | ||
if (componentType.getKind() != DECLARED) { | ||
return true; | ||
} | ||
|
||
if (knownImmutableTypes.contains(declaredClass)) { | ||
return false; | ||
} | ||
|
||
var superTypes = typeUtils.directSupertypes(componentType); | ||
var hasImmutableSuperType = superTypes.stream() | ||
.map(superType -> getQualifiedName((DeclaredType) superType)) | ||
.anyMatch(knownImmutableTypes::contains); | ||
|
||
if (hasImmutableSuperType) { | ||
return false; | ||
} | ||
|
||
return COLLECTION_SUPER_TYPES.contains(declaredClass); | ||
} | ||
|
||
private static String getQualifiedName(DeclaredType t) { | ||
return ((TypeElement) t.asElement()).getQualifiedName().toString(); | ||
} | ||
|
||
static String getComponentsDebugInfo(List<RecordComponent> recordComponents) { | ||
return recordComponents.stream() | ||
.map(RecordComponent::toString) | ||
.collect(joining("\n")); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name + " " + shouldBeProcessed + " : " + declaredType; | ||
} | ||
} |
Oops, something went wrong.