Skip to content

Commit

Permalink
Replace JDT's ClassFileConstants.Acc* by JDK's Flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria authored and Celine committed Jul 28, 2023
1 parent bd4f6d4 commit 7cb63ef
Show file tree
Hide file tree
Showing 201 changed files with 1,853 additions and 1,108 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.compiler.batch/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-20">
<attributes>
<attribute name="module" value="true"/>
<attribute name="add-exports" value="jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED"/>
<attribute name="add-exports" value="jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.compiler.batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<release></release>
<compilerArgs>
<arg>--add-exports</arg>
<arg>jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED</arg>
<arg>jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED,jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter;
import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Commandline.Argument;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.antadapter.AntAdapterMessages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
import org.eclipse.jdt.internal.compiler.util.Messages;
import org.eclipse.jdt.internal.compiler.util.Util;

import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.jvm.ByteCodes;

/**
Expand Down Expand Up @@ -270,7 +271,7 @@ private static void createProblemType(TypeDeclaration typeDeclaration, ClassFile
MethodBinding method = methodDecl.binding;
if (method == null) continue;
if (abstractMethodsOnly) {
method.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract;
method.modifiers = Flags.PUBLIC | Flags.ABSTRACT;
}
if (method.isConstructor()) {
if (typeBinding.isInterface()) continue;
Expand Down Expand Up @@ -725,7 +726,7 @@ private void addFieldInfo(FieldBinding fieldBinding) {
int accessFlags = fieldBinding.getAccessFlags();
if (this.targetJDK < ClassFileConstants.JDK1_5) {
// pre 1.5, synthetic was an attribute, not a modifier
accessFlags &= ~ClassFileConstants.AccSynthetic;
accessFlags &= ~Flags.SYNTHETIC;
}
this.contents[this.contentsOffset++] = (byte) (accessFlags >> 8);
this.contents[this.contentsOffset++] = (byte) accessFlags;
Expand Down Expand Up @@ -795,7 +796,7 @@ public void addFieldInfos() {

private void addMissingAbstractProblemMethod(MethodDeclaration methodDeclaration, MethodBinding methodBinding, CategorizedProblem problem, CompilationResult compilationResult) {
// always clear the strictfp/native/abstract bit for a problem method
generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccNative | ClassFileConstants.AccAbstract));
generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(Flags.STRICTFP | Flags.NATIVE | Flags.ABSTRACT));
int methodAttributeOffset = this.contentsOffset;
int attributeNumber = generateMethodInfoAttributes(methodBinding);

Expand Down Expand Up @@ -899,7 +900,7 @@ public void addProblemConstructor(
}

// always clear the strictfp/native/abstract bit for a problem method
generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccNative | ClassFileConstants.AccAbstract));
generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(Flags.STRICTFP | Flags.NATIVE | Flags.ABSTRACT));
int methodAttributeOffset = this.contentsOffset;
int attributesNumber = generateMethodInfoAttributes(methodBinding);

Expand Down Expand Up @@ -982,7 +983,7 @@ public void addProblemMethod(
method.abort(ProblemSeverities.AbortType, null);
}
// always clear the strictfp/native/abstract bit for a problem method
generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccNative | ClassFileConstants.AccAbstract));
generateMethodInfoHeader(methodBinding, methodBinding.modifiers & ~(Flags.STRICTFP | Flags.NATIVE | Flags.ABSTRACT));
int methodAttributeOffset = this.contentsOffset;
int attributesNumber = generateMethodInfoAttributes(methodBinding);

Expand Down Expand Up @@ -2996,7 +2997,7 @@ private int generateModuleAttribute(ModuleDeclaration module) {
this.constantPool.literalIndexForModule(binding.moduleName);
this.contents[localContentsOffset++] = (byte) (moduleNameIndex >> 8);
this.contents[localContentsOffset++] = (byte) moduleNameIndex;
int flags = module.modifiers & ~(ClassFileConstants.AccModule);
int flags = module.modifiers & ~(Flags.ACC_MODULE);
this.contents[localContentsOffset++] = (byte) (flags >> 8);
this.contents[localContentsOffset++] = (byte) flags;
String moduleVersion = module.getModuleVersion();
Expand Down Expand Up @@ -3044,7 +3045,7 @@ private int generateModuleAttribute(ModuleDeclaration module) {
int javabase_index = this.constantPool.literalIndexForModule(javaBaseBinding.moduleName);
this.contents[localContentsOffset++] = (byte) (javabase_index >> 8);
this.contents[localContentsOffset++] = (byte) (javabase_index);
flags = ClassFileConstants.AccMandated;
flags = Flags.MANDATED;
this.contents[localContentsOffset++] = (byte) (flags >> 8);
this.contents[localContentsOffset++] = (byte) flags;
int required_version = 0;
Expand Down Expand Up @@ -3587,9 +3588,9 @@ private int generateInnerClassAttribute(int numberOfInnerClasses, ReferenceBindi
if (innerClass.isAnonymousType()) {
ReferenceBinding superClass = innerClass.superclass();
if (superClass == null || !(superClass.isEnum() && superClass.isSealed()))
accessFlags &= ~ClassFileConstants.AccFinal;
accessFlags &= ~Flags.FINAL;
} else if (innerClass.isMemberType() && innerClass.isInterface()) {
accessFlags |= ClassFileConstants.AccStatic; // implicitely static
accessFlags |= Flags.STATIC; // implicitely static
}
this.contents[localContentsOffset++] = (byte) (accessFlags >> 8);
this.contents[localContentsOffset++] = (byte) accessFlags;
Expand Down Expand Up @@ -4428,13 +4429,13 @@ public void generateMethodInfoHeader(MethodBinding methodBinding, int accessFlag
if (this.targetJDK < ClassFileConstants.JDK1_5) {
// pre 1.5, synthetic is an attribute, not a modifier
// pre 1.5, varargs is an attribute, not a modifier (-target jsr14 mode)
accessFlags &= ~(ClassFileConstants.AccSynthetic | ClassFileConstants.AccVarargs);
accessFlags &= ~(Flags.SYNTHETIC | Flags.ACC_VARARGS);
}
if ((methodBinding.tagBits & TagBits.ClearPrivateModifier) != 0) {
accessFlags &= ~ClassFileConstants.AccPrivate;
accessFlags &= ~Flags.PRIVATE;
}
if (this.targetJDK >= ClassFileConstants.JDK17) {
accessFlags &= ~(ClassFileConstants.AccStrictfp);
accessFlags &= ~(Flags.STRICTFP);
}
this.contents[this.contentsOffset++] = (byte) (accessFlags >> 8);
this.contents[this.contentsOffset++] = (byte) accessFlags;
Expand Down Expand Up @@ -4489,8 +4490,8 @@ public void generateMethodInfoHeaderForClinit() {
if (this.contentsOffset + 10 >= this.contents.length) {
resizeContents(10);
}
this.contents[this.contentsOffset++] = (byte) ((ClassFileConstants.AccDefault | ClassFileConstants.AccStatic) >> 8);
this.contents[this.contentsOffset++] = (byte) (ClassFileConstants.AccDefault | ClassFileConstants.AccStatic);
this.contents[this.contentsOffset++] = (byte) ((0 | Flags.STATIC) >> 8);
this.contents[this.contentsOffset++] = (byte) (0 | Flags.STATIC);
int nameIndex = this.constantPool.literalIndex(ConstantPool.Clinit);
this.contents[this.contentsOffset++] = (byte) (nameIndex >> 8);
this.contents[this.contentsOffset++] = (byte) nameIndex;
Expand Down Expand Up @@ -4988,11 +4989,11 @@ private int generateMethodParameters(final MethodBinding binding) {

if (declaringClass.isEnum()) {
if (isConstructor) { // insert String name,int ordinal
length = writeArgumentName(ConstantPool.EnumName, ClassFileConstants.AccSynthetic, length);
length = writeArgumentName(ConstantPool.EnumOrdinal, ClassFileConstants.AccSynthetic, length);
length = writeArgumentName(ConstantPool.EnumName, Flags.SYNTHETIC, length);
length = writeArgumentName(ConstantPool.EnumOrdinal, Flags.SYNTHETIC, length);
} else if (binding instanceof SyntheticMethodBinding
&& CharOperation.equals(ConstantPool.ValueOf, binding.selector)) { // insert String name
length = writeArgumentName(ConstantPool.Name, ClassFileConstants.AccMandated, length);
length = writeArgumentName(ConstantPool.Name, Flags.MANDATED, length);
targetParameters = Binding.NO_PARAMETERS; // Override "unknown" synthetics below
}
}
Expand All @@ -5012,11 +5013,11 @@ private int generateMethodParameters(final MethodBinding binding) {
// isn't the first. The practical relevance of this is questionable, since the constructor call will be
// generated by the same constructor.
boolean couldForwardToMandated = anonymousWithNestedSuper ? declaringClass.superclass().enclosingType().equals(syntheticArgumentTypes[i]) : true;
int modifier = couldForwardToMandated && isImplicitlyDeclared ? ClassFileConstants.AccMandated : ClassFileConstants.AccSynthetic;
int modifier = couldForwardToMandated && isImplicitlyDeclared ? Flags.MANDATED : Flags.SYNTHETIC;
char[] name = CharOperation.concat(
TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX,
String.valueOf(i).toCharArray()); // cannot use depth, can be identical
length = writeArgumentName(name, modifier | ClassFileConstants.AccFinal, length);
length = writeArgumentName(name, modifier | Flags.FINAL, length);
}
}
if (binding instanceof SyntheticMethodBinding) {
Expand All @@ -5034,20 +5035,20 @@ private int generateMethodParameters(final MethodBinding binding) {
Argument argument = arguments[i];
length = writeArgumentName(argument.name, argument.binding.modifiers, length);
} else {
length = writeArgumentName(null, ClassFileConstants.AccSynthetic, length);
length = writeArgumentName(null, Flags.SYNTHETIC, length);
}
}
}
if (needSynthetics) {
SyntheticArgumentBinding[] syntheticOuterArguments = declaringClass.syntheticOuterLocalVariables();
int count = syntheticOuterArguments == null ? 0 : syntheticOuterArguments.length;
for (int i = 0; i < count; i++) {
length = writeArgumentName(syntheticOuterArguments[i].name, syntheticOuterArguments[i].modifiers | ClassFileConstants.AccSynthetic, length);
length = writeArgumentName(syntheticOuterArguments[i].name, syntheticOuterArguments[i].modifiers | Flags.SYNTHETIC, length);
}
// move the extra padding arguments of the synthetic constructor invocation to the end
for (int i = targetParameters.length, extraLength = binding.parameters.length; i < extraLength; i++) {
TypeBinding parameter = binding.parameters[i];
length = writeArgumentName(parameter.constantPoolName(), ClassFileConstants.AccSynthetic, length);
length = writeArgumentName(parameter.constantPoolName(), Flags.SYNTHETIC, length);
}
}

Expand Down Expand Up @@ -5084,7 +5085,7 @@ private int writeArgumentName(char[] name, int modifiers, int oldLength) {
int parameterNameIndex = name == null ? 0 : this.constantPool.literalIndex(name);
this.contents[this.contentsOffset++] = (byte) (parameterNameIndex >> 8);
this.contents[this.contentsOffset++] = (byte) parameterNameIndex;
int flags = modifiers & (ClassFileConstants.AccFinal | ClassFileConstants.AccSynthetic | ClassFileConstants.AccMandated);
int flags = modifiers & (Flags.FINAL | Flags.SYNTHETIC | Flags.MANDATED);
this.contents[this.contentsOffset++] = (byte) (flags >> 8);
this.contents[this.contentsOffset++] = (byte) flags;
return oldLength + 1;
Expand Down Expand Up @@ -5913,31 +5914,31 @@ public void initialize(SourceTypeBinding aType, ClassFile parentClassFile, boole
// Modifier manipulations for classfile
int accessFlags = aType.getAccessFlags();
if (aType.isPrivate()) { // rewrite private to non-public
accessFlags &= ~ClassFileConstants.AccPublic;
accessFlags &= ~Flags.PUBLIC;
}
if (aType.isProtected()) { // rewrite protected into public
accessFlags |= ClassFileConstants.AccPublic;
accessFlags |= Flags.PUBLIC;
}
// clear all bits that are illegal for a class or an interface
accessFlags
&= ~(
ClassFileConstants.AccStrictfp
| ClassFileConstants.AccProtected
| ClassFileConstants.AccPrivate
| ClassFileConstants.AccStatic
| ClassFileConstants.AccSynchronized
| ClassFileConstants.AccNative);
Flags.STRICTFP
| Flags.PROTECTED
| Flags.PRIVATE
| Flags.STATIC
| Flags.SYNCHRONIZED
| Flags.NATIVE);

// set the AccSuper flag (has to be done after clearing AccSynchronized - since same value)
if (!aType.isInterface()) { // class or enum
accessFlags |= ClassFileConstants.AccSuper;
accessFlags |= Flags.ACC_SUPER;
}
if (aType.isAnonymousType()) {
ReferenceBinding superClass = aType.superclass;
if (superClass == null || !(superClass.isEnum() && superClass.isSealed()))
accessFlags &= ~ClassFileConstants.AccFinal;
accessFlags &= ~Flags.FINAL;
}
int finalAbstract = ClassFileConstants.AccFinal | ClassFileConstants.AccAbstract;
int finalAbstract = Flags.FINAL | Flags.ABSTRACT;
if ((accessFlags & finalAbstract) == finalAbstract) {
accessFlags &= ~finalAbstract;
}
Expand Down Expand Up @@ -5991,7 +5992,7 @@ public void initialize(SourceTypeBinding aType, ClassFile parentClassFile, boole
}

public void initializeForModule(ModuleBinding module) {
initializeHeader(null, ClassFileConstants.AccModule);
initializeHeader(null, Flags.ACC_MODULE);
int classNameIndex = this.constantPool.literalIndexForType(TypeConstants.MODULE_INFO_NAME);
this.contents[this.contentsOffset++] = (byte) (classNameIndex >> 8);
this.contents[this.contentsOffset++] = (byte) classNameIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,40 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler;

import org.eclipse.jdt.core.compiler.*;
import org.eclipse.jdt.internal.compiler.env.*;
import org.eclipse.jdt.internal.compiler.impl.*;
import org.eclipse.jdt.internal.compiler.ast.*;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.CompilationProgress;
import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.ImportReference;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.lookup.*;
import org.eclipse.jdt.internal.compiler.parser.*;
import org.eclipse.jdt.internal.compiler.problem.*;
import org.eclipse.jdt.internal.compiler.util.*;

import java.io.*;
import java.util.*;
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
import org.eclipse.jdt.internal.compiler.env.ISourceType;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.CompilerStats;
import org.eclipse.jdt.internal.compiler.impl.ITypeRequestor;
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment;
import org.eclipse.jdt.internal.compiler.lookup.PackageBinding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.eclipse.jdt.internal.compiler.lookup.SourceTypeCollisionException;
import org.eclipse.jdt.internal.compiler.lookup.TypeConstants;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit;
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
import org.eclipse.jdt.internal.compiler.util.Messages;
import org.eclipse.jdt.internal.compiler.util.Util;

@SuppressWarnings("rawtypes")
public class Compiler implements ITypeRequestor, ProblemSeverities {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
import javax.lang.model.element.TypeElement;
import javax.tools.FileObject;
import javax.tools.JavaFileManager;
import javax.tools.JavaFileManager.Location;
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;
import javax.tools.JavaFileManager.Location;

import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
Expand Down
Loading

0 comments on commit 7cb63ef

Please sign in to comment.