Example usage for org.eclipse.jdt.internal.compiler.lookup LookupEnvironment convertToRawType

List of usage examples for org.eclipse.jdt.internal.compiler.lookup LookupEnvironment convertToRawType

Introduction

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

Prototype

public TypeBinding convertToRawType(TypeBinding type, boolean forceRawEnclosingType) 

Source Link

Document

Returns the given binding's raw type binding.

Usage

From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNodeBuilder.java

License:Open Source License

TypeBinding toRawType(TypeBinding tb) {
    if (tb instanceof ParameterizedTypeBinding) {
        ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) tb;
        // resolver.getScope() can return null (if the resolver hasn't yet been used to resolve something) - using
        // the environment on the ptb seems safe. Other occurrences of getScope in this file could feasibly
        // be changed in the same way if NPEs become problems there too
        return ptb.environment().convertToRawType(ptb.genericType(), false);
        // return resolver.getScope().environment.convertToRawType(ptb.genericType(), false);
    } else if (tb instanceof TypeVariableBinding) {
        TypeBinding fb = ((TypeVariableBinding) tb).firstBound;
        if (fb == null) {
            return tb.erasure(); // Should be JLObject
            // return resolver.getScope().getJavaLangObject();
        }/*  ww w.  jav  a2 s.c  om*/
        return fb;
    } else if (tb instanceof BinaryTypeBinding) {
        if (tb.isGenericType()) {
            try {
                Field f = BinaryTypeBinding.class.getDeclaredField("environment");
                f.setAccessible(true);
                LookupEnvironment le = (LookupEnvironment) f.get(tb);
                return le.convertToRawType(tb, false);
                // return resolver.getScope().environment.convertToRawType(tb, false);
            } catch (Exception e) {
                throw new RuntimeException("Problem building rawtype ", e);
            }
        } else {
            return tb;
        }
    } else if (tb instanceof ArrayBinding) {
        return tb;
    } else if (tb instanceof BaseTypeBinding) {
        return tb;
    } else if (tb instanceof SourceTypeBinding) {
        return tb;
    }
    throw new IllegalStateException("nyi " + tb.getClass());
}