Example usage for org.eclipse.jdt.core.dom ITypeBinding isSynthetic

List of usage examples for org.eclipse.jdt.core.dom ITypeBinding isSynthetic

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ITypeBinding isSynthetic.

Prototype

public boolean isSynthetic();

Source Link

Document

Returns whether this binding is synthetic.

Usage

From source file:com.google.devtools.j2objc.translate.MetadataWriter.java

License:Apache License

/**
 * Returns the modifiers for a specified type, including internal ones.
 * All class modifiers are defined in the JVM specification, table 4.1.
 *///from   w  ww.  ja v a  2s.co  m
private static int getTypeModifiers(ITypeBinding type) {
    int modifiers = type.getModifiers();
    if (type.isInterface()) {
        modifiers |= java.lang.reflect.Modifier.INTERFACE | java.lang.reflect.Modifier.ABSTRACT
                | java.lang.reflect.Modifier.STATIC;
    }
    if (type.isSynthetic()) {
        modifiers |= BindingUtil.ACC_SYNTHETIC;
    }
    if (type.isAnnotation()) {
        modifiers |= BindingUtil.ACC_ANNOTATION;
    }
    if (type.isEnum()) {
        modifiers |= BindingUtil.ACC_ENUM;
    }
    if (type.isAnonymous()) {
        // Anonymous classes are always static, though their closure may include an instance.
        modifiers |= BindingUtil.ACC_ANONYMOUS | java.lang.reflect.Modifier.STATIC;
    }
    return modifiers;
}

From source file:org.autorefactor.refactoring.rules.ReplaceQualifiedNamesBySimpleNamesRefactoring.java

License:Open Source License

private void importStaticTypesAndMembersFromType(ImportDeclaration node) {
    final IBinding binding = node.resolveBinding();
    if (binding == null) {
        return;/*from  w ww.j  ava 2 s.c  o  m*/
    }
    if (binding.getKind() != TYPE) {
        throw new NotImplementedException(node, "for a binding of kind " + binding.getKind());
    }
    final ITypeBinding typeBinding = (ITypeBinding) binding;
    final String typeName = typeBinding.getQualifiedName();
    for (IMethodBinding method : typeBinding.getDeclaredMethods()) {
        if (canAdd(method.getModifiers(), method.isSynthetic())) {
            QName qname = QName.valueOf(typeName, method.getName());
            methods.addName(FQN.fromImport(qname, true));
        }
    }
    for (IVariableBinding field : typeBinding.getDeclaredFields()) {
        if (canAdd(field.getModifiers(), field.isSynthetic())) {
            QName qname = QName.valueOf(typeName, field.getName());
            fields.addName(FQN.fromImport(qname, true));
        }
    }
    for (ITypeBinding memberType : typeBinding.getDeclaredTypes()) {
        if (canAdd(memberType.getModifiers(), memberType.isSynthetic())) {
            QName qname = QName.valueOf(memberType.getQualifiedName());
            types.addName(FQN.fromImport(qname, true));
        }
    }
}

From source file:org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.java

License:Open Source License

/**
 * @since 2.4//  ww  w .ja  v a 2 s.  co  m
 */
protected JvmDeclaredType createType(ITypeBinding typeBinding, String handleIdentifier, List<String> path,
        StringBuilder fqn) {
    if (typeBinding.isAnonymous() || typeBinding.isSynthetic())
        throw new IllegalStateException("Cannot create type for anonymous or synthetic classes");

    // Creates the right type of instance based on the type of binding.
    //
    JvmGenericType jvmGenericType;
    JvmDeclaredType result;
    boolean hasFields;
    if (typeBinding.isAnnotation()) {
        jvmGenericType = null;
        result = TypesFactory.eINSTANCE.createJvmAnnotationType();
        hasFields = false;
    } else if (typeBinding.isEnum()) {
        jvmGenericType = null;
        result = TypesFactory.eINSTANCE.createJvmEnumerationType();
        hasFields = true;
    } else {
        result = jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
        jvmGenericType.setInterface(typeBinding.isInterface());
        hasFields = true;
    }

    // Populate the information computed from the modifiers.
    //
    int modifiers = typeBinding.getModifiers();
    setTypeModifiers(result, modifiers);
    result.setDeprecated(typeBinding.isDeprecated());
    setVisibility(result, modifiers);

    // Determine the simple name and compose the fully qualified name and path, remembering the fqn length and path size so we can reset them.
    //
    String simpleName = typeBinding.getName();
    fqn.append(simpleName);
    int length = fqn.length();
    int size = path.size();
    path.add(simpleName);

    String qualifiedName = fqn.toString();
    result.internalSetIdentifier(qualifiedName);
    result.setSimpleName(simpleName);

    // Traverse the nested types using '$' as the qualified name separator.
    //
    fqn.append('$');
    createNestedTypes(typeBinding, result, handleIdentifier, path, fqn);

    // Traverse the methods using '.'as the qualifed name separator.
    //
    fqn.setLength(length);
    fqn.append('.');
    createMethods(typeBinding, handleIdentifier, path, fqn, result);

    // If there fields allowed, traverse them.
    //
    if (hasFields) {
        createFields(typeBinding, fqn, result);
    }

    // Set the super types.
    //
    setSuperTypes(typeBinding, qualifiedName, result);

    // If this is for a generic type, populate the type parameters.
    //
    if (jvmGenericType != null) {
        ITypeBinding[] typeParameterBindings = typeBinding.getTypeParameters();
        if (typeParameterBindings.length > 0) {
            InternalEList<JvmTypeParameter> typeParameters = (InternalEList<JvmTypeParameter>) jvmGenericType
                    .getTypeParameters();
            for (ITypeBinding variable : typeParameterBindings) {
                typeParameters.addUnique(createTypeParameter(variable, result));
            }
        }
    }

    // Populate the annotation values.
    //
    createAnnotationValues(typeBinding, result);

    // Restore the path.
    //
    path.remove(size);

    return result;
}

