Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
[eclipse/xtext-core#517] Moved Class File Constant Calculation to Jav…
Browse files Browse the repository at this point in the history
…aVersion Enum

Signed-off-by: Christian Dietrich <[email protected]>
  • Loading branch information
cdietrich committed Mar 27, 2018
1 parent 925638a commit 1d1cee7
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 99 deletions.
2 changes: 1 addition & 1 deletion gradle/upstream-repositories.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repositories {
if (findProperty('useJenkinsSnapshots') == 'true') {
maven { url "http://services.typefox.io/open-source/jenkins/job/lsp4j/job/master/lastStableBuild/artifact/build/maven-repository/" }
maven { url jenkinsPipelineRepo('xtext-lib') }
maven { url jenkinsPipelineRepo('xtext-core') }
maven { url 'http://services.typefox.io/open-source/jenkins/job/xtext-core/job/cd_core_issue_517/lastSuccessfulBuild/artifact/build/maven-repository/' }
} else {
mavenLocal()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.eclipse.jdt.internal.compiler.CompilationResult
import org.eclipse.jdt.internal.compiler.Compiler
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions
import org.eclipse.jdt.internal.compiler.parser.Parser
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory
Expand Down Expand Up @@ -188,28 +187,7 @@ class JavaDerivedStateComputer {
}

protected def long toJdtVersion(JavaVersion version) {
switch (version) {
case JAVA5:
ClassFileConstants.JDK1_5
case JAVA6:
ClassFileConstants.JDK1_6
case JAVA7:
ClassFileConstants.JDK1_7
case JAVA8: {
try {
ClassFileConstants.getField('JDK1_8').getLong(null)
} catch (NoSuchFieldException e) {
ClassFileConstants.JDK1_7
}
}
case JAVA9: {
try {
ClassFileConstants.getField('JDK9').getLong(null)
} catch (NoSuchFieldException e) {
ClassFileConstants.JDK1_7
}
}
}
version.toJdtClassFileConstant
}

protected def ClassLoader getClassLoader(Resource it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.parser.Parser;
Expand Down Expand Up @@ -316,53 +315,7 @@ protected CompilerOptions getCompilerOptions(final JavaConfig javaConfig) {
}

protected long toJdtVersion(final JavaVersion version) {
try {
long _switchResult = (long) 0;
if (version != null) {
switch (version) {
case JAVA5:
_switchResult = ClassFileConstants.JDK1_5;
break;
case JAVA6:
_switchResult = ClassFileConstants.JDK1_6;
break;
case JAVA7:
_switchResult = ClassFileConstants.JDK1_7;
break;
case JAVA8:
long _xtrycatchfinallyexpression = (long) 0;
try {
_xtrycatchfinallyexpression = ClassFileConstants.class.getField("JDK1_8").getLong(null);
} catch (final Throwable _t) {
if (_t instanceof NoSuchFieldException) {
_xtrycatchfinallyexpression = ClassFileConstants.JDK1_7;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
_switchResult = _xtrycatchfinallyexpression;
break;
case JAVA9:
long _xtrycatchfinallyexpression_1 = (long) 0;
try {
_xtrycatchfinallyexpression_1 = ClassFileConstants.class.getField("JDK9").getLong(null);
} catch (final Throwable _t_1) {
if (_t_1 instanceof NoSuchFieldException) {
_xtrycatchfinallyexpression_1 = ClassFileConstants.JDK1_7;
} else {
throw Exceptions.sneakyThrow(_t_1);
}
}
_switchResult = _xtrycatchfinallyexpression_1;
break;
default:
break;
}
}
return _switchResult;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
return version.toJdtClassFileConstant();
}

protected ClassLoader getClassLoader(final Resource it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.eclipse.jdt.core.compiler.CategorizedProblem
import org.eclipse.jdt.internal.compiler.Compiler
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit
import org.eclipse.jdt.internal.compiler.env.INameEnvironment
Expand All @@ -29,7 +28,6 @@ import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend.lib.annotations.Data
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor
import org.eclipse.xtext.util.JavaVersion
import org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler.Result

/**
*
Expand Down Expand Up @@ -152,13 +150,7 @@ class InMemoryJavaCompiler {
}

private def long toClassFmt(JavaVersion version) {
switch(version) {
case JAVA5: return ClassFileConstants.JDK1_5
case JAVA6: return ClassFileConstants.JDK1_6
case JAVA7: return ClassFileConstants.JDK1_7
case JAVA8: return ((ClassFileConstants.MAJOR_VERSION_1_7 + 1) << 16) + ClassFileConstants.MINOR_VERSION_0 // ClassFileConstants.JDK1_8
case JAVA9: return ((ClassFileConstants.MAJOR_VERSION_1_7 + 2) << 16) + ClassFileConstants.MINOR_VERSION_0 // ClassFileConstants.JDK1_9
}
return version.toJdtClassFileConstant
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
Expand Down Expand Up @@ -243,23 +242,7 @@ public long setJavaVersion(final JavaVersion javaVersion) {
}

private long toClassFmt(final JavaVersion version) {
if (version != null) {
switch (version) {
case JAVA5:
return ClassFileConstants.JDK1_5;
case JAVA6:
return ClassFileConstants.JDK1_6;
case JAVA7:
return ClassFileConstants.JDK1_7;
case JAVA8:
return (((ClassFileConstants.MAJOR_VERSION_1_7 + 1) << 16) + ClassFileConstants.MINOR_VERSION_0);
case JAVA9:
return (((ClassFileConstants.MAJOR_VERSION_1_7 + 2) << 16) + ClassFileConstants.MINOR_VERSION_0);
default:
break;
}
}
return 0;
return version.toJdtClassFileConstant();
}

/**
Expand Down

0 comments on commit 1d1cee7

Please sign in to comment.