Skip to content

Commit

Permalink
Remove Java 1.2 and 1.4 checks from JavaModelUtil
Browse files Browse the repository at this point in the history
Since ECJ min supported version is 1.8 all other code mandates 1.8+ too.

Part of #1685
  • Loading branch information
akurtakov committed Dec 21, 2024
1 parent 49898f4 commit 9bb5720
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Fabrice TIERCELIN and others.
* Copyright (c) 2021, 2024 Fabrice TIERCELIN and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -23,7 +23,6 @@
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.CastExpression;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.ConditionalExpression;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.FieldAccess;
Expand All @@ -47,7 +46,6 @@
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.internal.corext.dom.InterruptibleVisitor;
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperation;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;

public abstract class AbstractPrimitiveRatherThanWrapperFinder extends ASTVisitor {
protected List<CompilationUnitRewriteOperation> fResult;
Expand Down Expand Up @@ -187,7 +185,7 @@ public boolean visit(final VariableDeclarationStatement visited) {
varOccurrenceVisitor.getToStringMethods(),
varOccurrenceVisitor.getCompareToMethods(),
varOccurrenceVisitor.getPrimitiveValueMethods(),
getParsingMethodName(getWrapperFullyQualifiedName(), (CompilationUnit) visited.getRoot())));
getParsingMethodName(getWrapperFullyQualifiedName())));
return false;
}
}
Expand Down Expand Up @@ -259,7 +257,7 @@ private boolean canReturnPrimitiveInstead(final Expression expression) {

if (methodInvocation != null) {
return ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", getPrimitiveTypeName()) //$NON-NLS-1$
|| getParsingMethodName(getWrapperFullyQualifiedName(), (CompilationUnit) expression.getRoot()) != null
|| getParsingMethodName(getWrapperFullyQualifiedName()) != null
&& (
ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", String.class.getCanonicalName()) //$NON-NLS-1$
|| ASTNodes.usesGivenSignature(methodInvocation, getWrapperFullyQualifiedName(), "valueOf", String.class.getCanonicalName(), int.class.getSimpleName()) //$NON-NLS-1$
Expand All @@ -280,8 +278,8 @@ private boolean canReturnPrimitiveInstead(final Expression expression) {
return false;
}

private String getParsingMethodName(final String wrapperFullyQualifiedName, final CompilationUnit compilationUnit) {
if (Boolean.class.getCanonicalName().equals(wrapperFullyQualifiedName) && JavaModelUtil.is50OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
private String getParsingMethodName(final String wrapperFullyQualifiedName) {
if (Boolean.class.getCanonicalName().equals(wrapperFullyQualifiedName)) {
return "parseBoolean"; //$NON-NLS-1$
}

Expand All @@ -293,11 +291,11 @@ private String getParsingMethodName(final String wrapperFullyQualifiedName, fina
return "parseLong"; //$NON-NLS-1$
}

if (Double.class.getCanonicalName().equals(wrapperFullyQualifiedName) && JavaModelUtil.is1d2OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
if (Double.class.getCanonicalName().equals(wrapperFullyQualifiedName)) {
return "parseDouble"; //$NON-NLS-1$
}

if (Float.class.getCanonicalName().equals(wrapperFullyQualifiedName) && JavaModelUtil.is1d2OrHigher(compilationUnit.getJavaElement().getJavaProject())) {
if (Float.class.getCanonicalName().equals(wrapperFullyQualifiedName)) {
return "parseFloat"; //$NON-NLS-1$
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

import org.eclipse.core.runtime.CoreException;
Expand All @@ -36,7 +35,6 @@
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.OrderedInfixExpression;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;

import org.eclipse.jdt.ui.cleanup.ICleanUpFix;

Expand All @@ -63,10 +61,7 @@ public boolean visit(final InfixExpression visited) {
&& literalValue.compareTo(0L) != 0
&& comparisonMI.getExpression() != null
&& !ASTNodes.is(comparisonMI.getExpression(), ThisExpression.class)
&& (ASTNodes.usesGivenSignature(comparisonMI, Comparable.class.getCanonicalName(), "compareTo", Object.class.getCanonicalName()) //$NON-NLS-1$
|| ASTNodes.usesGivenSignature(comparisonMI, Comparator.class.getCanonicalName(), "compare", Object.class.getCanonicalName(), Object.class.getCanonicalName()) //$NON-NLS-1$
|| JavaModelUtil.is1d2OrHigher(((CompilationUnit) visited.getRoot()).getJavaElement().getJavaProject())
&& ASTNodes.usesGivenSignature(comparisonMI, String.class.getCanonicalName(), "compareToIgnoreCase", String.class.getCanonicalName()))) { //$NON-NLS-1$
&& ASTNodes.usesGivenSignature(comparisonMI, String.class.getCanonicalName(), "compareToIgnoreCase", String.class.getCanonicalName())) { //$NON-NLS-1$
if (literalValue.compareTo(0L) < 0) {
if (InfixExpression.Operator.EQUALS.equals(orderedCondition.getOperator())) {
fResult.add(new StandardComparisonFixOperation(visited, comparisonMI, InfixExpression.Operator.LESS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,14 +790,6 @@ public static boolean isVersionLessThan(String version1, String version2) {
}


public static boolean is1d2OrHigher(String compliance) {
return !isVersionLessThan(compliance, JavaCore.VERSION_1_2);
}

public static boolean is40OrHigher(String compliance) {
return !isVersionLessThan(compliance, JavaCore.VERSION_1_4);
}

public static boolean is50OrHigher(String compliance) {
return !isVersionLessThan(compliance, JavaCore.VERSION_1_5);
}
Expand Down Expand Up @@ -874,26 +866,6 @@ public static boolean is23OrHigher(String compliance) {
return !isVersionLessThan(compliance, JavaCore.VERSION_23);
}

/**
* Checks if the given project or workspace has source compliance 1.2 or greater.
*
* @param project the project to test or <code>null</code> to test the workspace settings
* @return <code>true</code> if the given project or workspace has source compliance 1.2 or greater.
*/
public static boolean is1d2OrHigher(IJavaProject project) {
return is1d2OrHigher(getSourceCompliance(project));
}

/**
* Checks if the given project or workspace has source compliance 1.4 or greater.
*
* @param project the project to test or <code>null</code> to test the workspace settings
* @return <code>true</code> if the given project or workspace has source compliance 1.4 or greater.
*/
public static boolean is1d4OrHigher(IJavaProject project) {
return is40OrHigher(getSourceCompliance(project));
}

/**
* Checks if the given project or workspace has source compliance 1.5 or greater.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021 Fabrice TIERCELIN and others.
* Copyright (c) 2021, 2024 Fabrice TIERCELIN and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -23,7 +23,6 @@
import org.eclipse.text.edits.TextEditGroup;

import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
Expand All @@ -40,7 +39,6 @@
import org.eclipse.jdt.internal.corext.fix.CompilationUnitRewriteOperationsFixCore.CompilationUnitRewriteOperationWithSourceRange;
import org.eclipse.jdt.internal.corext.fix.LinkedProposalModelCore;
import org.eclipse.jdt.internal.corext.refactoring.structure.CompilationUnitRewrite;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;

import org.eclipse.jdt.ui.cleanup.CleanUpRequirements;
import org.eclipse.jdt.ui.cleanup.ICleanUpFix;
Expand Down Expand Up @@ -124,7 +122,7 @@ public boolean visit(final MethodInvocation visited) {
return false;
}

String parsingMethodName= getParsingMethodName(canonicalName, wrapperClass.getSimpleName(), visited);
String parsingMethodName= getParsingMethodName(canonicalName, wrapperClass.getSimpleName());

if (parsingMethodName != null
&& isValueOfString(visited, canonicalName)) {
Expand All @@ -139,7 +137,7 @@ && isValueOfString(visited, canonicalName)) {
if (typeBinding != null
&& visited.arguments().isEmpty()) {
String primitiveValueMethodName= getPrimitiveValueMethodName(typeBinding.getQualifiedName());
String parsingMethodName= getParsingMethodName(typeBinding.getQualifiedName(), typeBinding.getName(), visited);
String parsingMethodName= getParsingMethodName(typeBinding.getQualifiedName(), typeBinding.getName());

if (primitiveValueMethodName != null
&& primitiveValueMethodName.equals(methodName)
Expand Down Expand Up @@ -185,17 +183,15 @@ private String getPrimitiveValueMethodName(final String wrapperFullyQualifiedNam
return null;
}

private String getParsingMethodName(final String wrapperFullyQualifiedName, final String wrapperSimpleName, final MethodInvocation visited) {
private String getParsingMethodName(final String wrapperFullyQualifiedName, final String wrapperSimpleName) {
if (Integer.class.getCanonicalName().equals(wrapperFullyQualifiedName)) {
return "parseInt"; //$NON-NLS-1$
}

IJavaProject javaProject= ((CompilationUnit) visited.getRoot()).getJavaElement().getJavaProject();

if ((Boolean.class.getCanonicalName().equals(wrapperFullyQualifiedName) && JavaModelUtil.is50OrHigher(javaProject))
if (Boolean.class.getCanonicalName().equals(wrapperFullyQualifiedName)
|| Long.class.getCanonicalName().equals(wrapperFullyQualifiedName)
|| (Double.class.getCanonicalName().equals(wrapperFullyQualifiedName) && JavaModelUtil.is1d2OrHigher(javaProject))
|| (Float.class.getCanonicalName().equals(wrapperFullyQualifiedName) && JavaModelUtil.is1d2OrHigher(javaProject))
|| Double.class.getCanonicalName().equals(wrapperFullyQualifiedName)
|| Float.class.getCanonicalName().equals(wrapperFullyQualifiedName)
|| Short.class.getCanonicalName().equals(wrapperFullyQualifiedName)
|| Byte.class.getCanonicalName().equals(wrapperFullyQualifiedName)) {
return "parse" + wrapperSimpleName; //$NON-NLS-1$
Expand Down

0 comments on commit 9bb5720

Please sign in to comment.