Package com.strobel.assembler.metadata

Examples of com.strobel.assembler.metadata.TypeReference


        return null;
    }

    private MemberReference getCurrentTypeReference() {
        final AstNode node = nodeStack.peek();
        final TypeReference typeReference = node.getUserData(Keys.TYPE_REFERENCE);

        if (typeReference != null) {
            return typeReference;
        }
View Full Code Here


    @Override
    public boolean matches(final INode other, final Match match) {
        if (other instanceof TypeReferenceExpression) {
            final TypeReferenceExpression typeReferenceExpression = (TypeReferenceExpression) other;
            final TypeReference typeReference = typeReferenceExpression.getType().getUserData(Keys.TYPE_REFERENCE);

            return typeReference != null &&
                   StringUtilities.equals(_descriptor, typeReference.getInternalName());
        }
        return false;
    }
View Full Code Here

        for (final ImportDeclaration oldImport : imports) {
            final Identifier importedType = oldImport.getImportIdentifier();

            if (importedType != null && !importedType.isNull()) {
                final TypeReference type = oldImport.getUserData(Keys.TYPE_REFERENCE);

                if (type != null) {
                    final String packageName = type.getPackageName();

                    if (!StringUtilities.isNullOrEmpty(packageName) &&
                        !StringUtilities.equals(packageName, "java.lang") &&
                        !StringUtilities.equals(packageName, filePackage)) {
View Full Code Here

        if (boxedValueResult == null || boxedValueResult.getType() == null) {
            return;
        }

        final TypeReference targetType = ((MethodReference) outerBoxMethod).getReturnType();
        final TypeReference sourceType = boxedValueResult.getType();

        switch (MetadataHelper.getNumericConversionType(targetType, sourceType)) {
            case IDENTITY:
            case IMPLICIT: {
                //
                // We don't actually want to remove round-trip boxing without some sort of cast,
                // or we may end up with:
                //
                // Integer i = null; Integer j = Integer.valueOf(i.intValue());
                //
                // ...becoming:
                //
                // Integer i = null; Integer j = i;
                //
/*
                boxedValue.remove();
                parent.replaceWith(boxedValue);
                break;
*/
                return;
            }

            case EXPLICIT_TO_UNBOXED: {
                final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);

                if (astBuilder == null) {
                    return;
                }

                boxedValue.remove();

                final TypeReference castType = ((MethodReference) outerBoxMethod).getParameters().get(0).getParameterType();
                final CastExpression cast = new CastExpression(astBuilder.convertType(castType), boxedValue);

                parent.replaceWith(cast);

                break;
View Full Code Here

    private void removeUnboxingForCast(
        final InvocationExpression e,
        final MemberReferenceExpression target,
        final CastExpression parent) {

        final TypeReference targetType = parent.getType().toTypeReference();

        if (targetType == null || !targetType.isPrimitive()) {
            return;
        }

        final Expression boxedValue = target.getTarget();
        final ResolveResult boxedValueResult = _resolver.apply(boxedValue);

        if (boxedValueResult == null || boxedValueResult.getType() == null) {
            return;
        }

        final TypeReference sourceType = boxedValueResult.getType();
        final ConversionType conversionType = MetadataHelper.getNumericConversionType(targetType, sourceType);

        switch (conversionType) {
            case IMPLICIT:
            case EXPLICIT:
View Full Code Here

        if (valueResult == null || valueResult.getType() == null) {
            return;
        }

        final TypeReference sourceType = valueResult.getType();
        final TypeReference targetType = ((MethodReference) reference).getReturnType();
        final ConversionType conversionType = MetadataHelper.getNumericConversionType(targetType, sourceType);

        switch (conversionType) {
            case IMPLICIT: {
                underlyingValue.remove();
                node.replaceWith(underlyingValue);
                break;
            }

            case EXPLICIT:
            case EXPLICIT_TO_UNBOXED: {
                final AstBuilder astBuilder = context.getUserData(Keys.AST_BUILDER);

                if (astBuilder == null) {
                    return;
                }

                final TypeReference castType;

                if (conversionType == ConversionType.EXPLICIT_TO_UNBOXED) {
                    castType = MetadataHelper.getUnderlyingPrimitiveTypeOrSelf(targetType);
                }
                else {
View Full Code Here

    private void tryAddOverrideAnnotation(final MethodDeclaration node) {
        boolean foundOverride = false;

        for (final Annotation annotation : node.getAnnotations()) {
            final TypeReference annotationType = annotation.getType().getUserData(Keys.TYPE_REFERENCE);

            if (StringUtilities.equals(annotationType.getInternalName(), OVERRIDE_ANNOTATION_NAME)) {
                foundOverride = true;
                break;
            }
        }

        if (foundOverride) {
            return;
        }

        final MethodDefinition method = node.getUserData(Keys.METHOD_DEFINITION);

        if (method.isStatic() || method.isConstructor() || method.isTypeInitializer()) {
            return;
        }

        final TypeDefinition declaringType = method.getDeclaringType();

        if (declaringType.getCompilerMajorVersion() < CompilerTarget.JDK1_6.majorVersion) {
            return;
        }

        final TypeReference annotationType = new MetadataParser(declaringType).parseTypeDescriptor(OVERRIDE_ANNOTATION_NAME);

        final List<MethodReference> candidates = MetadataHelper.findMethods(
            declaringType,
            new Predicate<MethodReference>() {
                @Override
                public boolean test(final MethodReference reference) {
                    return StringUtilities.equals(reference.getName(), method.getName());
                }
            },
            false,
            true
        );

        for (final MethodReference candidate : candidates) {
            if (MetadataHelper.isOverride(method, candidate)) {
                final Annotation annotation = new Annotation();

                if (_astBuilder != null) {
                    annotation.setType(_astBuilder.convertType(annotationType));
                }
                else {
                    annotation.setType(new SimpleType(annotationType.getSimpleName()));
                }

                node.getAnnotations().add(annotation);
                break;
            }
View Full Code Here

    @Override
    public Void visitObjectCreationExpression(final ObjectCreationExpression node, final Void _) {
        super.visitObjectCreationExpression(node, _);

        final TypeReference type = node.getType().getUserData(Keys.TYPE_REFERENCE);
        final TypeDefinition resolvedType = type != null ? type.resolve() : null;

        if (resolvedType != null && isLocalOrAnonymous(resolvedType)) {
            List<ObjectCreationExpression> instantiations = _instantiations.get(type);

            if (instantiations == null) {
View Full Code Here

        for (final AstNode candidate : _addQualifierCandidates) {
            if (candidate instanceof SimpleType) {
                final SimpleType type = (SimpleType) candidate;

                TypeReference referencedType = type.getUserData(Keys.ANONYMOUS_BASE_TYPE_REFERENCE);

                if (referencedType == null) {
                    referencedType = type.getUserData(Keys.TYPE_REFERENCE);
                }
View Full Code Here

        if (type == null || type.isGenericParameter() || type.isWildcardType()) {
            return null;
        }

        final TypeDefinition resolvedType = type.resolve();
        final TypeReference t = resolvedType != null ? resolvedType : (type.isGenericType() ? type.getUnderlyingType() : type);
        final Object resolvedObject = resolveName(node, t.getSimpleName(), modeForType(node));

        if (resolvedObject instanceof TypeReference &&
            MetadataHelper.isSameType(t, (TypeReference) resolvedObject)) {

            return t.getSimpleName();
        }

        if (t.isNested()) {
            final String outerReference = qualifyReference(node, t.getDeclaringType());

            if (outerReference != null) {
                return outerReference + "." + t.getSimpleName();
            }
        }

        if (resolvedObject != null) {
            return t.getFullName();
        }

        return null;
    }
View Full Code Here

TOP

Related Classes of com.strobel.assembler.metadata.TypeReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.