From source file:org.eclipse.xtext.common.types.access.jdt.JdtBasedTypeFactory.java

License:Open Source License

/**
 * @since 2.4//  w w w .j  av a2s  .c  o  m
 */
protected void createNestedTypes(ITypeBinding typeBinding, JvmDeclaredType result, String handleIdentifier,
        List<String> path, StringBuilder fqn) {
    resolveMembers.start();
    ITypeBinding[] declaredTypes = typeBinding.getDeclaredTypes();
    if (declaredTypes.length > 0) {
        InternalEList<JvmMember> members = (InternalEList<JvmMember>) result.getMembers();
        int length = fqn.length();
        for (ITypeBinding declaredType : declaredTypes) {
            if (!declaredType.isAnonymous() && !declaredType.isSynthetic()) {
                JvmDeclaredType nestedType = createType(declaredType, handleIdentifier, path, fqn);
                if (nestedType.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE) {
                    if (((JvmGenericType) nestedType).isInterface()) {
                        nestedType.setStatic(true);
                    }
                } else {
                    nestedType.setStatic(true);
                }
                members.addUnique(nestedType);
                fqn.setLength(length);
            }
        }
    }
    resolveMembers.stop();
}

From source file:org.summer.dsl.model.types.access.jdt.JdtBasedTypeFactory.java

License:Open Source License

/**
 * @since 2.4//from   w  w w  .  j av  a2s  .c o  m
 */
protected JvmDeclaredType createType(ITypeBinding typeBinding, String handleIdentifier, List<String> path,
        StringBuilder fqn) {
    if (typeBinding.isAnonymous() || typeBinding.isSynthetic())
        throw new IllegalStateException("Cannot create type for anonymous or synthetic classes");

    // Creates the right type of instance based on the type of binding.
    //
    JvmGenericType jvmGenericType;
    JvmDeclaredType result;
    boolean hasFields;
    if (typeBinding.isAnnotation()) {
        jvmGenericType = null;
        result = TypesFactory.eINSTANCE.createJvmAnnotationType();
        hasFields = false;
    } else if (typeBinding.isEnum()) {
        jvmGenericType = null;
        result = TypesFactory.eINSTANCE.createJvmEnumerationType();
        hasFields = true;
    } else {
        result = jvmGenericType = TypesFactory.eINSTANCE.createJvmGenericType();
        jvmGenericType.setInterface(typeBinding.isInterface());
        hasFields = true;
    }

    // Populate the information computed from the modifiers.
    //
    int modifiers = typeBinding.getModifiers();
    setTypeModifiers(result, modifiers);
    setVisibility(result, modifiers);

    // Determine the simple name and compose the fully qualified name and path, remembering the fqn length and path size so we can reset them.
    //
    String simpleName = typeBinding.getName();
    fqn.append(simpleName);
    int length = fqn.length();
    int size = path.size();
    path.add(simpleName);

    String qualifiedName = fqn.toString();
    result.internalSetIdentifier(qualifiedName);
    result.setSimpleName(simpleName);

    // Traverse the nested types using '$' as the qualified name separator.
    //
    fqn.append('$');
    createNestedTypes(typeBinding, result, handleIdentifier, path, fqn);

    // Traverse the methods using '.'as the qualifed name separator.
    //
    fqn.setLength(length);
    fqn.append('.');
    createMethods(typeBinding, handleIdentifier, path, fqn, result);

    // If there fields allowed, traverse them.
    //
    if (hasFields) {
        createFields(typeBinding, fqn, result);
    }

    // Set the super types.
    //
    setSuperTypes(typeBinding, qualifiedName, result);

    // If this is for a generic type, populate the type parameters.
    //
    if (jvmGenericType != null) {
        ITypeBinding[] typeParameterBindings = typeBinding.getTypeParameters();
        if (typeParameterBindings.length > 0) {
            InternalEList<JvmTypeParameter> typeParameters = (InternalEList<JvmTypeParameter>) jvmGenericType
                    .getTypeParameters();
            for (ITypeBinding variable : typeParameterBindings) {
                typeParameters.addUnique(createTypeParameter(variable, result));
            }
        }
    }

    // Populate the annotation values.
    //
    createAnnotationValues(typeBinding, result);

    // Restore the path.
    //
    path.remove(size);

    return result;
}

From source file:org.summer.dsl.model.types.access.jdt.JdtBasedTypeFactory.java

License:Open Source License

/**
 * @since 2.4//from  w ww  . j  a  v  a2 s  . c  om
 */
protected void createNestedTypes(ITypeBinding typeBinding, JvmDeclaredType result, String handleIdentifier,
        List<String> path, StringBuilder fqn) {
    resolveMembers.start();
    ITypeBinding[] declaredTypes = typeBinding.getDeclaredTypes();
    if (declaredTypes.length > 0) {
        InternalEList<JvmMember> members = (InternalEList<JvmMember>) result.getMembers();
        int length = fqn.length();
        for (ITypeBinding declaredType : declaredTypes) {
            if (!declaredType.isAnonymous() && !declaredType.isSynthetic()) {
                members.addUnique(createType(declaredType, handleIdentifier, path, fqn));
                fqn.setLength(length);
            }
        }
    }
    resolveMembers.stop();
}