Search in sources :

Example 1 with AbortType

use of org.eclipse.jdt.internal.compiler.problem.AbortType in project bazel-jdt-java-toolchain by salesforce.

the class ModuleDeclaration method generateCode.

public void generateCode() {
    if ((this.bits & ASTNode.HasBeenGenerated) != 0)
        return;
    this.bits |= ASTNode.HasBeenGenerated;
    if (this.ignoreFurtherInvestigation) {
        return;
    }
    try {
        // create the result for a compiled type
        LookupEnvironment env = this.scope.environment();
        ClassFile classFile = env.classFilePool.acquireForModule(this.binding, env.globalOptions);
        classFile.initializeForModule(this.binding);
        // finalize the compiled type result
        classFile.addModuleAttributes(this.binding, this.annotations, this.scope.referenceCompilationUnit());
        this.scope.referenceCompilationUnit().compilationResult.record(this.binding.moduleName, classFile);
    } catch (AbortType e) {
        if (this.binding == null)
            return;
    }
}
Also used : AbortType(org.eclipse.jdt.internal.compiler.problem.AbortType) LookupEnvironment(org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment) ClassFile(org.eclipse.jdt.internal.compiler.ClassFile)

Example 2 with AbortType

use of org.eclipse.jdt.internal.compiler.problem.AbortType in project bazel-jdt-java-toolchain by salesforce.

the class ClassFile method addSpecialMethods.

/**
 * INTERNAL USE-ONLY
 * Generate the byte for all the special method infos.
 * They are:
 * - synthetic access methods
 * - default abstract methods
 * - lambda methods.
 */
