Example usage for org.eclipse.jdt.internal.compiler.lookup SyntheticMethodBinding readableName

List of usage examples for org.eclipse.jdt.internal.compiler.lookup SyntheticMethodBinding readableName

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup SyntheticMethodBinding readableName.

Prototype

@Override
    public char[] readableName()  

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java

License:Open Source License

/**
  * Copy a synthetic access method to `tgtTypeDecl'.
  *//from  w w w .j ava 2  s  .c o  m
  * For SyntheticRoleFieldAccess the purpose of copying is:
  * - override the inherited method (requires sign.-weakening)
  * - update the contained cast to the suitable role class.
  *
  * @param srcMethod
  * @param tgtTypeDecl either role or team.
  * @param targetTeamDecl equal to tgtTypeDecl or its enclosing
  */
private static MethodBinding copySyntheticMethod(SyntheticMethodBinding srcMethod, TypeDeclaration tgtTypeDecl,
        TypeDeclaration targetTeamDecl) {
    MethodBinding dstMethod = null;
    boolean isSuperAccess = false;
    if ((srcMethod.modifiers & AccSynthetic) != 0) {
        FieldBinding srcField, dstField;
        switch (srcMethod.purpose) {
        case SyntheticMethodBinding.SuperFieldReadAccess:
            isSuperAccess = true;
            //$FALL-THROUGH$
        case SyntheticMethodBinding.FieldReadAccess:
            if (srcMethod instanceof SyntheticRoleFieldAccess)
                srcField = ((SyntheticRoleFieldAccess) srcMethod).resolvedField(); // ensure binding is initialized.
            else
                srcField = srcMethod.targetReadField;
            dstField = ConstantPoolObjectMapper.mapField(srcMethod, srcField, targetTeamDecl.binding);
            dstMethod = tgtTypeDecl.binding.addSyntheticMethod(dstField, true /* read */, isSuperAccess, false);
            if (!srcField.isStatic() && (srcMethod instanceof SyntheticRoleFieldAccess))
                dstMethod.parameters[0] = srcMethod.parameters[0]; // manual weakening
            break;
        case SyntheticMethodBinding.SuperFieldWriteAccess:
            isSuperAccess = true;
            //$FALL-THROUGH$
        case SyntheticMethodBinding.FieldWriteAccess:
            if (srcMethod instanceof SyntheticRoleFieldAccess)
                srcField = ((SyntheticRoleFieldAccess) srcMethod).resolvedField(); // ensure binding is initialized.
            else
                srcField = srcMethod.targetWriteField;
            dstField = ConstantPoolObjectMapper.mapField(srcMethod, srcField, targetTeamDecl.binding);
            dstMethod = tgtTypeDecl.binding.addSyntheticMethod(dstField, false /* write */, isSuperAccess,
                    false);
            if (!srcField.isStatic() && (srcMethod instanceof SyntheticRoleFieldAccess))
                dstMethod.parameters[0] = srcMethod.parameters[0]; // manual weakening
            break;
        case SyntheticMethodBinding.SuperMethodAccess:
            isSuperAccess = true;
            //$FALL-THROUGH$
        case SyntheticMethodBinding.MethodAccess:
            MethodBinding dstOrigMethod = ConstantPoolObjectMapper.mapMethod(srcMethod, srcMethod.targetMethod,
                    null, targetTeamDecl.binding);
            if (dstOrigMethod.isCallin())
                dstMethod = tgtTypeDecl.binding.addSyntheticBaseCallSurrogate(dstOrigMethod);
            else
                dstMethod = tgtTypeDecl.binding.addSyntheticMethod(dstOrigMethod, isSuperAccess);
            break;
        case SyntheticMethodBinding.BridgeMethod:
            dstMethod = ConstantPoolObjectMapper.mapMethod(srcMethod, srcMethod, null, targetTeamDecl.binding);
            if (dstMethod == null)
                tgtTypeDecl.scope.problemReporter()
                        .abortDueToInternalError("Expected synthetic bridge method does not exist: " //$NON-NLS-1$
                                + new String(srcMethod.readableName()));
            break;
        case SyntheticMethodBinding.RoleMethodBridgeInner:
        case SyntheticMethodBinding.RoleMethodBridgeOuter:
            return null; // not copied but generated anew
        default:
            tgtTypeDecl.scope.problemReporter()
                    .abortDueToInternalError("Synthetic methods only partially supported"); //$NON-NLS-1$
            return null;
        }
    }
    if (dstMethod instanceof SyntheticMethodBinding) {
        int lineNumber = srcMethod.getLineNumber();
        if (lineNumber > -1) { // accessor to synth field has no line
            MethodBinding copySrc = srcMethod.copyInheritanceSrc;
            if (copySrc == null)
                copySrc = srcMethod;
            SyntheticMethodBinding synthMethod = (SyntheticMethodBinding) dstMethod;
            LineNumberProvider lineNoProvider = TypeModel.getLineNumberProvider(tgtTypeDecl);
            LineInfo lineInfo = lineNoProvider.addLineInfo(copySrc.declaringClass, lineNumber, 1);
            synthMethod.lineNumber = lineInfo.getOutputStartLine();
        }
    }
    return dstMethod;
}