Example usage for org.eclipse.jdt.core.compiler CharOperation prefixEquals

List of usage examples for org.eclipse.jdt.core.compiler CharOperation prefixEquals

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler CharOperation prefixEquals.

Prototype

public static final boolean prefixEquals(char[] prefix, char[] name) 

Source Link

Document

Answers true if the given name starts with the given prefix, false otherwise.

Usage

From source file:org.eclipse.ajdt.core.text.ITDAwareSelectionRequestor.java

License:Open Source License

public void acceptField(char[] declaringTypePackageName, char[] declaringTypeName, char[] name,
        boolean isDeclaration, char[] uniqueKey, int start, int end) {
    try {// ww  w  .j  a  v a 2 s .  c  o m
        IType targetType = findType(declaringTypePackageName, declaringTypeName);
        if (targetType == null) {
            // type couldn't be found.  this is really some kind of problem
            return;
        }
        List<IJavaElement> itds = ensureModel(targetType).getRelationshipsForElement(targetType,
                AJRelationshipManager.ASPECT_DECLARATIONS);
        for (IJavaElement elt : itds) {
            if (matchedField(elt, name)) {
                accepted.add(elt);
                return;
            }
        }

        // if we are selecting inside of an ITD and the field being matched is a regular field, we find it here.
        IntertypeElement itd = maybeGetITD(start);
        if (itd != null) {
            IField field = targetType.getField(String.valueOf(name));
            if (field.exists()) {
                accepted.add(field);
                return;
            }
        }

        // now check to see if we actually found a field in an ITIT
        IJavaElement parent = targetType.getParent();
        if (parent.getElementType() == IJavaElement.TYPE) {
            // definitely an inner type.  If the outer type does not match,
            // then we know that this was from an ITIT
            char[] enclosingName = (parent.getElementName() + ".").toCharArray();
            if (!CharOperation.prefixEquals(enclosingName, declaringTypeName)) {
                IField field = targetType.getField(String.valueOf(name));
                if (field.exists()) {
                    accepted.add(field);
                }
            }
        }
    } catch (JavaModelException e) {
    }
}

From source file:org.eclipse.ajdt.core.text.ITDAwareSelectionRequestor.java

License:Open Source License

public void acceptMethod(char[] declaringTypePackageName, char[] declaringTypeName,
        String enclosingDeclaringTypeSignature, char[] selector, char[][] parameterPackageNames,
        char[][] parameterTypeNames, String[] parameterSignatures, char[][] typeParameterNames,
        char[][][] typeParameterBoundNames, boolean isConstructor, boolean isDeclaration, char[] uniqueKey,
        int start, int end) {
    try {//from ww w.  j  a va2s  .co  m
        IType targetType = findType(declaringTypePackageName, declaringTypeName);
        if (targetType == null) {
            return;
        }

        String[] simpleParameterSigs;
        if (parameterSignatures != null) {
            simpleParameterSigs = new String[parameterSignatures.length];
            for (int i = 0; i < parameterSignatures.length; i++) {
                simpleParameterSigs[i] = toSimpleName(parameterSignatures[i]);
            }
        } else {
            simpleParameterSigs = null;
        }

        List<IJavaElement> itds = ensureModel(targetType).getRelationshipsForElement(targetType,
                AJRelationshipManager.ASPECT_DECLARATIONS);
        for (IJavaElement elt : itds) {
            if (matchedMethod(elt, selector, simpleParameterSigs)) {
                accepted.add(elt);
                return;
            }
        }

        IntertypeElement itd = maybeGetITD(start);
        String selectorStr = String.valueOf(selector);
        if (itd != null && !isDeclaration) {
            // if we are selecting inside of an ITD and the method being matched is a regular method, we find it here.
            IMethod method = targetType.getMethod(selectorStr, parameterSignatures);
            if (method.exists()) {
                accepted.add(method);
                return;
            }
        }

        // still need to determine if the ITD declaration itself is being selected

        // now check to see if we actually found a method in an ITIT
        IJavaElement parent = targetType.getParent();
        if (parent.getElementType() == IJavaElement.TYPE) {
            // definitely an inner type.  If the outer type does not match,
            // then we know that this was from an ITIT
            char[] enclosingName = (parent.getElementName() + ".").toCharArray();
            if (!CharOperation.prefixEquals(enclosingName, declaringTypeName)) {
                IMethod[] methods = targetType.getMethods();
                for (IMethod method : methods) {
                    if (method.getElementName().equals(selectorStr)
                            && matchedParameters(simpleParameterSigs, method.getParameterTypes())) {
                        accepted.add(method);
                    }
                }
            }
        }

    } catch (JavaModelException e) {
    }
}

