Example usage for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding isEnum

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

Introduction

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

Prototype

@Override
    public boolean isEnum() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected IType lookupType(ReferenceBinding typeBinding) {
    if (typeBinding == null || !typeBinding.isValidBinding())
        return null;

    char[] packageName = typeBinding.qualifiedPackageName();
    IPackageFragment[] pkgs = this.nameLookup.findPackageFragments(
            (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME
                    : new String(packageName),
            false);/*from  w ww .ja v  a2  s . co m*/

    // iterate type lookup in each package fragment
    char[] sourceName = typeBinding.qualifiedSourceName();
    String typeName = new String(sourceName);
    int acceptFlag = 0;
    if (typeBinding.isAnnotationType()) {
        acceptFlag = NameLookup.ACCEPT_ANNOTATIONS;
    } else if (typeBinding.isEnum()) {
        acceptFlag = NameLookup.ACCEPT_ENUMS;
    } else if (typeBinding.isInterface()) {
        acceptFlag = NameLookup.ACCEPT_INTERFACES;
    } else if (typeBinding.isClass()) {
        acceptFlag = NameLookup.ACCEPT_CLASSES;
    }
    if (pkgs != null) {
        for (int i = 0, length = pkgs.length; i < length; i++) {
            IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag,
                    true/*consider secondary types*/);
            if (type != null)
                return type;
        }
    }

    // search inside enclosing element
    char[][] qualifiedName = CharOperation.splitOn('.', sourceName);
    int length = qualifiedName.length;
    if (length == 0)
        return null;

    IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type
    if (type == null)
        return null;

    for (int i = 1; i < length; i++) {
        type = type.getType(new String(qualifiedName[i]));
        if (type == null)
            return null;
    }
    if (type.exists())
        return type;
    return null;
}

From source file:com.google.gwt.dev.jjs.impl.BuildTypeMap.java

License:Apache License

private JDeclaredType createType(String name, SourceInfo info, ReferenceBinding binding) {

    JDeclaredType newType;//from  w  w w .  j a v  a 2  s  .co m
    if (binding.isClass()) {
        newType = program.createClass(info, name, binding.isAbstract(), binding.isFinal());
    } else if (binding.isInterface() || binding.isAnnotationType()) {
        newType = program.createInterface(info, name);
    } else if (binding.isEnum()) {
        if (binding.isAnonymousType()) {
            // Don't model an enum subclass as a JEnumType.
            newType = program.createClass(info, name, false, true);
        } else {
            newType = program.createEnum(info, name, binding.isAbstract());
        }
    } else {
        throw new InternalCompilerException("ReferenceBinding is not a class, interface, or enum.");
    }

    info.addCorrelation(info.getCorrelator().by(newType));

    /**
     * We emulate static initializers and instance initializers as methods. As
     * in other cases, this gives us: simpler AST, easier to optimize, more like
     * output JavaScript. Clinit is always in slot 0, init (if it exists) is
     * always in slot 1.
     */
    SourceInfo child = info.makeChild();
    JMethod clinit = program.createMethod(child, "$clinit", newType, program.getTypeVoid(), false, true, true,
            AccessModifier.PRIVATE, false);
    clinit.freezeParamTypes();
    clinit.setSynthetic();
    child.addCorrelation(info.getCorrelator().by(clinit));

    if (newType instanceof JClassType) {
        child = info.makeChild();
        JMethod init = program.createMethod(child, "$init", newType, program.getTypeVoid(), false, false, true,
                AccessModifier.PRIVATE, false);
        init.freezeParamTypes();
        init.setSynthetic();
        child.addCorrelation(info.getCorrelator().by(init));
    }

    newType.setExternal(linker.isExternalType(newType.getName()));
    return newType;
}

From source file:com.google.gwt.dev.jjs.impl.ReferenceMapper.java

License:Apache License

private JDeclaredType createType(ReferenceBinding binding) {
    String name = JdtUtil.asDottedString(binding.compoundName);
    SourceInfo info = SourceOrigin.UNKNOWN;
    if (binding.isClass()) {
        return new JClassType(info, name, binding.isAbstract(), binding.isFinal());
    } else if (binding.isInterface() || binding.isAnnotationType()) {
        return new JInterfaceType(info, name);
    } else if (binding.isEnum()) {
        if (binding.isAnonymousType()) {
            // Don't model an enum subclass as a JEnumType.
            return new JClassType(info, name, false, true);
        } else {/* w w w  .j  a  v  a2 s  .co m*/
            return new JEnumType(info, name, binding.isAbstract());
        }
    } else {
        throw new InternalCompilerException("ReferenceBinding is not a class, interface, or enum.");
    }
}