public void addSpecialMethods(TypeDeclaration typeDecl) {
    // add all methods (default abstract methods and synthetic)
    // default abstract methods
    generateMissingAbstractMethods(this.referenceBinding.scope.referenceType().missingAbstractMethods, this.referenceBinding.scope.referenceCompilationUnit().compilationResult);
    MethodBinding[] defaultAbstractMethods = this.referenceBinding.getDefaultAbstractMethods();
    for (int i = 0, max = defaultAbstractMethods.length; i < max; i++) {
        MethodBinding methodBinding = defaultAbstractMethods[i];
        generateMethodInfoHeader(methodBinding);
        int methodAttributeOffset = this.contentsOffset;
        int attributeNumber = generateMethodInfoAttributes(methodBinding);
        completeMethodInfo(methodBinding, methodAttributeOffset, attributeNumber);
    }
    // add synthetic methods infos
    int emittedSyntheticsCount = 0;
    SyntheticMethodBinding deserializeLambdaMethod = null;
    boolean continueScanningSynthetics = true;
    while (continueScanningSynthetics) {
        continueScanningSynthetics = false;
        SyntheticMethodBinding[] syntheticMethods = this.referenceBinding.syntheticMethods();
        int currentSyntheticsCount = syntheticMethods == null ? 0 : syntheticMethods.length;
        if (emittedSyntheticsCount != currentSyntheticsCount) {
            for (int i = emittedSyntheticsCount, max = currentSyntheticsCount; i < max; i++) {
                SyntheticMethodBinding syntheticMethod = syntheticMethods[i];
                switch(syntheticMethod.purpose) {
                    case SyntheticMethodBinding.FieldReadAccess:
                    case SyntheticMethodBinding.SuperFieldReadAccess:
                        // generate a method info to emulate an reading access to
                        // a non-accessible field
                        addSyntheticFieldReadAccessMethod(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.FieldWriteAccess:
                    case SyntheticMethodBinding.SuperFieldWriteAccess:
                        // generate a method info to emulate an writing access to
                        // a non-accessible field
                        addSyntheticFieldWriteAccessMethod(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.MethodAccess:
                    case SyntheticMethodBinding.SuperMethodAccess:
                    case SyntheticMethodBinding.BridgeMethod:
                        // generate a method info to emulate an access to a non-accessible method / super-method or bridge method
                        addSyntheticMethodAccessMethod(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.ConstructorAccess:
                        // generate a method info to emulate an access to a non-accessible constructor
                        addSyntheticConstructorAccessMethod(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.EnumValues:
                        // generate a method info to define <enum>#values()
                        addSyntheticEnumValuesMethod(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.EnumValueOf:
                        // generate a method info to define <enum>#valueOf(String)
                        addSyntheticEnumValueOfMethod(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.SwitchTable:
                        // generate a method info to define the switch table synthetic method
                        addSyntheticSwitchTable(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.TooManyEnumsConstants:
                        addSyntheticEnumInitializationMethod(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.LambdaMethod:
                        syntheticMethod.lambda.generateCode(this.referenceBinding.scope, this);
                        // lambda code generation could schedule additional nested lambdas for code generation.
                        continueScanningSynthetics = true;
                        break;
                    case SyntheticMethodBinding.ArrayConstructor:
                        addSyntheticArrayConstructor(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.ArrayClone:
                        addSyntheticArrayClone(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.FactoryMethod:
                        addSyntheticFactoryMethod(syntheticMethod);
                        break;
                    case SyntheticMethodBinding.DeserializeLambda:
                        // delay processing
                        deserializeLambdaMethod = syntheticMethod;
                        break;
                    case SyntheticMethodBinding.SerializableMethodReference:
                        // Nothing to be done
                        break;
                    case SyntheticMethodBinding.RecordCanonicalConstructor:
                        addSyntheticRecordCanonicalConstructor(typeDecl, syntheticMethod);
                        break;
                    case SyntheticMethodBinding.RecordOverrideEquals:
                    case SyntheticMethodBinding.RecordOverrideHashCode:
                    case SyntheticMethodBinding.RecordOverrideToString:
                        addSyntheticRecordOverrideMethods(typeDecl, syntheticMethod, syntheticMethod.purpose);
                        break;
                }
            }
            emittedSyntheticsCount = currentSyntheticsCount;
        }
    }
    if (deserializeLambdaMethod != null) {
        int problemResetPC = 0;
        this.codeStream.wideMode = false;
        boolean restart = false;
        do {
            try {
                problemResetPC = this.contentsOffset;
                addSyntheticDeserializeLambda(deserializeLambdaMethod, this.referenceBinding.syntheticMethods());
                restart = false;
            } catch (AbortMethod e) {
                // Restart code generation if possible ...
                if (e.compilationResult == CodeStream.RESTART_IN_WIDE_MODE) {
                    // a branch target required a goto_w, restart code generation in wide mode.
                    this.contentsOffset = problemResetPC;
                    this.methodCount--;
                    // request wide mode
                    this.codeStream.resetInWideMode();
                    restart = true;
                } else {
                    throw new AbortType(this.referenceBinding.scope.referenceContext.compilationResult, e.problem);
                }
            }
        } while (restart);
    }
}
Also used : AbortType(org.eclipse.jdt.internal.compiler.problem.AbortType) SyntheticMethodBinding(org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding) PolymorphicMethodBinding(org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding) MethodBinding(org.eclipse.jdt.internal.compiler.lookup.MethodBinding) SyntheticMethodBinding(org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding) AbortMethod(org.eclipse.jdt.internal.compiler.problem.AbortMethod)

Aggregations

AbortType (org.eclipse.jdt.internal.compiler.problem.AbortType)2 ClassFile (org.eclipse.jdt.internal.compiler.ClassFile)1 LookupEnvironment (org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment)1 MethodBinding (org.eclipse.jdt.internal.compiler.lookup.MethodBinding)1 PolymorphicMethodBinding (org.eclipse.jdt.internal.compiler.lookup.PolymorphicMethodBinding)1 SyntheticMethodBinding (org.eclipse.jdt.internal.compiler.lookup.SyntheticMethodBinding)1 AbortMethod (org.eclipse.jdt.internal.compiler.problem.AbortMethod)1