From source file:org.eclipse.ajdt.core.text.ITDAwareSelectionRequestor.java

License:Open Source License

public void acceptType(char[] packageName, char[] annotationName, int modifiers, boolean isDeclaration,
        char[] genericTypeSignature, int start, int end) {
    try {/* w ww .j a  v a2 s . co m*/
        int origStart = AspectsConvertingParser.translatePositionToBeforeChanges(start, replacements);
        int origEnd = AspectsConvertingParser.translatePositionToBeforeChanges(end, replacements);
        IntertypeElement itd = maybeGetITD(origStart);
        if (itd != null) {
            // find out if we are selecting the target type name part of an itd
            // itd.getNameRange() returns the range of the name, but excludes the target type.  Must subtract from there.  
            // Make assumption that there are no spaces
            // or comments between '.' and the rest of the name
            ISourceRange nameRange = itd.getNameRange();

            String itdName = itd.getElementName();
            int typeNameLength = Math.max(itdName.lastIndexOf('.'), 0);
            String typeName = itdName.substring(0, typeNameLength);

            int typeNameStart;
            if (itd.getAJKind() == Kind.INTER_TYPE_CONSTRUCTOR) {
                typeNameStart = nameRange.getOffset();
            } else {
                typeNameStart = nameRange.getOffset() - 1 - typeName.length();
            }
            // now determine if the selected section is completely contained within the type name
            if (contained(origStart, origEnd, typeNameStart, typeNameStart + typeNameLength)) {
                IType targetType = itd.findTargetType();
                if (targetType != null && targetType.getFullyQualifiedName('.')
                        .equals(toQualifiedName(packageName, annotationName))) {
                    accepted.add(targetType);
                }
            }
        } else {

            // now check to see if we actually found an ITIT
            IType targetType = findType(packageName, annotationName);
            if (targetType != null) {
                IJavaElement parent = targetType.getParent();
                if (parent.getElementType() == IJavaElement.TYPE) {
                    // definitely an inner type.  If the outer type does not match,
                    // then we know that this was from an ITIT
                    char[] enclosingName = (parent.getElementName() + ".").toCharArray();
                    if (!CharOperation.prefixEquals(enclosingName, annotationName)) {
                        accepted.add(targetType);
                    }
                }
            }
        }
    } catch (JavaModelException e) {
    }
}

From source file:org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.java

License:Open Source License

public FieldBinding getSyntheticField(ReferenceBinding targetEnclosingType, boolean onlyExactMatch) {

    if (this.synthetics == null || this.synthetics[SourceTypeBinding.FIELD_EMUL] == null)
        return null;
    FieldBinding field = (FieldBinding) this.synthetics[SourceTypeBinding.FIELD_EMUL].get(targetEnclosingType);
    if (field != null)
        return field;

    // type compatibility : to handle cases such as
    // class T { class M{}}
    // class S extends T { class N extends M {}} --> need to use S as a default enclosing instance for the super constructor call in N().
    if (!onlyExactMatch) {
        Iterator accessFields = this.synthetics[SourceTypeBinding.FIELD_EMUL].values().iterator();
        while (accessFields.hasNext()) {
            field = (FieldBinding) accessFields.next();
            if (CharOperation.prefixEquals(TypeConstants.SYNTHETIC_ENCLOSING_INSTANCE_PREFIX, field.name)
                    && field.type.findSuperTypeOriginatingFrom(targetEnclosingType) != null)
                return field;
        }/*from  www  . jav a 2  s .co  m*/
    }
    return null;
}

From source file:org.eclipse.objectteams.otdt.core.compiler.OTNameUtils.java

License:Open Source License

/**
 * Is selector the name of a predicate method?
 *//*www  .  j  av  a 2s .c  o m*/
public static boolean isPredicate(char[] selector) {
    if (!CharOperation.prefixEquals(OT_DOLLAR_NAME, selector))
        return false;
    return (CharOperation.prefixEquals(PREDICATE_METHOD_NAME, selector)
            || CharOperation.prefixEquals(BASE_PREDICATE_PREFIX, selector));
}

From source file:org.eclipse.objectteams.otdt.core.compiler.OTNameUtils.java

License:Open Source License

/** Does name denote a synthetic marker interface used for marking tsuper methods? */
public static boolean isTSuperMarkerInterface(char[] name) {
    if (name == null) // some types like LocalTypeBinding and IntersectionCastTypeBinding don't have a name
        return false;
    int lastDollar = CharOperation.lastIndexOf('$', name);
    if (lastDollar > -1)
        name = CharOperation.subarray(name, lastDollar + 1, -1);
    return CharOperation.prefixEquals(TSUPER_OT_NAME, name);
}

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

License:Open Source License