From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownClassMirror.java

License:Open Source License

public JDTClass(ReferenceBinding klass, IType type) {
    this.type = type;
    bindingRef = new WeakReference<ReferenceBinding>(klass);
    pkg = new JDTPackage(klass.getPackage());
    simpleName = new String(klass.sourceName());
    qualifiedName = JDTUtils.getFullyQualifiedName(klass);
    isPublic = klass.isPublic();/*ww  w .j a v a  2s  . c  om*/
    isInterface = klass.isInterface();
    isAbstract = klass.isAbstract();
    isProtected = klass.isProtected();
    isDefaultAccess = klass.isDefault();
    isLocalType = klass.isLocalType();
    isStatic = (klass.modifiers & ClassFileConstants.AccStatic) != 0;
    isFinal = klass.isFinal();
    isEnum = klass.isEnum();
    isBinary = klass.isBinaryBinding();
    isAnonymous = klass.isAnonymousType();
    isJavaSource = (klass instanceof SourceTypeBinding)
            && new String(((SourceTypeBinding) klass).getFileName()).endsWith(".java");
    isAnnotationType = klass.isAnnotationType();
    bindingKey = klass.computeUniqueKey();

    char[] bindingFileName = klass.getFileName();
    int start = CharOperation.lastIndexOf('/', bindingFileName) + 1;
    if (start == 0 || start < CharOperation.lastIndexOf('\\', bindingFileName))
        start = CharOperation.lastIndexOf('\\', bindingFileName) + 1;
    fileName = new String(CharOperation.subarray(bindingFileName, start, -1));

    int jarFileEntrySeparatorIndex = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR,
            bindingFileName);
    if (jarFileEntrySeparatorIndex > 0) {
        char[] jarPart = CharOperation.subarray(bindingFileName, 0, jarFileEntrySeparatorIndex);
        IJavaElement jarPackageFragmentRoot = JavaCore.create(new String(jarPart));
        String jarPath = jarPackageFragmentRoot.getPath().toOSString();
        char[] entryPart = CharOperation.subarray(bindingFileName, jarFileEntrySeparatorIndex + 1,
                bindingFileName.length);
        fullPath = new StringBuilder(jarPath).append("!/").append(entryPart).toString();
    } else {
        fullPath = new String(bindingFileName);
    }

    ReferenceBinding sourceOrClass = klass;
    if (!klass.isBinaryBinding()) {
        sourceOrClass = klass.outermostEnclosingType();
    }
    char[] classFullName = new char[0];
    for (char[] part : sourceOrClass.compoundName) {
        classFullName = CharOperation.concat(classFullName, part, '/');
    }
    char[][] temp = CharOperation.splitOn('.', sourceOrClass.getFileName());
    String extension = temp.length > 1 ? "." + new String(temp[temp.length - 1]) : "";
    javaModelPath = new String(classFullName) + extension;

    if (type == null) {
        annotations = new HashMap<>();
        methods = Collections.emptyList();
        interfaces = Collections.emptyList();
        typeParams = Collections.emptyList();
        fields = Collections.emptyList();
        innerClasses = Collections.emptyList();
    }
}

From source file:org.eclipse.che.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected IType lookupType(ReferenceBinding typeBinding) {
    if (typeBinding == null || !typeBinding.isValidBinding())
        return null;

    char[] packageName = typeBinding.qualifiedPackageName();
    IPackageFragment[] pkgs = this.nameLookup.findPackageFragments(
            (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME
                    : new String(packageName),
            false);// w w  w . jav a  2 s  .c o  m

    // iterate type lookup in each package fragment
    char[] sourceName = typeBinding.qualifiedSourceName();
    String typeName = new String(sourceName);
    int acceptFlag = 0;
    if (typeBinding.isAnnotationType()) {
        acceptFlag = NameLookup.ACCEPT_ANNOTATIONS;
    } else if (typeBinding.isEnum()) {
        acceptFlag = NameLookup.ACCEPT_ENUMS;
    } else if (typeBinding.isInterface()) {
        acceptFlag = NameLookup.ACCEPT_INTERFACES;
    } else if (typeBinding.isClass()) {
        acceptFlag = NameLookup.ACCEPT_CLASSES;
    }
    if (pkgs != null) {
        for (int i = 0, length = pkgs.length; i < length; i++) {
            IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag, false,
                    true/*consider secondary types*/);
            if (type != null)
                return type;
        }
    }

    // search inside enclosing element
    char[][] qualifiedName = CharOperation.splitOn('.', sourceName);
    int length = qualifiedName.length;
    if (length == 0)
        return null;

    IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type
    if (type == null)
        return null;

    for (int i = 1; i < length; i++) {
        type = type.getType(new String(qualifiedName[i]));
        if (type == null)
            return null;
    }
    if (type.exists())
        return type;
    return null;
}

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

