Skip to content

Commit 30ba99f

Browse files
committed
Replace getEntity call of MoveToClassRefactoring by getEntityOrThrow where necessary (same with getTarget).
1 parent f22a07c commit 30ba99f

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

core/src/main/java/org/jetbrains/research/groups/ml_methods/refactoring/MoveToClassRefactoring.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ public MoveToClassRefactoring(
5555
* Returns class in which entity is placed in this refactoring
5656
*/
5757
public @NotNull PsiClass getTargetClassOrThrow() {
58-
return getTargetClass().orElseThrow(() ->
58+
return Optional.ofNullable(targetClass.getElement()).orElseThrow(() ->
5959
new IllegalStateException("Cannot get target class. Reference is invalid."));
6060
}
6161

6262
public @NotNull PsiMember getEntityOrThrow() {
63-
return getEntity().orElseThrow(() ->
63+
return Optional.ofNullable(entity.getElement()).orElseThrow(() ->
6464
new IllegalStateException("Cannot get entity. Reference is invalid."));
6565
}
6666

core/src/main/java/org/jetbrains/research/groups/ml_methods/utils/RefactoringUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static CalculatedRefactoring intersect(List<CalculatedRefactoring> refac
7272
public static List<CalculatedRefactoring> combine(Collection<List<CalculatedRefactoring>> refactorings) {
7373
return refactorings.stream()
7474
.flatMap(List::stream)
75-
.collect(Collectors.groupingBy(it -> it.getRefactoring().getEntity(), Collectors.toList()))
75+
.collect(Collectors.groupingBy(it -> it.getRefactoring().getEntityOrThrow(), Collectors.toList()))
7676
.entrySet().stream()
7777
.map(entry -> combine(entry.getValue(), refactorings.size()))
7878
.filter(Objects::nonNull)

features-extraction/src/main/java/org/jetbrains/research/groups/ml_methods/extraction/FeaturesExtractionApplicationStarter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void main(String[] args) {
8888
refactorings.forEach(refactoring ->
8989
LOGGER.info(
9090
refactoring.getMethod() + "->" +
91-
refactoring.getTargetClass() + System.lineSeparator() +
91+
refactoring.getTargetClassOrThrow() + System.lineSeparator() +
9292
extractMethodDeclaration(refactoring.getMethodOrThrow()))
9393
);
9494

features-extraction/src/main/java/org/jetbrains/research/groups/ml_methods/extraction/FormatterApplicationStarter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void main(String[] args) {
9292
refactorings.forEach(refactoring ->
9393
LOGGER.info(
9494
refactoring.getMethod() + "->" +
95-
refactoring.getTargetClass() + System.lineSeparator() +
95+
refactoring.getTargetClassOrThrow() + System.lineSeparator() +
9696
extractMethodDeclaration(refactoring.getMethodOrThrow()))
9797
);
9898
writer.write(refactorings, out);

src/main/java/org/jetbrains/research/groups/ml_methods/ui/RefactoringsApplier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static Map<CalculatedRefactoring, String> getWarnings(List<CalculatedRefactoring
8686

8787
private static boolean checkValid(Collection<MoveToClassRefactoring> refactorings) {
8888
final long uniqueUnits = refactorings.stream()
89-
.map(MoveToClassRefactoring::getEntity)
89+
.map(MoveToClassRefactoring::getEntityOrThrow)
9090
.distinct()
9191
.count();
9292
return uniqueUnits == refactorings.size();

0 commit comments

Comments
 (0)