Example usage for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding methods

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

Introduction

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

Prototype

MethodBinding[] methods

To view the source code for org.eclipse.jdt.internal.compiler.lookup SourceTypeBinding methods.

Click Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.TypeBindingConvector.java

License:Open Source License

public static String toJsonBinaryType(SourceTypeBinding binding) {
    JsonObject object = new JsonObject();
    if (!binding.isAnnotationType()) {
        object.add("annotations", toJsonAnnotations(binding.getAnnotations()));
    } else {/*w  w w .  ja va 2s.  co  m*/
        object.add("annotations", JsonNull.INSTANCE);

    }
    object.add("enclosingMethod", null);
    object.add("enclosingTypeName", binding.enclosingType() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.enclosingType().constantPoolName())));

    object.add("fields", toJsonFields(binding.fields()));
    object.add("genericSignature", binding.genericSignature() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.genericSignature())));
    object.add("interfaceNames", toJsonInterfaces(binding.superInterfaces()));
    object.add("memberTypes", toJsonMemberTypes(binding.memberTypes()));
    object.add("methods", toJsonMethods(binding.methods()));
    object.add("missingTypeNames", null);
    object.add("name", binding.constantPoolName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.constantPoolName())));
    object.add("sourceName", binding.sourceName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.sourceName())));
    object.add("superclassName", binding.superclass() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.superclass().constantPoolName())));
    long annotationTagBits = binding.getAnnotationTagBits();
    //remove AreMethodsComplete bit tag from type
    annotationTagBits &= ~TagBits.AreMethodsComplete;

    object.add("tagBits", new JsonPrimitive(String.valueOf(annotationTagBits)));
    object.add("anonymous", new JsonPrimitive(binding.isAnonymousType()));
    object.add("local", new JsonPrimitive(binding.isLocalType()));
    object.add("member", new JsonPrimitive(binding.isMemberType()));
    object.add("sourceFileName", binding.sourceName() == null ? JsonNull.INSTANCE
            : new JsonPrimitive(new String(binding.sourceName())));
    object.add("modifiers", new JsonPrimitive(binding.modifiers));
    object.add("binaryType", new JsonPrimitive(true));
    object.add("fileName", null);
    return gson.toJson(object);
}

From source file:lombok.eclipse.handlers.ast.EclipseTypeEditor.java

License:Open Source License

private AbstractMethodDeclaration injectMethodImpl(final lombok.ast.AbstractMethodDecl<?> methodDecl) {
    final AbstractMethodDeclaration method = builder.build(methodDecl, MethodDeclaration.class);
    EclipseHandlerUtil.injectMethod(node(), method);

    TypeDeclaration type = get();/* w  ww.j  av  a  2 s  . c o  m*/
    if (type.scope != null && method.scope == null) {
        boolean aboutToBeResolved = false;
        for (StackTraceElement elem : Thread.currentThread().getStackTrace()) {
            if ("org.eclipse.jdt.internal.compiler.lookup.ClassScope".equals(elem.getClassName())
                    && "buildFieldsAndMethods".equals(elem.getMethodName())) {
                aboutToBeResolved = true;
                break;
            }
        }
        if (!aboutToBeResolved) {
            MethodScope scope = new MethodScope(type.scope, method,
                    methodDecl.getModifiers().contains(lombok.ast.Modifier.STATIC));
            MethodBinding methodBinding = null;
            try {
                methodBinding = (MethodBinding) Reflection.methodScopeCreateMethodMethod.invoke(scope, method);
            } catch (final Exception e) {
                // See 'Reflection' class for why we ignore this exception.
            }
            if (methodBinding != null) {
                SourceTypeBinding sourceType = type.scope.referenceContext.binding;
                MethodBinding[] methods = sourceType.methods();
                methods = resize(methods, methods.length + 1);
                methods[methods.length - 1] = methodBinding;
                sourceType.setMethods(methods);
                sourceType.resolveTypesFor(methodBinding);
            }
        }
    }
    return method;
}

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

