Example usage for org.eclipse.jdt.internal.compiler.lookup BinaryTypeBinding BinaryTypeBinding

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

Introduction

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

Prototype

public BinaryTypeBinding(PackageBinding packageBinding, IBinaryType binaryType, LookupEnvironment environment,
        boolean needFieldsAndMethods) 

Source Link

Document

Standard constructor for creating binary type bindings from binary models (classfiles)

Usage

From source file:io.gige.compiler.internal.HookedJavaFileObject.java

License:Open Source License

protected void closed() {
    if (!_closed) {
        _closed = true;/*from  ww  w . j  av  a 2 s  .  c o  m*/
        // TODO: support encoding
        switch (this.getKind()) {
        case SOURCE:
            CompilationUnit unit = new CompilationUnit(null, _fileName, null /* encoding */);
            _filer.addNewUnit(unit);
            break;
        case CLASS:
            IBinaryType binaryType = null;
            try {
                binaryType = ClassFileReader.read(_fileName);
            } catch (ClassFormatException e) {
                /*
                 * When the annotation processor produces garbage, javac
                 * seems to show some resilience, by hooking the source
                 * type, which since is resolved can answer annotations
                 * during discovery - Not sure if this sanctioned by the
                 * spec, to be taken up with Oracle. Here we mimic the bug,
                 * see that addNewClassFile is simply collecting
                 * ReferenceBinding's, so adding a SourceTypeBinding works
                 * just fine.
                 */
                ReferenceBinding type = this._filer._env.getCompiler().lookupEnvironment
                        .getType(CharOperation.splitOn('.', _typeName.toCharArray()));
                if (type != null)
                    _filer.addNewClassFile(type);
            } catch (IOException e) {
                // ignore
            }
            if (binaryType != null) {
                char[] name = binaryType.getName();
                ReferenceBinding type = this._filer._env.getCompiler().lookupEnvironment
                        .getType(CharOperation.splitOn('/', name));
                if (type != null && type.isValidBinding()) {
                    if (type.isBinaryBinding()) {
                        _filer.addNewClassFile(type);
                    } else {
                        BinaryTypeBinding binaryBinding = new BinaryTypeBinding(type.getPackage(), binaryType,
                                this._filer._env.getCompiler().lookupEnvironment, true);
                        if (binaryBinding != null)
                            _filer.addNewClassFile(binaryBinding);
                    }
                }
            }
            break;
        case HTML:
        case OTHER:
            break;
        }
    }
}