Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration cs, Execution
}
// If the class already has method, don't make any changes to it.
if (classDecl.getBody().getStatements().stream()
.filter(statement -> statement instanceof J.MethodDeclaration)
.filter(J.MethodDeclaration.class::isInstance)
.map(J.MethodDeclaration.class::cast)
.anyMatch(methodDeclaration -> methodMatcher.matches(methodDeclaration, classDecl))) {
return classDecl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
boolean hasBeanDiscoveryMode = false;
String idealVersion = null;
for (Xml.Attribute attribute : t.getAttributes()) {
if (attribute.getKeyAsString().equals("bean-discovery-mode")) {
if ("bean-discovery-mode".equals(attribute.getKeyAsString())) {
hasBeanDiscoveryMode = true;
} else if (attribute.getKeyAsString().endsWith("schemaLocation")) {
String schemaLocation = attribute.getValueAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public J visitTypeCast(J.TypeCast typeCast, ExecutionContext ctx) {
String fullyQualifiedName = ((JavaType.FullyQualified) elementType).getFullyQualifiedName();
J.ArrayType castType = (J.ArrayType) typeCast.getClazz().getTree();

if (fullyQualifiedName.equals("java.lang.Object") && !(castType.getElementType() instanceof J.ArrayType)) {
if ("java.lang.Object".equals(fullyQualifiedName) && !(castType.getElementType() instanceof J.ArrayType)) {
// we don't need to fix this case because toArray() does return Object[] type
return typeCast;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ class SharedDataHolder {
// both shared-cache-mode and javax.persistence.sharedCache.mode are present
// None of the properties/elements are present
public boolean shouldFlag() {
return (openJPACacheProperty != null ||
return openJPACacheProperty != null ||
((sharedCacheModeElement != null && sharedCacheModeElementUnspecified) || (sharedCacheModeProperty != null && sharedCacheModePropertyUnspecified)) ||
(sharedCacheModeElement != null && sharedCacheModeProperty != null) ||
(sharedCacheModeElement == null && sharedCacheModeProperty == null && eclipselinkCacheProperty == null));
(sharedCacheModeElement == null && sharedCacheModeProperty == null && eclipselinkCacheProperty == null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public J visitInstanceOf(J.InstanceOf instOf, ExecutionContext ctx) {
J.InstanceOf instanceOfVar = (J.InstanceOf) super.visitInstanceOf(instOf, ctx);

if (instanceOfVar.getExpression() instanceof J.MethodInvocation) {
J.MethodInvocation mi = ((J.MethodInvocation) instanceOfVar.getExpression());
J.MethodInvocation mi = (J.MethodInvocation) instanceOfVar.getExpression();
if (methodMatcherGetPeer.matches(mi) && TypeUtils.isAssignableTo(lightweightPeerFQCN, ((TypedTree) instanceOfVar.getClazz()).getType())) {
mi = (J.MethodInvocation) new ChangeMethodName(getPeerMethodPattern, "isLightweight", true, null)
.getVisitor().visit(mi, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext ctx) {
// noinspection Convert2MethodRef
JavaTemplate.Builder encoderTemplate = useMimeCoder ?
Semantics.expression(this, "getMimeEncoder", () -> Base64.getMimeEncoder()) :
Semantics.expression(this, "getEncoder", () -> Base64.getEncoder());
Semantics.expression(this, "getEncoder", Base64::getEncoder);
return encoderTemplate
.build()
.apply(updateCursor(c), c.getCoordinates().replace());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ public Duration getEstimatedEffortPerOccurrence() {
public TreeVisitor<?, ExecutionContext> getVisitor() {
TreeVisitor<?, ExecutionContext> check = Preconditions.and(new UsesJavaVersion<>(9),
new UsesType<>(guavaType, false));
final MethodMatcher IMMUTABLE_MATCHER = new MethodMatcher(guavaType + " of(..)");
final MethodMatcher immutableMatcher = new MethodMatcher(guavaType + " of(..)");
return Preconditions.check(check, new JavaVisitor<ExecutionContext>() {
@Override
public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx) {
J.MethodInvocation mi = (J.MethodInvocation) super.visitMethodInvocation(method, ctx);
if (!IMMUTABLE_MATCHER.matches(mi) || !isParentTypeDownCast(mi)) {
if (!immutableMatcher.matches(mi) || !isParentTypeDownCast(mi)) {
return mi;
}
maybeRemoveImport(guavaType);
Expand Down Expand Up @@ -198,7 +198,7 @@ private boolean isParentTypeDownCast(MethodCall immutableMethod) {
int index = 0;
if (c.getConstructorType() != null) {
for (Expression argument : c.getArguments()) {
if (IMMUTABLE_MATCHER.matches(argument)) {
if (immutableMatcher.matches(argument)) {
break;
}
index++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu

maybeRemoveImport("com.google.common.base.Joiner");

return JavaTemplate.<J.MethodInvocation>apply(
return JavaTemplate.apply(
"String.join(#{any(java.lang.CharSequence)}",
getCursor(),
mi.getCoordinates().replace(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex

// Exit if class already has default no-arg constructor
if (classDecl.getBody().getStatements().stream()
.filter(statement -> statement instanceof J.MethodDeclaration)
.filter(J.MethodDeclaration.class::isInstance)
.map(J.MethodDeclaration.class::cast)
.filter(J.MethodDeclaration::isConstructor)
.anyMatch(constructor -> constructor.getParameters().get(0) instanceof J.Empty)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public AnnotateTypesVisitor(String annotationToBeAdded) {
String className = split[split.length - 1];
String packageName = this.annotationToBeAdded.substring(0, this.annotationToBeAdded.lastIndexOf("."));
this.annotationMatcher = new AnnotationMatcher("@" + this.annotationToBeAdded);
String interfaceAsString = String.format("package %s\npublic @interface %s {}", packageName, className);
String interfaceAsString = String.format("package %s%npublic @interface %s {}", packageName, className);
//noinspection LanguageMismatch
this.template = JavaTemplate.builder("@" + className)
.imports(this.annotationToBeAdded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ public String getDescription() {
@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
Pattern temporalPattern = Pattern.compile(".*TemporalType\\.(TIMESTAMP|DATE|TIME)");
final String JAVA_SQL_TIMESTAMP = "java.sql.Timestamp";
final String JAVA_SQL_TIME = "java.sql.Time";
final String JAVA_SQL_DATE = "java.sql.Date";
final String javaSqlTimestamp = "java.sql.Timestamp";
final String javaSqlTime = "java.sql.Time";
final String javaSqlDate = "java.sql.Date";

Set<String> javaSqlDateTimeTypes = Stream.of(
JAVA_SQL_TIMESTAMP,
JAVA_SQL_TIME,
JAVA_SQL_DATE
javaSqlTimestamp,
javaSqlTime,
javaSqlDate
).collect(Collectors.toSet());
// Combinations of TemporalType and java.sql classes that do not need removal
Map<String, String> doNotRemove = Stream.of(new String[][]{
{"DATE", JAVA_SQL_TIMESTAMP},
{"TIME", JAVA_SQL_TIMESTAMP},
{"TIMESTAMP", JAVA_SQL_DATE}
{"DATE", javaSqlTimestamp},
{"TIME", javaSqlTimestamp},
{"TIMESTAMP", javaSqlDate}
}).collect(Collectors.toMap(data -> data[0], data -> data[1]));
// TODO: maybe future recipe to handle these by creating a converter class
// https://wiki.eclipse.org/EclipseLink/Examples/JPA/Migration/OpenJPA/Mappings#.40Temporal_on_java.sql.Date.2FTime.2FTimestamp_fields
Expand All @@ -88,9 +88,9 @@ public TreeVisitor<?, ExecutionContext> getVisitor() {
Preconditions.and(
new UsesType<>("javax.persistence.Temporal", true),
Preconditions.or(
new UsesType<>(JAVA_SQL_DATE, true),
new UsesType<>(JAVA_SQL_TIME, true),
new UsesType<>(JAVA_SQL_TIMESTAMP, true)
new UsesType<>(javaSqlDate, true),
new UsesType<>(javaSqlTime, true),
new UsesType<>(javaSqlTimestamp, true)
)
),
new JavaIsoVisitor<ExecutionContext>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Javadoc visitReference(Javadoc.Reference reference, ExecutionContext ctx)
@Override
public @NonNull J visitFieldAccess(@NonNull J.FieldAccess fieldAccess, @NonNull ExecutionContext ctx) {
J.FieldAccess f = (J.FieldAccess) super.visitFieldAccess(fieldAccess, ctx);
if (TypeUtils.isOfClassType(f.getType(), JODA_DATE_TIME_ZONE) && f.getSimpleName().equals("UTC")) {
if (TypeUtils.isOfClassType(f.getType(), JODA_DATE_TIME_ZONE) && "UTC".equals(f.getSimpleName())) {
return JavaTemplate.builder("ZoneOffset.UTC")
.imports(JAVA_ZONE_OFFSET)
.build()
Expand All @@ -203,7 +203,7 @@ public Javadoc visitReference(Javadoc.Reference reference, ExecutionContext ctx)
}
}

JavaType.FullyQualified jodaType = ((JavaType.Class) ident.getType());
JavaType.FullyQualified jodaType = (JavaType.Class) ident.getType();
JavaType.FullyQualified fqType = TimeClassMap.getJavaTimeType(jodaType.getFullyQualifiedName());
if (fqType == null) {
return ident;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public class AbstractDateTimeTemplates implements Templates {
private final JavaTemplate toStringTemplate = JavaTemplate.builder("#{any(" + JAVA_DATE_TIME + ")}.toString()").build();

@Getter
private final List<MethodTemplate> templates = new ArrayList<MethodTemplate>() {
{
add(new MethodTemplate(getDayOfMonth, getDayOfMonthTemplate));
add(new MethodTemplate(getDayOfWeek, getDayOfWeekTemplate));
add(new MethodTemplate(getHourOfDay, getHourOfDayTemplate));
add(new MethodTemplate(getMillisOfSecond, getMillisOfSecondTemplate));
add(new MethodTemplate(getMinuteOfDay, getMinuteOfDayTemplate));
add(new MethodTemplate(getMinuteOfHour, getMinuteOfHourTemplate));
add(new MethodTemplate(getMonthOfYear, getMonthOfYearTemplate));
add(new MethodTemplate(getSecondOfDay, getSecondOfDayTemplate));
add(new MethodTemplate(getSecondOfMinute, getSecondOfMinuteTemplate));
add(new MethodTemplate(getWeekOfWeekyear, getWeekOfWeekyearTemplate));
add(new MethodTemplate(toString, toStringTemplate));
}
};
private final List<MethodTemplate> templates;
{
templates = new ArrayList<>();
templates.add(new MethodTemplate(getDayOfMonth, getDayOfMonthTemplate));
templates.add(new MethodTemplate(getDayOfWeek, getDayOfWeekTemplate));
templates.add(new MethodTemplate(getHourOfDay, getHourOfDayTemplate));
templates.add(new MethodTemplate(getMillisOfSecond, getMillisOfSecondTemplate));
templates.add(new MethodTemplate(getMinuteOfDay, getMinuteOfDayTemplate));
templates.add(new MethodTemplate(getMinuteOfHour, getMinuteOfHourTemplate));
templates.add(new MethodTemplate(getMonthOfYear, getMonthOfYearTemplate));
templates.add(new MethodTemplate(getSecondOfDay, getSecondOfDayTemplate));
templates.add(new MethodTemplate(getSecondOfMinute, getSecondOfMinuteTemplate));
templates.add(new MethodTemplate(getWeekOfWeekyear, getWeekOfWeekyearTemplate));
templates.add(new MethodTemplate(toString, toStringTemplate));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public class AbstractDurationTemplates implements Templates {
private final JavaTemplate toPeriodTemplate = JavaTemplate.builder("#{any(" + JAVA_DURATION + ")}.toPeriod()").build();

@Getter
private final List<MethodTemplate> templates = new ArrayList<MethodTemplate>() {
{
add(new MethodTemplate(isLongerThan, isLongerThanTemplate));
add(new MethodTemplate(toPeriod, toPeriodTemplate));
}
};
private final List<MethodTemplate> templates;
{
templates = new ArrayList<>();
templates.add(new MethodTemplate(isLongerThan, isLongerThanTemplate));
templates.add(new MethodTemplate(toPeriod, toPeriodTemplate));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,27 @@ public class AbstractInstantTemplates implements Templates {
private final JavaTemplate toStringFormatterTemplate = JavaTemplate.builder("#{any(" + JAVA_DATE_TIME + ")}.format(#{any(" + JAVA_TIME_FORMATTER + ")})").build();

@Getter
private final List<MethodTemplate> templates = new ArrayList<MethodTemplate>() {
{
add(new MethodTemplate(equals, equalsTemplate));
add(new MethodTemplate(getZone, getZoneTemplate));
add(new MethodTemplate(isAfterLong, isAfterLongTemplate));
add(new MethodTemplate(isAfterLong, isAfterLongTemplateWithInstant));
add(new MethodTemplate(isAfter, isAfterTemplate));
add(new MethodTemplate(isAfter, isAfterTemplateWithInstant));
add(new MethodTemplate(isBeforeLong, isBeforeLongTemplate));
add(new MethodTemplate(isBeforeLong, isBeforeLongTemplateWithInstant));
add(new MethodTemplate(isBefore, isBeforTemplate));
add(new MethodTemplate(isBefore, isBeforeTemplateWithInstant));
add(new MethodTemplate(isBeforeNow, isBeforeNowTemplate));
add(new MethodTemplate(isEqualLong, isEqualLongTemplate));
add(new MethodTemplate(isEqualReadableInstant, isEqualReadableInstantTemplate));
add(new MethodTemplate(toDate, toDateTemplate));
add(new MethodTemplate(toInstant, toInstantTemplate));
add(new MethodTemplate(toString, toStringTemplate));
add(new MethodTemplate(toStringFormatter, toStringFormatterTemplate));
}
};
private final List<MethodTemplate> templates;
{
templates = new ArrayList<>();
templates.add(new MethodTemplate(equals, equalsTemplate));
templates.add(new MethodTemplate(getZone, getZoneTemplate));
templates.add(new MethodTemplate(isAfterLong, isAfterLongTemplate));
templates.add(new MethodTemplate(isAfterLong, isAfterLongTemplateWithInstant));
templates.add(new MethodTemplate(isAfter, isAfterTemplate));
templates.add(new MethodTemplate(isAfter, isAfterTemplateWithInstant));
templates.add(new MethodTemplate(isBeforeLong, isBeforeLongTemplate));
templates.add(new MethodTemplate(isBeforeLong, isBeforeLongTemplateWithInstant));
templates.add(new MethodTemplate(isBefore, isBeforTemplate));
templates.add(new MethodTemplate(isBefore, isBeforeTemplateWithInstant));
templates.add(new MethodTemplate(isBeforeNow, isBeforeNowTemplate));
templates.add(new MethodTemplate(isEqualLong, isEqualLongTemplate));
templates.add(new MethodTemplate(isEqualReadableInstant, isEqualReadableInstantTemplate));
templates.add(new MethodTemplate(toDate, toDateTemplate));
templates.add(new MethodTemplate(toInstant, toInstantTemplate));
templates.add(new MethodTemplate(toString, toStringTemplate));
templates.add(new MethodTemplate(toStringFormatter, toStringFormatterTemplate));
}

@Override
public boolean matchesMethodCall(MethodCall method, MethodTemplate template) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public class AbstractIntervalTemplates implements Templates {
.build();

@Getter
private final List<MethodTemplate> templates = new ArrayList<MethodTemplate>() {
{
add(new MethodTemplate(getStart, getStartTemplate));
add(new MethodTemplate(getEnd, getEndTemplate));
add(new MethodTemplate(toDuration, toDurationTemplate));
add(new MethodTemplate(toDurationMillis, toDurationMillisTemplate));
add(new MethodTemplate(contains, containsTemplate));
}
};
private final List<MethodTemplate> templates;
{
templates = new ArrayList<>();
templates.add(new MethodTemplate(getStart, getStartTemplate));
templates.add(new MethodTemplate(getEnd, getEndTemplate));
templates.add(new MethodTemplate(toDuration, toDurationTemplate));
templates.add(new MethodTemplate(toDurationMillis, toDurationMillisTemplate));
templates.add(new MethodTemplate(contains, containsTemplate));
}
}
Loading
Loading