Skip to content

Commit 2db2e25

Browse files
committed
Replace getMethod and getField calls as well. Also rename methods.
1 parent 30ba99f commit 2db2e25

File tree

16 files changed

+55
-55
lines changed

16 files changed

+55
-55
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@ public boolean isMoveFieldRefactoring() {
4343
/**
4444
* Returns field that is moved in this refactoring.
4545
*/
46-
public @NotNull Optional<PsiField> getField() {
46+
public @NotNull Optional<PsiField> getOptionalField() {
4747
return Optional.ofNullable(field.getElement());
4848
}
4949

5050
/**
5151
* Returns field that is moved in this refactoring.
5252
*/
53-
public @NotNull PsiField getFieldOrThrow() {
54-
return getField().orElseThrow(() ->
53+
public @NotNull PsiField getField() {
54+
return Optional.ofNullable(field.getElement()).orElseThrow(() ->
5555
new IllegalStateException("Cannot get field. Reference is invalid."));
5656
}
5757

5858
@Override
59-
public @Nullable Optional<PsiClass> getContainingClass() {
59+
public @Nullable Optional<PsiClass> getOptionalContainingClass() {
6060
return field.getElement() == null ?
6161
Optional.empty() : Optional.ofNullable(field.getElement().getContainingClass());
6262
}
6363

6464
@NotNull
6565
@Override
66-
public PsiClass getContainingClassOrThrow() {
67-
return Optional.ofNullable(getFieldOrThrow().getContainingClass())
66+
public PsiClass getContainingClass() {
67+
return Optional.ofNullable(getField().getContainingClass())
6868
.orElseThrow(() -> new IllegalStateException("No containing class."));
6969
}
7070

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ public boolean isMoveFieldRefactoring() {
4444
/**
4545
* Returns method that is moved in this refactoring.
4646
*/
47-
public @NotNull Optional<PsiMethod> getMethod() {
47+
public @NotNull Optional<PsiMethod> getOptionalMethod() {
4848
return Optional.ofNullable(method.getElement());
4949
}
5050

5151
/**
5252
* Returns method that is moved in this refactoring.
5353
*/
54-
public @NotNull PsiMethod getMethodOrThrow() {
55-
return getMethod().orElseThrow(() ->
54+
public @NotNull PsiMethod getMethod() {
55+
return Optional.ofNullable(method.getElement()).orElseThrow(() ->
5656
new IllegalStateException("Cannot get method. Reference is invalid."));
5757
}
5858

5959
@Override
60-
public @Nullable Optional<PsiClass> getContainingClass() {
60+
public @Nullable Optional<PsiClass> getOptionalContainingClass() {
6161
return method.getElement() == null ?
6262
Optional.empty() : Optional.ofNullable(method.getElement().getContainingClass());
6363
}
6464

6565
@NotNull
6666
@Override
67-
public PsiClass getContainingClassOrThrow() {
68-
return Optional.ofNullable(getMethodOrThrow().getContainingClass())
67+
public PsiClass getContainingClass() {
68+
return Optional.ofNullable(getMethod().getContainingClass())
6969
.orElseThrow(() -> new IllegalStateException("No containing class."));
7070
}
7171

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,33 @@ public MoveToClassRefactoring(
3333
/**
3434
* Returns class which contains moved entity.
3535
*/
36-
public abstract @Nullable Optional<PsiClass> getContainingClass();
36+
public abstract @Nullable Optional<PsiClass> getOptionalContainingClass();
3737

3838
/**
3939
* Returns class which contains moved entity.
4040
*/
41-
public abstract @NotNull PsiClass getContainingClassOrThrow();
41+
public abstract @NotNull PsiClass getContainingClass();
4242

4343
/**
4444
* Returns class in which entity is placed in this refactoring
4545
*/
46-
public @NotNull Optional<PsiClass> getTargetClass() {
46+
public @NotNull Optional<PsiClass> getOptionalTargetClass() {
4747
return Optional.ofNullable(targetClass.getElement());
4848
}
4949

50-
public @NotNull Optional<PsiMember> getEntity() {
50+
public @NotNull Optional<PsiMember> getOptionalEntity() {
5151
return Optional.ofNullable(entity.getElement());
5252
}
5353

5454
/**
5555
* Returns class in which entity is placed in this refactoring
5656
*/
57-
public @NotNull PsiClass getTargetClassOrThrow() {
57+
public @NotNull PsiClass getTargetClass() {
5858
return Optional.ofNullable(targetClass.getElement()).orElseThrow(() ->
5959
new IllegalStateException("Cannot get target class. Reference is invalid."));
6060
}
6161

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private RefactoringUtil() {
2727
public static List<CalculatedRefactoring> filter(List<CalculatedRefactoring> refactorings) {
2828
final List<CalculatedRefactoring> validRefactorings = new ArrayList<>();
2929
for (CalculatedRefactoring refactoring : refactorings) {
30-
final PsiElement element = refactoring.getRefactoring().getEntityOrThrow();
30+
final PsiElement element = refactoring.getRefactoring().getEntity();
3131
final boolean isMovable = ApplicationManager.getApplication()
3232
.runReadAction((Computable<Boolean>) () -> isMovable(element));
3333
if (isMovable) {
@@ -52,9 +52,9 @@ public static List<CalculatedRefactoring> intersect(Collection<List<CalculatedRe
5252
return refactorings.stream()
5353
.flatMap(List::stream)
5454
.collect(Collectors.groupingBy(refactoring ->
55-
getHumanReadableName(refactoring.getRefactoring().getEntityOrThrow()) +
55+
getHumanReadableName(refactoring.getRefactoring().getEntity()) +
5656
"&" +
57-
getHumanReadableName(refactoring.getRefactoring().getTargetClassOrThrow()),
57+
getHumanReadableName(refactoring.getRefactoring().getTargetClass()),
5858
Collectors.toList()))
5959
.values().stream()
6060
.filter(collection -> collection.size() == refactorings.size())
@@ -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().getEntityOrThrow(), Collectors.toList()))
75+
.collect(Collectors.groupingBy(it -> it.getRefactoring().getEntity(), Collectors.toList()))
7676
.entrySet().stream()
7777
.map(entry -> combine(entry.getValue(), refactorings.size()))
7878
.filter(Objects::nonNull)

core/src/test/java/org/jetbrains/research/groups/ml_methods/algorithm/TestCasesCheckers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class TestCasesCheckers {
2323

2424
private static Map<String, String> toMap(List<CalculatedRefactoring> refactorings) {
2525
return refactorings.stream().collect(Collectors.toMap(it ->
26-
getHumanReadableName(it.getRefactoring().getEntityOrThrow()),
27-
it -> getHumanReadableName(it.getRefactoring().getTargetClassOrThrow())));
26+
getHumanReadableName(it.getRefactoring().getEntity()),
27+
it -> getHumanReadableName(it.getRefactoring().getTargetClass())));
2828
}
2929

3030
@NotNull

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

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

9595
List<FeatureVector> vectors;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public void main(String[] args) {
9292
refactorings.forEach(refactoring ->
9393
LOGGER.info(
9494
refactoring.getMethod() + "->" +
95-
refactoring.getTargetClassOrThrow() + System.lineSeparator() +
96-
extractMethodDeclaration(refactoring.getMethodOrThrow()))
95+
refactoring.getTargetClass() + System.lineSeparator() +
96+
extractMethodDeclaration(refactoring.getMethod()))
9797
);
9898
writer.write(refactorings, out);
9999
} catch (Throwable throwable) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ private MoveMethodFeaturesExtractor() {}
4949
List<FeatureVector> vectors = new ArrayList<>();
5050
for (MoveMethodRefactoring refactoring : refactorings) {
5151
MethodInfo methodInfo =
52-
repository.getMethodInfo(refactoring.getMethodOrThrow()).orElseThrow(
52+
repository.getMethodInfo(refactoring.getMethod()).orElseThrow(
5353
() -> new IllegalArgumentException(
5454
"Refactoring of method which was not found in scope"
5555
)
5656
);
5757

58-
vectors.add(extractor.extract(methodInfo, refactoring.getTargetClassOrThrow()));
58+
vectors.add(extractor.extract(methodInfo, refactoring.getTargetClass()));
5959
}
6060

6161
return vectors;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public RefactoringTextRepresentation(String sourceClassQualifiedName, String met
4444
}
4545

4646
public RefactoringTextRepresentation(MoveMethodRefactoring refactoring) {
47-
PsiMethod method = refactoring.getMethodOrThrow();
48-
PsiClass targetClass = refactoring.getTargetClassOrThrow();
47+
PsiMethod method = refactoring.getMethod();
48+
PsiClass targetClass = refactoring.getTargetClass();
4949
if (method.getContainingClass() == null || method.getContainingClass().getQualifiedName() == null) {
5050
String errorMessage = "Refactorings without source qualified names are not supported. " +
5151
"Problem during creating refactoring for method " + method.getName() + ".";

src/main/java/org/jetbrains/research/groups/ml_methods/intention/RefactorIntentionAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class RefactorIntentionAction extends BaseIntentionAction {
2929
@NotNull
3030
@Override
3131
public String getText() {
32-
return String.format("Move to %s", getHumanReadableName(refactoring.getTargetClassOrThrow()));
32+
return String.format("Move to %s", getHumanReadableName(refactoring.getTargetClass()));
3333
}
3434

3535
@Nls

0 commit comments

Comments
 (0)