/**
 * @param typeToWrap ReferenceBinding or array thereof
 * @param anchorName//from   w  ww. j  a v  a  2 s.c o m
 * @param site
 * @param declaringMethod where to look for arguments being used as type anchor.
 * @param environment
 * @return a wrapped version of typeToWrap
 */
private TypeBinding getWrappedType(TypeBinding typeToWrap, char[] anchorName, ReferenceBinding site,
        final MethodBinding declaringMethod, LookupEnvironment environment) {
    assert !CharOperation.equals(anchorName, NO_ANCHOR) : "NO_ANCHOR should have been filtered out"; //$NON-NLS-1$

    ReferenceBinding type = (ReferenceBinding) typeToWrap.leafComponentType();
    if (CharOperation.prefixEquals(ARG_ANCHOR_PREFIX.toCharArray(), anchorName)) {
        // Type anchored to another argument:
        LocalVariableBinding anchor = new LocalVariableBinding(anchorName, type.enclosingType(), 0, true); // name is irrelevant.
        // make sure this anchor can answer `anchor.declaringScope.referenceMethodBinding()`:
        anchor.declaringScope = new CallinCalloutScope(null, null) {
            public MethodBinding referenceMethodBinding() {
                return declaringMethod;
            }
        };
        TypeBinding wrappedType = anchor.getRoleTypeBinding(type, typeToWrap.dimensions());

        // argument position is relevant:
        char[] tail = CharOperation.subarray(anchorName, ARG_ANCHOR_PREFIX.length(), -1);
        RoleTypeBinding wrappedRole = (RoleTypeBinding) wrappedType.leafComponentType();
        wrappedRole._argumentPosition = Integer.parseInt(String.valueOf(tail));
        wrappedRole._declaringMethod = new IMethodProvider() {
            public MethodBinding getMethod() {
                return declaringMethod;
            }
        };

        return wrappedType;
    } else {
        return RoleTypeCreator.wrapTypeWithAnchorFromName(typeToWrap, anchorName, site, environment);
    }
}

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

License:Open Source License

/**
* @param roleBinding//from   w  w  w.  j  a  v a  2 s. c  o  m
 * @param mapping
 * @throws InternalCompilerError
*/
private CallinCalloutBinding createBinding(ReferenceBinding roleBinding, Mapping mapping) {
    CallinCalloutBinding result = null;
    CallinCalloutBinding[] callinCallouts = roleBinding.callinCallouts;
    if (callinCallouts != null) {
        for (int i = 0; i < callinCallouts.length; i++) {
            if (CharOperation.equals(mapping._mappingName, callinCallouts[i].name)) {
                // fill in details to existing binding:
                result = callinCallouts[i];
                result.callinModifier = encodeCallinModifier(mapping._callinModifier);
                break;
            }
        }
    }
    if (result == null)
        result = new CallinCalloutBinding(roleBinding, mapping._mappingName,
                encodeCallinModifier(mapping._callinModifier));
    BaseMethod[] mappingBaseMethods = mapping._baseMethods;
    MethodBinding[] baseMethods = new MethodBinding[mappingBaseMethods.length];

    ReferenceBinding currentType = roleBinding;
    char[] roleSignature = mapping._roleSignature;
    if (result.callinModifier == TerminalTokens.TokenNamereplace) {
        // ignore generalized return by truncating the signature:
        int closePos = CharOperation.indexOf(')', roleSignature);
        if (closePos > -1)
            roleSignature = CharOperation.subarray(roleSignature, 0, closePos + 1);
    }

    roleMethod: while (currentType != null) {
        ReferenceBinding currentType2 = currentType;
        while (currentType2 != null) {
            MethodBinding[] methods = currentType2.getMethods(mapping._roleSelector);
            for (int j = 0; j < methods.length; j++) {
                if (CharOperation.prefixEquals(roleSignature,
                        MethodSpec.signature(methods[j], WeavingScheme.OTRE))) {
                    result._roleMethodBinding = methods[j];
                    break roleMethod;
                }
            }
            currentType2 = currentType2.superclass();
        }
        currentType = currentType.enclosingType();
    }
    if (result._roleMethodBinding == null)
        throw new InternalCompilerError("role method specified in callin mapping does not exist " + mapping); //$NON-NLS-1$

    mappingBaseMethods: for (int i = 0; i < mappingBaseMethods.length; i++) {
        BaseMethod bm = mappingBaseMethods[i];
        currentType = roleBinding.baseclass();
        while (currentType != null) {
            MethodBinding[] methods = currentType.getMethods(bm._selector);
            for (int j = 0; j < methods.length; j++) {
                if (CharOperation.equals(bm._signature, methods[j].signature())) // TODO(SH): enhancing? / _isCallin?
                {
                    baseMethods[i] = methods[j];
                    continue mappingBaseMethods;
                }
            }
            currentType = currentType.superclass();
        }
        baseMethods[i] = new ProblemMethodBinding(bm._selector, null, roleBinding.baseclass(),
                ProblemReasons.NotFound);
    }
    result._baseMethods = baseMethods;
    mapping._binding = result;

    result.copyInheritanceSrc = findTSuperBinding(mapping._mappingName, roleBinding);
    return result;
}

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

