Package com.strobel.assembler.metadata

Examples of com.strobel.assembler.metadata.TypeDefinition


    @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 && resolvedType.isLocalClass()) {
            List<ObjectCreationExpression> instantiations = _instantiations.get(type);

            if (instantiations == null) {
                _instantiations.put(type, instantiations = new ArrayList<>());
            }
View Full Code Here


    @Override
    public Void visitAnonymousObjectCreationExpression(final AnonymousObjectCreationExpression node, final Void _) {
        super.visitAnonymousObjectCreationExpression(node, _);

        final TypeDefinition resolvedType = node.getTypeDeclaration().getUserData(Keys.TYPE_DEFINITION);

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

            if (instantiations == null) {
                _instantiations.put(resolvedType, instantiations = new ArrayList<>());
            }
View Full Code Here

            super(context);
        }

        @Override
        public Void visitTypeDeclaration(final TypeDeclaration typeDeclaration, final Void _) {
            final TypeDefinition type = typeDeclaration.getUserData(Keys.TYPE_DEFINITION);

            if (type != null && type.isLocalClass()) {
                _localTypes.put(type, typeDeclaration);
            }

            return super.visitTypeDeclaration(typeDeclaration, _);
        }
View Full Code Here

    }

    @Override
    public Void visitTypeDeclaration(final TypeDeclaration node, final Void _) {
        if (!(node.getParent() instanceof CompilationUnit)) {
            final TypeDefinition type = node.getUserData(Keys.TYPE_DEFINITION);

            if (type != null && AstBuilder.isMemberHidden(type, context)) {
                node.remove();
                return null;
            }
View Full Code Here

                //
                // Remove redundant default constructors.
                //

                final TypeDefinition declaringType = method.getDeclaringType();

                if (declaringType != null) {
                    final boolean hasOtherConstructors = any(
                        declaringType.getDeclaredMethods(),
                        new Predicate<MethodDefinition>() {
                            @Override
                            public boolean test(final MethodDefinition m) {
                                return m.isConstructor() &&
                                       !m.isSynthetic() &&
View Full Code Here

            }
        }

        for (AstNode child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
            if (child instanceof TypeDeclaration) {
                final TypeDefinition currentType = context.getCurrentType();
                final MethodDefinition currentMethod = context.getCurrentMethod();

                context.setCurrentType(null);
                context.setCurrentMethod(null);

                try {
                    final TypeDefinition type = child.getUserData(Keys.TYPE_DEFINITION);

                    if (type != null && type.isInterface()) {
                        continue;
                    }

                    new DeclareVariablesTransform(context).run(child);
                }
View Full Code Here

            if (resolvedArgument != null) {
                final TypeReference createdType = node.getType().getUserData(Keys.TYPE_REFERENCE);
                final TypeReference argumentType = resolvedArgument.getType();

                if (createdType != null && argumentType != null) {
                    final TypeDefinition resolvedCreatedType = createdType.resolve();

                    if (resolvedCreatedType != null &&
                        resolvedCreatedType.isInnerClass() &&
                        !resolvedCreatedType.isStatic() &&
                        isEnclosedBy(resolvedCreatedType, argumentType)) {

                        if (isContextWithinTypeInstance(argumentType) &&
                            firstArgument instanceof ThisReferenceExpression) {

                            final MethodReference constructor = (MethodReference) node.getUserData(Keys.MEMBER_REFERENCE);

                            if (constructor != null &&
                                arguments.size() == constructor.getParameters().size()) {

                                firstArgument.remove();
                            }
                        }
                        else {
                            firstArgument.remove();
                            node.setTarget(firstArgument);

                            final SimpleType type = new SimpleType(resolvedCreatedType.getSimpleName());

                            type.putUserData(Keys.TYPE_REFERENCE, resolvedCreatedType);
                            node.getType().replaceWith(type);
                        }
                    }
View Full Code Here

                if (resolvedArgument != null) {
                    final TypeReference superType = node.getUserData(Keys.TYPE_REFERENCE);
                    final TypeReference argumentType = resolvedArgument.getType();

                    if (superType != null && argumentType != null) {
                        final TypeDefinition resolvedSuperType = superType.resolve();

                        if (resolvedSuperType != null &&
                            resolvedSuperType.isInnerClass() &&
                            !resolvedSuperType.isStatic() &&
                            isEnclosedBy(context.getCurrentType(), argumentType)) {

                            firstArgument.remove();

                            if (!(firstArgument instanceof ThisReferenceExpression)) {
View Full Code Here

        }
        else {
            type = metadataSystem.lookupType(internalName);
        }

        final TypeDefinition resolvedType;

        if (type == null || (resolvedType = type.resolve()) == null) {
            output.writeLine("!!! ERROR: Failed to load class %s.", internalName);
            return;
        }
View Full Code Here

        if (type.isPrimitive()) {
            return KEYWORD.colorize(text);
        }

        final String packageName = type.getPackageName();
        final TypeDefinition resolvedType = type.resolve();

        if (StringUtilities.isNullOrEmpty(packageName)) {
            if (resolvedType != null && resolvedType.isAnnotation()) {
                return ATTRIBUTE.colorize(text);
            }
            else {
                return TYPE.colorize(text);
            }
        }

        String s = text;
        char delimiter = '.';
        String packagePrefix = packageName + delimiter;

        int arrayDepth = 0;

        while (arrayDepth < s.length() && s.charAt(arrayDepth) == '[') {
            arrayDepth++;
        }

        if (arrayDepth > 0) {
            s = s.substring(arrayDepth);
        }

        final boolean isSignature = s.startsWith("L") && s.endsWith(";");

        if (isSignature) {
            s = s.substring(1, s.length() - 1);
        }

        if (!StringUtilities.startsWith(s, packagePrefix)) {
            delimiter = '/';
            packagePrefix = packageName.replace('.', delimiter) + delimiter;
        }

        if (StringUtilities.startsWith(s, packagePrefix)) {
            final StringBuilder sb = new StringBuilder();
            final String[] packageParts = packageName.split("\\.");

            for (int i = 0; i < arrayDepth; i++) {
                sb.append('[');
            }

            if (isSignature) {
                sb.append('L');
            }

            for (int i = 0; i < packageParts.length; i++) {
                if (i != 0) {
                    sb.append(DELIMITER.colorize(String.valueOf(delimiter)));
                }

                sb.append(PACKAGE.colorize(packageParts[i]));
            }

            sb.append(DELIMITER.colorize(String.valueOf(delimiter)));

            final String typeName = s.substring(packagePrefix.length());
            final String[] typeParts = typeName.split("\\$|\\.");
            final Ansi typeColor = resolvedType != null && resolvedType.isAnnotation() ? ATTRIBUTE : TYPE;
            final boolean dollar = typeName.indexOf('$') >= 0;

            for (int i = 0; i < typeParts.length; i++) {
                if (i != 0) {
                    sb.append(DELIMITER.colorize(dollar ? "$" : "."));
                }

                sb.append(typeColor.colorize(typeParts[i]));
            }

            if (isSignature) {
                sb.append(';');
            }

            return sb.toString();
        }

        if (resolvedType != null && resolvedType.isAnnotation()) {
            return ATTRIBUTE.colorize(text);
        }
        else {
            return TYPE.colorize(text);
        }
View Full Code Here

TOP

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

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.