License:Open Source License

/**
 * When generating code for a role class, copy all non-wide string/integer constants
 * from all tsuper roles in order to reserve constant pool positions below 256.
 * Note, that this strategy is not safe, since multiple tsupers may introduce any
 * number of constants below 256 :(/*from  w w  w.  jav a2 s  . co m*/
 */
public void checkCopyNonWideConstants(Scope scope, ClassFile classFile) {
    SourceTypeBinding dstType = classFile.referenceBinding;
    this._writer = new ConstantPoolObjectWriter(classFile);
    if (dstType.isRole() && !dstType.isInterface()) // for all role classes
    {

        ReferenceBinding[] tsuperRoles = dstType.roleModel.getTSuperRoleBindings();
        for (int i = 0; i < tsuperRoles.length; i++) // for all tsuper roles
        {
            RoleModel srcRole = tsuperRoles[i].roleModel;
            if (srcRole == null || !srcRole.hasByteCode())
                continue;
            byte[] srcConstantPool = srcRole.getByteCode();
            if (srcConstantPool == null)
                continue; // be shy, no idea how it could happen

            this._reader = new ConstantPoolObjectReader(srcRole, srcConstantPool, scope.environment());

            copyAllNonWideConstants(srcRole.getConstantPoolOffsets().length,
                    srcRole.getBinding().enclosingType(), dstType);
        }
    }
    if (dstType.isTeam()) {
        ReferenceBinding orgObjectteamsTeam = scope.getOrgObjectteamsTeam();
        if (!TypeAnalyzer.isOrgObjectteamsTeam(dstType) && !dstType.superclass.isTeam()) {
            TeamMethodGenerator tmg = scope.environment().getTeamMethodGenerator();
            if (tmg.requestBytes()) { // if o.o.Team is converted we don't have the bytecode - and shouldn't need it
                this._reader = new ConstantPoolObjectReader(tmg.classBytes, tmg.constantPoolOffsets,
                        orgObjectteamsTeam.getTeamModel(), scope.environment());
                copyAllNonWideConstants(tmg.constantPoolOffsets.length, dstType.superclass, dstType);
            }
        }

        TeamModel srcModel = dstType.superclass.getTeamModel();
        if (srcModel == null)
            return;
        // if the team has a copied ctor (w/ arg-lifting), bytecodes
        // for the team need to be copied from the super-team, too:
        for (MethodBinding method : dstType.methods()) {
            method = method.copyInheritanceSrc;
            if (method == null || method.model == null)
                continue; // shouldn't happen anyway
            TeamModel methodSrcTeam = srcModel;
            if (TypeBinding.notEquals(method.declaringClass, srcModel.getBinding())) {
                // copied from implicit super team - find the source:
                if (!method.declaringClass.isTeam())
                    continue;
                methodSrcTeam = method.declaringClass.getTeamModel();
            }
            if (!method.model.hasBytes())
                continue; // method not relevant for copying
            this._reader = new ConstantPoolObjectReader(method.model, methodSrcTeam, scope.environment());
            copyAllNonWideConstants(method.model.getConstantPoolOffsets().length, methodSrcTeam.getBinding(),
                    dstType);
            return; // triggered by any method, this team class is fully handled.
        }
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticBaseCallSurrogate.java

License:Open Source License

/**
 * Add any required base-call surrogates to the given type.
 * @param type must be a role class. /*from ww w. ja v a2s  .  c o m*/
 */
public static void addFakedBaseCallSurrogates(SourceTypeBinding type, LookupEnvironment environment) {
    if (type.methods() == null)
        return;
    if (environment.globalOptions.weavingScheme == WeavingScheme.OTDRE) // no surrogates for the dynamic weaver.
        return;
    for (MethodBinding method : type.methods())
        if (method.isCallin() && (method.returnType != null))
            SyntheticBaseCallSurrogate.getBaseCallSurrogate(method, type.roleModel, environment);
}