License:Open Source License

/**
 * This method realizes the logic of the mapping for methods.
 * @param srcMethod         where to copy from
 * @param refMethodBinding  what to copy/remap
 * @param dstTeam           where to copy to
 * @param addMarkerArgAllowed whether copying is allowed to add a marker arg
 * @return destination method//from  ww w . jav  a  2 s. c  om
 */
public static MethodBinding mapMethod(MethodBinding srcMethod, MethodBinding refMethodBinding,
        MethodBinding dstMethod, ReferenceBinding dstTeam, boolean addMarkerArgAllowed) {
    if (dstMethod != null) {
        if (dstMethod.model != null) {
            if (dstMethod.model.oldSelfcall == refMethodBinding)
                return dstMethod.model.adjustedSelfcall;
        }
        if (isConfinedSuperCtor(srcMethod, refMethodBinding))
            return getConfinedSuperCtor(dstMethod);
    }
    // if Binding points at Role-Method of Superteamclass, then mapping must be done
    if (isMappableMethod(refMethodBinding)) {
        if (refMethodBinding.isSynthetic()) {
            RoleModel role = ((ReferenceBinding) mapClass(srcMethod, refMethodBinding.declaringClass,
                    dstTeam)).roleModel;
            if (role != null) {
                MethodBinding foundMethod = role.mapSyntheticMethod(refMethodBinding);
                if (foundMethod != null)
                    return foundMethod;
            }
        }
        boolean isDecapsAccessor = false;
        if (CharOperation.prefixEquals(IOTConstants.OT_DECAPS, refMethodBinding.selector)) {
            // to find a decapsulated method, first strip off the accessor's prefix, then search and ...
            refMethodBinding = new MethodBinding(refMethodBinding, refMethodBinding.declaringClass);
            refMethodBinding.selector = CharOperation.subarray(refMethodBinding.selector,
                    IOTConstants.OT_DECAPS.length, -1);
            isDecapsAccessor = true;
        }
        MethodBinding foundMethod = doMapMethod(srcMethod, refMethodBinding, dstMethod, dstTeam,
                addMarkerArgAllowed);
        if (foundMethod != null && isDecapsAccessor) {
            // .. append the stripped prefix after finding
            foundMethod = new MethodBinding(foundMethod, foundMethod.declaringClass);
            foundMethod.selector = CharOperation.concat(IOTConstants.OT_DECAPS, foundMethod.selector);
        }
        return foundMethod;
    }
    return refMethodBinding;
}

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

License:Open Source License

private FieldBinding getFieldRef(int index) {
    int start = getConstantPoolStartPosition(index);
    assert (u1At(start) == FieldRefTag);
    int class_index = u2At(start + 1);
    int name_index = u2At(start + 3);
    ReferenceBinding class_rb = getClassBinding(class_index);
    ReferenceBinding actualReceiver = class_rb;
    if (class_rb == null)
        return null;

    char[][] nameandtype = getNameAndType(name_index);
    char[] name = nameandtype[0];
    char[] type = nameandtype[1];
    FieldBinding fb = null;//ww w  .j  a v a  2  s . co m
    if (class_rb.erasure() instanceof SourceTypeBinding) {
        SourceTypeBinding sourceType = (SourceTypeBinding) class_rb.erasure();
        // can't find synthetics in 'fields'.
        if (CharOperation.prefixEquals(TypeConstants.SYNTHETIC_OUTER_LOCAL_PREFIX, name))
            return sourceType.getSyntheticOuterLocal(name);
        if (CharOperation.prefixEquals(TypeConstants.SYNTHETIC_CLASS, name))
            return sourceType.getSyntheticClassLiteral(name);
    } // FIXME(SH): else read from RoleModel??

    do {
        fb = findFieldBinding(class_rb, name, type);
        if (fb != null) {
            if (TypeBinding.notEquals(actualReceiver, class_rb))
                // return sourceType.getUpdatedFieldBinding(fb, actualReceiver);
                // no sourceType available so directly create the updated binding:
                return new FieldBinding(fb, actualReceiver);
            return fb;
        }
        class_rb = class_rb.superclass();
    } while (!CharOperation.equals(class_rb.constantPoolName(), ConstantPool.JavaLangObjectConstantPoolName));
    return fb;
}