Skip to content

Commit

Permalink
Fix logic per suggestions in PR
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohnstn committed Oct 17, 2024
1 parent 206e0ae commit 0c21872
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.eclipse.jdt.internal.compiler.ast.TypeReference.AnnotationPosition;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.StringConstant;
import org.eclipse.jdt.internal.compiler.lookup.*;

Expand Down Expand Up @@ -572,17 +573,14 @@ private boolean sinceValueUnreached(Binding binding, Scope scope) {
}
AnnotationBinding[] annotations = binding.getAnnotations();
for (AnnotationBinding annotation : annotations) {
if (annotation != null && String.valueOf(annotation.getAnnotationType().readableName()).equals("java.lang.Deprecated")) { //$NON-NLS-1$
if (annotation != null && annotation.getAnnotationType().id == TypeIds.T_JavaLangDeprecated) {
ElementValuePair[] pairs = annotation.getElementValuePairs();
for (ElementValuePair pair : pairs) {
if (String.valueOf(pair.getName()).equals("since")) { //$NON-NLS-1$
if (CharOperation.equals(pair.getName(), TypeConstants.SINCE)) {
if (pair.getValue() instanceof StringConstant strConstant) {
try {
String value = strConstant.stringValue();
int sinceValue = Integer.parseInt(value);
// As long as the AST levels and ClassFileConstants.MAJOR_VERSION grow simultaneously,
// we can use the offset of +44 to compute the Major version from the given AST Level
long sinceLevel = ClassFileConstants.getComplianceLevelForJavaVersion(sinceValue + 44);
long sinceLevel = CompilerOptions.versionToJdkLevel(value);
long complianceLevel = scope.compilerOptions().complianceLevel;
if (complianceLevel < sinceLevel) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import junit.framework.Test;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;

Expand Down Expand Up @@ -914,12 +915,7 @@ public void testBug533063_2() throws Exception {
runner.runWarningTest();
}
public void testBug534304_1() throws Exception {
Map<String, String> options= getCompilerOptions();
String compliance= options.get(CompilerOptions.OPTION_Compliance);
if (compliance.equals(CompilerOptions.VERSION_9) ||
compliance.equals(CompilerOptions.VERSION_10) ||
compliance.equals(CompilerOptions.VERSION_11) ||
compliance.equals(CompilerOptions.VERSION_12)) {
if (this.complianceLevel < ClassFileConstants.JDK13) {
return;
}
runNegativeTest(
Expand Down Expand Up @@ -962,12 +958,7 @@ public void testBug534304_1() throws Exception {
"----------\n");
}
public void testBug534304_2() throws Exception {
Map<String, String> options= getCompilerOptions();
String compliance= options.get(CompilerOptions.OPTION_Compliance);
if (compliance.equals(CompilerOptions.VERSION_9) ||
compliance.equals(CompilerOptions.VERSION_10) ||
compliance.equals(CompilerOptions.VERSION_11) ||
compliance.equals(CompilerOptions.VERSION_12)) {
if (this.complianceLevel < ClassFileConstants.JDK13) {
runNegativeTest(
new String[] {
"p1/C1.java",
Expand Down

0 comments on commit 0c21872

Please sign in to comment.