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

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

Introduction

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

Prototype

@Override
    public boolean isAnnotationType() 

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 {//from w w w. ja  v a2 s .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:com.google.gwt.dev.jjs.impl.GwtAstBuilder.java

License:Apache License

private void createTypes(TypeDeclaration x) {
    SourceInfo info = makeSourceInfo(x);
    try {/*from  ww  w  .java  2s .co m*/
        SourceTypeBinding binding = x.binding;
        String name;
        if (binding instanceof LocalTypeBinding) {
            char[] localName = binding.constantPoolName();
            name = new String(localName).replace('/', '.');
        } else {
            name = JdtUtil.asDottedString(binding.compoundName);
        }
        name = intern(name);
        JDeclaredType type;
        String jsPrototype = JsInteropUtil.maybeGetJsTypePrototype(x);
        JsInteropType interopType = JsInteropUtil.maybeGetJsInteropType(x, jsPrototype);

        if (binding.isClass()) {
            type = new JClassType(info, name, binding.isAbstract(), binding.isFinal(), interopType);
            JsInteropUtil.maybeSetJsPrototypeFlag(x, (JClassType) type);
        } else if (binding.isInterface() || binding.isAnnotationType()) {
            type = new JInterfaceType(info, name, interopType, jsPrototype);
        } else if (binding.isEnum()) {
            if (binding.isAnonymousType()) {
                // Don't model an enum subclass as a JEnumType.
                type = new JClassType(info, name, false, true, interopType);
            } else {
                type = new JEnumType(info, name, binding.isAbstract(), interopType);
            }
        } else {
            throw new InternalCompilerException("ReferenceBinding is not a class, interface, or enum.");
        }
        typeMap.setSourceType(binding, type);
        newTypes.add(type);
        if (x.memberTypes != null) {
            for (TypeDeclaration memberType : x.memberTypes) {
                createTypes(memberType);
            }
        }
    } catch (Throwable e) {
        InternalCompilerException ice = translateException(null, e);
        StringBuffer sb = new StringBuffer();
        x.printHeader(0, sb);
        ice.addNode(x.getClass().getName(), sb.toString(), info);
        throw ice;
    }
}

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

License:Open Source License

/**
 * Add any groovy specific method bindings to the set determined by the compiler. These
 *//*from w w w  . j a  va 2s . c  o m*/
@Override
protected MethodBinding[] augmentMethodBindings(MethodBinding[] methodBindings) {
    // Don't add these methods to annotations
    SourceTypeBinding binding = this.referenceContext.binding;
    if (binding != null && (binding.isAnnotationType() || binding.isInterface())) {
        return methodBindings;
    }
    boolean implementsGroovyLangObject = false;

    ReferenceBinding[] superInterfaces = binding.superInterfaces;
    if (superInterfaces != null) {
        for (int i = 0, max = superInterfaces.length; i < max; i++) {
            char[][] interfaceName = superInterfaces[i].compoundName;
            if (CharOperation.equals(interfaceName, GROOVY_LANG_GROOVYOBJECT)) {
                implementsGroovyLangObject = true;
                break;
            }
        }
    }

    List<MethodBinding> groovyMethods = new ArrayList<MethodBinding>();

    // If we don't then a supertype did and these methods do not have to be added here
    if (implementsGroovyLangObject) {
        if (debugListener != null) {
            debugListener.record("augment: type " + new String(this.referenceContext.name)
                    + " having GroovyObject methods added");
        }
        TypeBinding bindingJLO = getJavaLangObject();
        TypeBinding bindingJLS = getJavaLangString();
        TypeBinding bindingGLM = getGroovyLangMetaClassBinding();

        // Now add the groovy.lang.GroovyObject methods:
        //
        // Object invokeMethod(String name, Object args);
        // Object getProperty(String propertyName);
        // void setProperty(String propertyName, Object newValue);
        // MetaClass getMetaClass();
        // void setMetaClass(MetaClass metaClass);

        // Note on synthetic
        // javac/ecj don't see synthetic methods when considering if a type implements an interface. So don't make these
        // synthetic

        // Visibility is public and possibly static/abstract depending on the containing type
        createMethod("invokeMethod", false, "", new TypeBinding[] { bindingJLS, bindingJLO }, bindingJLO,
                groovyMethods, methodBindings, null);
        createMethod("getProperty", false, "", new TypeBinding[] { bindingJLS }, bindingJLO, groovyMethods,
                methodBindings, null);
        createMethod("setProperty", false, "", new TypeBinding[] { bindingJLS, bindingJLO }, TypeBinding.VOID,
                groovyMethods, methodBindings, null);
        createMethod("getMetaClass", false, "", null, bindingGLM, groovyMethods, methodBindings, null);
        createMethod("setMetaClass", false, "", new TypeBinding[] { bindingGLM }, TypeBinding.VOID,
                groovyMethods, methodBindings, null);
    }
    // FIXASC decide what difference this makes - should we not be adding anything at all?
    // will not be an instance of GroovyTypeDeclaration if created through SourceTypeConverter
    if (this.referenceContext instanceof GroovyTypeDeclaration) {
        GroovyTypeDeclaration typeDeclaration = (GroovyTypeDeclaration) this.referenceContext;

        boolean useOldWay = false;
        if (useOldWay) {
            // FIXASC the methods created here need to be a subtype of
            // MethodBinding because they need their source position to be the
            // property
            List<PropertyNode> properties = typeDeclaration.properties;
            for (PropertyNode property : properties) {
                String name = property.getName();
                FieldBinding fBinding = typeDeclaration.binding.getField(name.toCharArray(), false);
                // null binding indicates there was a problem resolving its type
                if (fBinding != null && !(fBinding.type instanceof MissingTypeBinding)) {
                    String getterName = "get" + MetaClassHelper.capitalize(name);
                    createMethod(getterName, property.isStatic(), "", /* TypeBinding.NO_TYPES */null,
                            fBinding.type, groovyMethods, methodBindings, typeDeclaration);
                    if (!fBinding.isFinal()) {
                        String setterName = "set" + MetaClassHelper.capitalize(name);
                        createMethod(setterName, property.isStatic(), "", new TypeBinding[] { fBinding.type },
                                TypeBinding.VOID, groovyMethods, methodBindings, typeDeclaration);
                    }
                    if (fBinding.type == TypeBinding.BOOLEAN) {
                        createMethod("is" + MetaClassHelper.capitalize(name), property.isStatic(),
                                "", /* TypeBinding.NO_TYPES, */
                                null, fBinding.type, groovyMethods, methodBindings, typeDeclaration);
                    }
                }
            }
        } else {
            // Create getters/setters without resolving the types.
            List<PropertyNode> properties = typeDeclaration.properties;
            for (PropertyNode property : properties) {
                String name = property.getName();
                String capitalizedName = MetaClassHelper.capitalize(name);
                // Create getter
                createGetterMethod(name, "get" + capitalizedName, property.isStatic(), groovyMethods,
                        methodBindings, typeDeclaration);
                // Create setter if non-final property
                if (!Modifier.isFinal(property.getModifiers())) {
                    createSetterMethod(name, "set" + capitalizedName, property.isStatic(), groovyMethods,
                            methodBindings, typeDeclaration, property.getType().getName());
                }
                // Create isA if type is boolean
                String propertyType = property.getType().getName();
                if (propertyType.equals("boolean")) {
                    createGetterMethod(name, "is" + capitalizedName, property.isStatic(), groovyMethods,
                            methodBindings, typeDeclaration);
                }
            }
        }
    }

    MethodBinding[] newMethodBindings = groovyMethods
            .toArray(new MethodBinding[methodBindings.length + groovyMethods.size()]);
    System.arraycopy(methodBindings, 0, newMethodBindings, groovyMethods.size(), methodBindings.length);
    return newMethodBindings;
}

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

License:Open Source License

/**
 * Ensure Groovy types extend groovy.lang.GroovyObject
 *///from  w ww  .  jav a 2  s. c o m
private void augmentTypeHierarchy(SourceTypeBinding typeBinding) {
    if (typeBinding.isAnnotationType() || typeBinding.isInterface()) {
        return;
    }
    ReferenceBinding groovyLangObjectBinding = getGroovyLangObjectBinding();
    if (!typeBinding.implementsInterface(groovyLangObjectBinding, true)) {
        ReferenceBinding[] superInterfaceBindings = typeBinding.superInterfaces;
        if (superInterfaceBindings != null) {
            int count = superInterfaceBindings.length;
            System.arraycopy(superInterfaceBindings, 0,
                    superInterfaceBindings = new ReferenceBinding[count + 1], 0, count);
            superInterfaceBindings[count] = groovyLangObjectBinding;
            typeBinding.superInterfaces = superInterfaceBindings;
        }
    }
}