Example usage for org.eclipse.jdt.internal.compiler.lookup MethodBinding signature

List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding signature

Introduction

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

Prototype

null signature

To view the source code for org.eclipse.jdt.internal.compiler.lookup MethodBinding signature.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java

License:Open Source License

public static char[] getSignature(MethodBinding methodBinding) {
    char[] result = null;

    int oldMod = methodBinding.modifiers;
    //TODO remove the next line when method from binary type will be able to generate generic signature
    methodBinding.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
    result = methodBinding.genericSignature();
    if (result == null) {
        result = methodBinding.signature();
    }/*from   w  ww . j a  v  a 2s .  co  m*/
    methodBinding.modifiers = oldMod;

    if (result != null) {
        result = CharOperation.replaceOnCopy(result, '/', '.');
    }
    return result;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ClassFileMatchLocator.java

License:Open Source License

/**
 * Locate declaration in the current class file. This class file is always in a jar.
 *///  w  w w.j  a v a2s.  c o m
public void locateMatches(MatchLocator locator, ClassFile classFile, IBinaryType info) throws CoreException {
    SearchPattern pattern = locator.pattern;

    // check annotations references
    matchAnnotations(pattern, locator, classFile, info);

    // check class definition
    BinaryType binaryType = (BinaryType) classFile.getType();
    if (matchBinary(pattern, info, null)) {
        binaryType = new ResolvedBinaryType((JavaElement) binaryType.getParent(), binaryType.getElementName(),
                binaryType.getKey());
        locator.reportBinaryMemberDeclaration(null, binaryType, null, info, SearchMatch.A_ACCURATE);
        return;
    }

    // Define arrays to store methods/fields from binary type if necessary
    IBinaryMethod[] binaryMethods = info.getMethods();
    int bMethodsLength = binaryMethods == null ? 0 : binaryMethods.length;
    IBinaryMethod[] unresolvedMethods = null;
    char[][] binaryMethodSignatures = null;
    boolean hasUnresolvedMethods = false;

    // Get fields from binary type info
    IBinaryField[] binaryFields = info.getFields();
    int bFieldsLength = binaryFields == null ? 0 : binaryFields.length;
    IBinaryField[] unresolvedFields = null;
    boolean hasUnresolvedFields = false;

    // Report as many accurate matches as possible
    int accuracy = SearchMatch.A_ACCURATE;
    boolean mustResolve = pattern.mustResolve;
    if (mustResolve) {
        BinaryTypeBinding binding = locator.cacheBinaryType(binaryType, info);
        if (binding != null) {
            // filter out element not in hierarchy scope
            if (!locator.typeInHierarchy(binding))
                return;

            // Search matches on resolved methods
            MethodBinding[] availableMethods = binding.availableMethods();
            int aMethodsLength = availableMethods == null ? 0 : availableMethods.length;
            hasUnresolvedMethods = bMethodsLength != aMethodsLength;
            for (int i = 0; i < aMethodsLength; i++) {
                MethodBinding method = availableMethods[i];
                char[] methodSignature = method.genericSignature();
                if (methodSignature == null)
                    methodSignature = method.signature();

                // Report the match if possible
                int level = locator.patternLocator.resolveLevel(method);
                if (level != PatternLocator.IMPOSSIBLE_MATCH) {
                    IMethod methodHandle = binaryType.getMethod(
                            new String(method.isConstructor()
                                    ? binding.compoundName[binding.compoundName.length - 1]
                                    : method.selector),
                            CharOperation.toStrings(
                                    Signature.getParameterTypes(convertClassFileFormat(methodSignature))));
                    accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE
                            : SearchMatch.A_INACCURATE;
                    locator.reportBinaryMemberDeclaration(null, methodHandle, method, info, accuracy);
                }

                // Remove method from unresolved list
                if (hasUnresolvedMethods) {
                    if (binaryMethodSignatures == null) { // Store binary method signatures to avoid multiple computation
                        binaryMethodSignatures = new char[bMethodsLength][];
                        for (int j = 0; j < bMethodsLength; j++) {
                            IBinaryMethod binaryMethod = binaryMethods[j];
                            char[] signature = binaryMethod.getGenericSignature();
                            if (signature == null)
                                signature = binaryMethod.getMethodDescriptor();
                            binaryMethodSignatures[j] = signature;
                        }
                    }
                    for (int j = 0; j < bMethodsLength; j++) {
                        if (CharOperation.equals(binaryMethods[j].getSelector(), method.selector)
                                && CharOperation.equals(binaryMethodSignatures[j], methodSignature)) {
                            if (unresolvedMethods == null) {
                                System.arraycopy(binaryMethods, 0,
                                        unresolvedMethods = new IBinaryMethod[bMethodsLength], 0,
                                        bMethodsLength);
                            }
                            unresolvedMethods[j] = null;
                            break;
                        }
                    }
                }
            }

            // Search matches on resolved fields
            FieldBinding[] availableFields = binding.availableFields();
            int aFieldsLength = availableFields == null ? 0 : availableFields.length;
            hasUnresolvedFields = bFieldsLength != aFieldsLength;
            for (int i = 0; i < aFieldsLength; i++) {
                FieldBinding field = availableFields[i];

                // Report the match if possible
                int level = locator.patternLocator.resolveLevel(field);
                if (level != PatternLocator.IMPOSSIBLE_MATCH) {
                    IField fieldHandle = binaryType.getField(new String(field.name));
                    accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE
                            : SearchMatch.A_INACCURATE;
                    locator.reportBinaryMemberDeclaration(null, fieldHandle, field, info, accuracy);
                }

                // Remove the field from unresolved list
                if (hasUnresolvedFields) {
                    for (int j = 0; j < bFieldsLength; j++) {
                        if (CharOperation.equals(binaryFields[j].getName(), field.name)) {
                            if (unresolvedFields == null) {
                                System.arraycopy(binaryFields, 0,
                                        unresolvedFields = new IBinaryField[bFieldsLength], 0, bFieldsLength);
                            }
                            unresolvedFields[j] = null;
                            break;
                        }
                    }
                }
            }

            // If all methods/fields were accurate then returns now
            if (!hasUnresolvedMethods && !hasUnresolvedFields) {
                return;
            }
        }
        accuracy = SearchMatch.A_INACCURATE;
    }

    // Report inaccurate methods
    if (mustResolve)
        binaryMethods = unresolvedMethods;
    bMethodsLength = binaryMethods == null ? 0 : binaryMethods.length;
    for (int i = 0; i < bMethodsLength; i++) {
        IBinaryMethod method = binaryMethods[i];
        if (method == null)
            continue; // impossible match or already reported as accurate
        if (matchBinary(pattern, method, info)) {
            char[] name;
            if (method.isConstructor()) {
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=329727
                // We don't need the enclosing type name for the constructor name
                name = info.getSourceName();
            } else {
                name = method.getSelector();
            }
            String selector = new String(name);
            char[] methodSignature = binaryMethodSignatures == null ? null : binaryMethodSignatures[i];
            if (methodSignature == null) {
                methodSignature = method.getGenericSignature();
                if (methodSignature == null)
                    methodSignature = method.getMethodDescriptor();
            }
            String[] parameterTypes = CharOperation
                    .toStrings(Signature.getParameterTypes(convertClassFileFormat(methodSignature)));
            IMethod methodHandle = binaryType.getMethod(selector, parameterTypes);
            methodHandle = new ResolvedBinaryMethod(binaryType, selector, parameterTypes,
                    methodHandle.getKey());
            locator.reportBinaryMemberDeclaration(null, methodHandle, null, info, accuracy);
        }
    }

    // Report inaccurate fields
    if (mustResolve)
        binaryFields = unresolvedFields;
    bFieldsLength = binaryFields == null ? 0 : binaryFields.length;
    for (int i = 0; i < bFieldsLength; i++) {
        IBinaryField field = binaryFields[i];
        if (field == null)
            continue; // impossible match or already reported as accurate
        if (matchBinary(pattern, field, info)) {
            String fieldName = new String(field.getName());
            IField fieldHandle = binaryType.getField(fieldName);
            fieldHandle = new ResolvedBinaryField(binaryType, fieldName, fieldHandle.getKey());
            locator.reportBinaryMemberDeclaration(null, fieldHandle, null, info, accuracy);
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

private static JsonElement toJsonMethod(MethodBinding method) {
    JsonObject object = new JsonObject();
    object.addProperty("modifiers", method.getAccessFlags());
    object.addProperty("constructor", method.isConstructor());
    object.add("argumentNames", toJsonParametersName(method.sourceMethod()));
    object.add("annotations", toJsonAnnotations(method.getAnnotations()));
    object.add("defaultValue", toJsonDefaultValue(method.getDefaultValue()));
    object.add("exceptionTypeNames", toJsonExceptionTypeNames(method.thrownExceptions));
    object.add("genericSignature", method.genericSignature() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(method.genericSignature())));
    object.add("methodDescriptor",
            method.signature() == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.signature())));
    object.add("parameterAnnotations", toJsonParameterAnnotations(method));
    object.add("selector",
            method.selector == null ? JsonNull.INSTANCE : new JsonPrimitive(new String(method.selector)));
    object.addProperty("tagBits", String.valueOf(method.getAnnotationTagBits()));
    object.addProperty("clinit", false);
    return object;
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.ClassFileMatchLocator.java

License:Open Source License

/**
 * Locate declaration in the current class file. This class file is always in a jar.
 *//* w ww. jav a  2 s  . co  m*/
public void locateMatches(MatchLocator locator, ClassFile classFile, IBinaryType info) throws CoreException {
    SearchPattern pattern = locator.pattern;

    // check annotations references
    matchAnnotations(pattern, locator, classFile, info);

    // check class definition
    BinaryType binaryType = (BinaryType) classFile.getType();
    if (matchBinary(pattern, info, null)) {
        binaryType = new ResolvedBinaryType((JavaElement) binaryType.getParent(), binaryType.getElementName(),
                binaryType.getKey());
        locator.reportBinaryMemberDeclaration(null, binaryType, null, info, SearchMatch.A_ACCURATE);
        return;
    }

    // Define arrays to store methods/fields from binary type if necessary
    IBinaryMethod[] binaryMethods = info.getMethods();
    int bMethodsLength = binaryMethods == null ? 0 : binaryMethods.length;
    IBinaryMethod[] unresolvedMethods = null;
    char[][] binaryMethodSignatures = null;
    boolean hasUnresolvedMethods = false;

    // Get fields from binary type info
    IBinaryField[] binaryFields = info.getFields();
    int bFieldsLength = binaryFields == null ? 0 : binaryFields.length;
    IBinaryField[] unresolvedFields = null;
    boolean hasUnresolvedFields = false;

    // Report as many accurate matches as possible
    int accuracy = SearchMatch.A_ACCURATE;
    boolean mustResolve = pattern.mustResolve;
    if (mustResolve) {
        BinaryTypeBinding binding = locator.cacheBinaryType(binaryType, info);
        if (binding != null) {
            // filter out element not in hierarchy scope
            if (!locator.typeInHierarchy(binding))
                return;

            // Search matches on resolved methods
            MethodBinding[] availableMethods = binding.availableMethods();
            int aMethodsLength = availableMethods == null ? 0 : availableMethods.length;
            hasUnresolvedMethods = bMethodsLength != aMethodsLength;
            for (int i = 0; i < aMethodsLength; i++) {
                MethodBinding method = availableMethods[i];
                char[] methodSignature = method.genericSignature();
                if (methodSignature == null)
                    methodSignature = method.signature();

                // Report the match if possible
                int level = locator.patternLocator.resolveLevel(method);
                if (level != org.eclipse.jdt.internal.core.search.matching.PatternLocator.IMPOSSIBLE_MATCH) {
                    IMethod methodHandle = binaryType.getMethod(
                            new String(method.isConstructor()
                                    ? binding.compoundName[binding.compoundName.length - 1]
                                    : method.selector),
                            CharOperation.toStrings(
                                    Signature.getParameterTypes(convertClassFileFormat(methodSignature))));
                    accuracy = level == org.eclipse.jdt.internal.core.search.matching.PatternLocator.ACCURATE_MATCH
                            ? SearchMatch.A_ACCURATE
                            : SearchMatch.A_INACCURATE;
                    locator.reportBinaryMemberDeclaration(null, methodHandle, method, info, accuracy);
                }

                // Remove method from unresolved list
                if (hasUnresolvedMethods) {
                    if (binaryMethodSignatures == null) { // Store binary method signatures to avoid multiple computation
                        binaryMethodSignatures = new char[bMethodsLength][];
                        for (int j = 0; j < bMethodsLength; j++) {
                            IBinaryMethod binaryMethod = binaryMethods[j];
                            char[] signature = binaryMethod.getGenericSignature();
                            if (signature == null)
                                signature = binaryMethod.getMethodDescriptor();
                            binaryMethodSignatures[j] = signature;
                        }
                    }
                    for (int j = 0; j < bMethodsLength; j++) {
                        if (CharOperation.equals(binaryMethods[j].getSelector(), method.selector)
                                && CharOperation.equals(binaryMethodSignatures[j], methodSignature)) {
                            if (unresolvedMethods == null) {
                                System.arraycopy(binaryMethods, 0,
                                        unresolvedMethods = new IBinaryMethod[bMethodsLength], 0,
                                        bMethodsLength);
                            }
                            unresolvedMethods[j] = null;
                            break;
                        }
                    }
                }
            }

            // Search matches on resolved fields
            FieldBinding[] availableFields = binding.availableFields();
            int aFieldsLength = availableFields == null ? 0 : availableFields.length;
            hasUnresolvedFields = bFieldsLength != aFieldsLength;
            for (int i = 0; i < aFieldsLength; i++) {
                FieldBinding field = availableFields[i];

                // Report the match if possible
                int level = locator.patternLocator.resolveLevel(field);
                if (level != org.eclipse.jdt.internal.core.search.matching.PatternLocator.IMPOSSIBLE_MATCH) {
                    IField fieldHandle = binaryType.getField(new String(field.name));
                    accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE
                            : SearchMatch.A_INACCURATE;
                    locator.reportBinaryMemberDeclaration(null, fieldHandle, field, info, accuracy);
                }

                // Remove the field from unresolved list
                if (hasUnresolvedFields) {
                    for (int j = 0; j < bFieldsLength; j++) {
                        if (CharOperation.equals(binaryFields[j].getName(), field.name)) {
                            if (unresolvedFields == null) {
                                System.arraycopy(binaryFields, 0,
                                        unresolvedFields = new IBinaryField[bFieldsLength], 0, bFieldsLength);
                            }
                            unresolvedFields[j] = null;
                            break;
                        }
                    }
                }
            }

            // If all methods/fields were accurate then returns now
            if (!hasUnresolvedMethods && !hasUnresolvedFields) {
                return;
            }
        }
        accuracy = SearchMatch.A_INACCURATE;
    }

    // Report inaccurate methods
    if (mustResolve)
        binaryMethods = unresolvedMethods;
    bMethodsLength = binaryMethods == null ? 0 : binaryMethods.length;
    for (int i = 0; i < bMethodsLength; i++) {
        IBinaryMethod method = binaryMethods[i];
        if (method == null)
            continue; // impossible match or already reported as accurate
        if (matchBinary(pattern, method, info)) {
            char[] name;
            if (method.isConstructor()) {
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=329727
                // We don't need the enclosing type name for the constructor name
                name = info.getSourceName();
            } else {
                name = method.getSelector();
            }
            String selector = new String(name);
            char[] methodSignature = binaryMethodSignatures == null ? null : binaryMethodSignatures[i];
            if (methodSignature == null) {
                methodSignature = method.getGenericSignature();
                if (methodSignature == null)
                    methodSignature = method.getMethodDescriptor();
            }
            String[] parameterTypes = CharOperation
                    .toStrings(Signature.getParameterTypes(convertClassFileFormat(methodSignature)));
            IMethod methodHandle = binaryType.getMethod(selector, parameterTypes);
            methodHandle = new ResolvedBinaryMethod(binaryType, selector, parameterTypes,
                    methodHandle.getKey());
            locator.reportBinaryMemberDeclaration(null, methodHandle, null, info, accuracy);
        }
    }

    // Report inaccurate fields
    if (mustResolve)
        binaryFields = unresolvedFields;
    bFieldsLength = binaryFields == null ? 0 : binaryFields.length;
    for (int i = 0; i < bFieldsLength; i++) {
        IBinaryField field = binaryFields[i];
        if (field == null)
            continue; // impossible match or already reported as accurate
        if (matchBinary(pattern, field, info)) {
            String fieldName = new String(field.getName());
            IField fieldHandle = binaryType.getField(fieldName);
            fieldHandle = new ResolvedBinaryField(binaryType, fieldName, fieldHandle.getKey());
            locator.reportBinaryMemberDeclaration(null, fieldHandle, null, info, accuracy);
        }
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.BytecodeTransformer.java

License:Open Source License

/**
 * Copy the method structure, ie., the header comprising name and signature
 * and _all_ attributes (including Code).
 * Everything _but_ Code is adjusted (only strings).
 *
 * @param conv            converter for mapping strings to the new constantpool
 * @param src             bytes to copy from
 * @param srcOffset       offset into src
 * @param dest            bytes to copy into
 * @param dstMethod/*from ww w  .j a v  a2s  . c o m*/
 * @param expectedLen     number of bytes to be adjusted (for sanity checking only)
 * @return if a CopyInheritanceSrc Attribute is already present return the offset where the lineOffset is stored, -1 otherwise
 */
private int copyAdjustStructure(ClassFile classFile, ConstantPoolSimpleConverter conv, byte[] src,
        int srcOffset, byte[] dest, MethodBinding dstMethod, int expectedLen) {
    conv.updateName(2); // method name
    conv.writeName(4, dstMethod.signature(classFile)); // method signature
    int attributesCount = OTByteCodes.getWord(dest, 6);

    int offset = METHOD_PREFIX_LEN;

    int copyInhSrcLineOffsetOffset = -1;

    for (int i = 0; i < attributesCount; i++) {
        char[] attrName = conv.updateName(offset); // attribute name
        offset += 2;

        int attrLen = OTByteCodes.getInt(src, srcOffset + offset); // attribute length
        offset += 4;

        if (CharOperation.equals(attrName, ExceptionsName)) {
            int numExceptions = OTByteCodes.getWord(src, srcOffset + offset);
            offset += 2;
            for (int j = 0; j < numExceptions; j++) {
                int ref = OTByteCodes.getWord(src, srcOffset + offset);
                ConstantPoolObject cpo = this._reader.readConstantPoolObject(ref, 2);
                cpo = this._mapper.mapConstantPoolObject(cpo);
                this._writer.writeConstantPoolObject(dest, offset, 2, cpo);
                offset += 2;
            }
        } else if (CharOperation.equals(attrName, SignatureName)) {
            conv.updateName(offset);
            offset += 2;
        } else if (CharOperation.equals(attrName, IOTConstants.COPY_INHERITANCE_SOURCE_NAME)) {
            conv.updateName(offset);
            if (attrLen > 2) {
                copyInhSrcLineOffsetOffset = offset + 2;
                offset += 6;
            } else {
                // legacy attribute without lineOffset
                copyInhSrcLineOffsetOffset = 0;
                offset += 2;
            }
        } else if (CharOperation.equals(attrName, IOTConstants.TYPE_ANCHOR_LIST)) {
            int num = OTByteCodes.getWord(src, srcOffset + offset);
            offset += 2;
            for (int j = 0; j < num; j++) {
                conv.updateName(offset);
                offset += 2;
            }
        } else if (CharOperation.equals(attrName, RuntimeVisibleAnnotationsName)
                || CharOperation.equals(attrName, RuntimeInvisibleAnnotationsName)) {
            int annotCount = OTByteCodes.getWord(src, srcOffset + offset);
            offset += 2;
            for (int j = 0; j < annotCount; j++)
                offset = adjustAnnotation(conv, src, srcOffset, offset);
        } else {
            offset += attrLen;
        }

    }
    assert offset == expectedLen;
    return copyInhSrcLineOffsetOffset;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CalloutMappingsAttribute.java

License:Open Source License

void writeElementValue(int i) {
    CallinCalloutBinding mapping = this._mappings[i];
    writeName(mapping._roleMethodBinding.constantPoolName());
    writeName(mapping._roleMethodBinding.signature());
    byte flags = 0;
    switch (mapping.calloutModifier) {
    case TerminalTokens.TokenNameget:
        flags = CALLOUT_GET;/*  w  w  w .  j  av  a 2s.  c om*/
        break;
    case TerminalTokens.TokenNameset:
        flags = CALLOUT_SET;
        break;
    }
    switch (mapping.declaredModifiers) {
    case ClassFileConstants.AccPublic:
        flags |= CALLOUT_PUBLIC;
        break;
    case ClassFileConstants.AccProtected:
        flags |= CALLOUT_PROTECTED;
        break;
    case ClassFileConstants.AccPrivate:
        flags |= CALLOUT_PRIVATE;
        break;
    }
    writeByte(flags);
    MethodBinding baseMethod = mapping._baseMethods[0];
    writeName(baseMethod.declaringClass.attributeName());
    writeName(baseMethod.constantPoolName());
    writeName(baseMethod.signature());
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CalloutMappingsAttribute.java

License:Open Source License

private boolean methodMatchesSignature(MethodBinding methodBinding, char[] signature) {
    if (CharOperation.equals(methodBinding.signature(), signature))
        return true;

    char[][] signatureTypes = scanSignature(signature);

    TypeBinding type = methodBinding.returnType;
    if (!typeMatchesSignature(type, signatureTypes[0]))
        return false;

    char[][] types = CharOperation.subarray(signatureTypes, 1, -1);
    if (types.length != methodBinding.parameters.length)
        return false;
    for (int i = 0; i < types.length; i++)
        if (!typeMatchesSignature(methodBinding.parameters[i], types[i]))
            return false;
    return true;/*from   w  w  w  .ja  v  a 2 s  .c o  m*/
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectReader.java

License:Open Source License

/**
 * compare the MethodBinding with an MethodRef entry from ConstantPool
 * @param binding the binding wich is to be comared with the ConstantPool-Entry
 * @param name the ConstantPool name of a Method
 * @param descriptor the ConstantPool signature of a Method
 * @return true if binding and signature means the same Method
 *///from   www  .j av  a 2s .  c om
private boolean isEqual(MethodBinding binding, char[] name, char[] descriptor) {
    if (new String(binding.selector).compareTo(new String(name)) != 0)
        return false;

    char[] signature = binding.signature(); // erasure
    if (CharOperation.equals(signature, descriptor))
        return true;

    if (binding.isConstructor()) {

        // chop off synthetic enclosing instance argument:

        // 1. try to chop off enclosing team only:
        int separatorPosMethod = CharOperation.indexOf('$', signature);
        int separatorPosDescriptor = CharOperation.indexOf('$', descriptor);

        // 2. chop off full arg until ';'
        if (separatorPosMethod == -1 && separatorPosDescriptor == -1) {
            separatorPosMethod = CharOperation.indexOf(';', signature);
            separatorPosDescriptor = CharOperation.indexOf(';', descriptor);
        }
        if (separatorPosMethod > 0 && separatorPosDescriptor > 0) {
            TypeBinding type1 = this._environment.getTypeFromSignature(signature, 1, separatorPosMethod,
                    false/*GENERIC*/, this._srcModel.getBinding(), null,
                    TypeAnnotationWalker.EMPTY_ANNOTATION_WALKER);
            TypeBinding type2 = this._environment.getTypeFromSignature(descriptor, 1, separatorPosDescriptor,
                    false/*GENERIC*/, this._srcModel.getBinding(), null,
                    TypeAnnotationWalker.EMPTY_ANNOTATION_WALKER);
            if (!type1.isTeam() || !type2.isTeam())
                return false;
            if (!type1.isCompatibleWith(type2))
                return false;

            signature = CharOperation.subarray(signature, separatorPosMethod, -1);
            descriptor = CharOperation.subarray(descriptor, separatorPosDescriptor, -1);
        }
    }
    return false;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPoolObjectWriter.java

License:Open Source License

/**
 * This method adds a ConstantPool Entry in the corresponding cache of this ConstantPool
 * @param cpo the ConstantPoolObject which should be added
 * @return a new reference into this ConstantPool
 *///w w  w . j  a  v  a2  s  .  c  om
int writeConstantPoolObject(ConstantPoolObject cpo) {
    int type = cpo.getType();
    switch (type) {
    case StringTag:
        return this.dstClassFile.constantPool.literalIndex(cpo.getString());
    case IntegerTag:
        return this.dstClassFile.constantPool.literalIndex(cpo.getInteger());
    case FloatTag:
        return this.dstClassFile.constantPool.literalIndex(cpo.getFloat());
    case LongTag:
        return this.dstClassFile.constantPool.literalIndex(cpo.getLong());
    case DoubleTag:
        return this.dstClassFile.constantPool.literalIndex(cpo.getDouble());
    case ClassTag:
        return this.dstClassFile.codeStream.recordTypeBinding(cpo.getClassObject()); // record type anchor, too.
    case FieldRefTag:
        FieldBinding fieldBinding = cpo.getFieldRef();
        if ((fieldBinding.tagBits & TagBits.IsFakedField) != 0)
            fieldBinding = fieldBinding.model.getOriginalFromFake();
        return this.dstClassFile.constantPool.literalIndexForField(
                fieldBinding.declaringClass.constantPoolName(), fieldBinding.name,
                fieldBinding.type.signature());
    case MethodRefTag:
        MethodBinding methodBinding = cpo.getMethodRef();
        return this.dstClassFile.constantPool.literalIndexForMethod(
                methodBinding.declaringClass.constantPoolName(), methodBinding.selector,
                methodBinding.signature(), false); // class
    case InterfaceMethodRefTag:
        methodBinding = cpo.getInterfaceMethodRef();
        return this.dstClassFile.constantPool.literalIndexForMethod(
                methodBinding.declaringClass.constantPoolName(), methodBinding.selector,
                methodBinding.signature(), true); // interface
    case Utf8Tag:
        return this.dstClassFile.constantPool.literalIndex(cpo.getUtf8());
    case NameAndTypeTag: //...
    default:
        throw new RuntimeException();
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CopyInheritanceSourceAttribute.java

License:Open Source License

/**
 * Create a new "CopyInheritanceSrc" attribute.
 *//*from   ww w .j av a  2 s.c  om*/
public static AbstractAttribute copyInherSrcAttribute(MethodBinding srcMethod, MethodModel destModel) {
    if (srcMethod.declaringClass instanceof LocalTypeBinding)
        ((LocalTypeBinding) srcMethod.declaringClass).computeConstantPoolName();
    char[] name = srcMethod.declaringClass.constantPoolName();//CharOperation.concatWith(srcMethod.declaringClass.compoundName, '.');
    name = CharOperation.append(name, '.');
    name = CharOperation.concat(name, srcMethod.selector);
    name = CharOperation.concat(name, srcMethod.signature());
    int offset = 0;
    MethodModel model = srcMethod.model;
    if (model != null)
        offset = model._lineOffset;
    // offset in destModel and attribute will be updated by BytecodeTransformer (needs full line number info of source)
    return new CopyInheritanceSourceAttribute(name, offset);
}