protected IType lookupType(ReferenceBinding typeBinding) {
    if (typeBinding == null)
        return null;

    char[] packageName = typeBinding.qualifiedPackageName();
    IPackageFragment[] pkgs = this.nameLookup.findPackageFragments(
            (packageName == null || packageName.length == 0) ? IPackageFragment.DEFAULT_PACKAGE_NAME
                    : new String(packageName),
            false);/*from w w  w . j  a v a  2  s  . c om*/

    // iterate type lookup in each package fragment
    char[] sourceName = typeBinding.qualifiedSourceName();
    String typeName = new String(sourceName);
    int acceptFlag = 0;
    if (typeBinding.isAnnotationType()) {
        acceptFlag = NameLookup.ACCEPT_ANNOTATIONS;
    } else if (typeBinding.isEnum()) {
        acceptFlag = NameLookup.ACCEPT_ENUMS;
    } else if (typeBinding.isInterface()) {
        acceptFlag = NameLookup.ACCEPT_INTERFACES;
    } else if (typeBinding.isClass()) {
        acceptFlag = NameLookup.ACCEPT_CLASSES;
    }
    if (pkgs != null) {
        for (int i = 0, length = pkgs.length; i < length; i++) {
            IType type = this.nameLookup.findType(typeName, pkgs[i], false, acceptFlag,
                    true/*consider secondary types*/);
            if (type != null)
                return type;
        }
    }

    // search inside enclosing element
    char[][] qualifiedName = CharOperation.splitOn('.', sourceName);
    int length = qualifiedName.length;
    if (length == 0)
        return null;

    IType type = createTypeHandle(new String(qualifiedName[0])); // find the top-level type
    if (type == null)
        return null;

    for (int i = 1; i < length; i++) {
        type = type.getType(new String(qualifiedName[i]));
        if (type == null)
            return null;
    }
    if (type.exists())
        return type;
    return null;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.LiftingEnvironment.java

License:Open Source License

/**
 * Collect all direct roles from a given team only omitting
 * synthetic role interfaces./*from w ww .j  a  va 2  s .  c  o  m*/
 * @return non-null array.
 */
private TreeNode[] getRoles() {
    ReferenceBinding[] roles = this._teamType.binding.memberTypes;
    TreeNode[] treeNodes = new TreeNode[roles.length];
    int count = 0;
    for (int j = 0; j < roles.length; j++) {
        ReferenceBinding role = roles[j];
        if (role.isEnum())
            continue;
        if (!role.roleModel.isSynthInterface()) {
            RoleModel roleModel = role.roleModel;
            TreeNode treeNode = new TreeNode(roleModel);
            treeNodes[count++] = treeNode;
        }
    }
    TreeNode[] treeRoles = new TreeNode[count];
    System.arraycopy(treeNodes, 0, treeRoles, 0, count);
    return treeRoles;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel.java

License:Open Source License

/**
  * Get all roles represented by their RoleModel.
  * Considers Ast or Bindings, whatever is more appropriate.
  * SH: used to ensure STATE_ROLE_INHERITANCE for this team, which is now
  *     moved to CalloutImplementor.getRoleModelForType() to make this
  *     method reusable.//from  w w w . j  av a 2s .  com
  * Does not take external roles into account, yet.
  *
  * @returns all direct roles for this Team.
  */
public RoleModel[] getRoles(boolean includeSynthInterfaces) {
    List<RoleModel> list = new LinkedList<RoleModel>();
    if (this._binding != null) {
        // if binding exists, it may contain reused binary roles
        // which are not present in _ast, so prefer binding.
        ReferenceBinding[] roleBindings = this._binding.memberTypes();
        for (int i = 0; i < roleBindings.length; i++) {
            ReferenceBinding binding = roleBindings[i];
            if (binding.isEnum())
                continue;
            if (includeSynthInterfaces || binding.isDirectRole()) {
                if (binding.roleModel != null)
                    list.add(binding.roleModel);
            }
        }
    } else {

        TypeDeclaration[] roles = this._ast.memberTypes;
        if (roles != null) {
            for (int idx = 0; idx < roles.length; idx++) {
                if ((roles[idx].modifiers & ClassFileConstants.AccEnum) != 0)
                    continue; // enums are not roles
                if (includeSynthInterfaces || roles[idx].isSourceRole()) {
                    RoleModel roleModel = roles[idx].getRoleModel(this);
                    if (roleModel != null)
                        list.add(roleModel);
                }
            }
        }
    }
    return list.toArray(new RoleModel[list.size()]);
}