Example usage for org.eclipse.jdt.internal.compiler.util HashtableOfObject HashtableOfObject

List of usage examples for org.eclipse.jdt.internal.compiler.util HashtableOfObject HashtableOfObject

Introduction

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

Prototype

public HashtableOfObject() 

Source Link

Usage

From source file:org.codehaus.groovy.eclipse.codeassist.processors.GroovyProposalTypeSearchRequestor.java

License:Apache License

/**
 * This method is called after all types have been accepted by
 * this requestor.  Converts each type into an {@link ICompletionProposal}
 * @return list of all {@link ICompletionProposal}s applicable for this
 * content assist request.//from ww w . j a v a2s  .  c o m
 */
List<ICompletionProposal> processAcceptedTypes() {

    this.checkCancel();

    if (this.acceptedTypes == null)
        return Collections.EMPTY_LIST;

    int length = this.acceptedTypes.size();

    if (length == 0)
        return Collections.EMPTY_LIST;

    HashtableOfObject onDemandFound = new HashtableOfObject();
    String thisPackageName = module.getPackageName() == null ? "" : module.getPackageName();

    List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
    try {
        next: for (int i = 0; i < length; i++) {

            // does not check cancellation for every types to avoid
            // performance loss
            if ((i % CHECK_CANCEL_FREQUENCY) == 0) {
                checkCancel();
            }

            AcceptedType acceptedType = (AcceptedType) this.acceptedTypes.elementAt(i);
            char[] packageName = acceptedType.packageName;
            char[] simpleTypeName = acceptedType.simpleTypeName;
            char[][] enclosingTypeNames = acceptedType.enclosingTypeNames;
            int modifiers = acceptedType.modifiers;
            int accessibility = acceptedType.accessibility;

            char[] typeName;
            char[] flatEnclosingTypeNames;
            if (enclosingTypeNames == null || enclosingTypeNames.length == 0) {
                flatEnclosingTypeNames = null;
                typeName = simpleTypeName;
            } else {
                flatEnclosingTypeNames = CharOperation.concatWith(acceptedType.enclosingTypeNames, '.');
                typeName = CharOperation.concat(flatEnclosingTypeNames, simpleTypeName, '.');
            }
            char[] fullyQualifiedName = CharOperation.concat(packageName, typeName, '.');

            // get this imports from the module node
            if (!this.importCachesInitialized) {
                initializeImportCaches();
            }

            // check to see if this type is imported explicitly
            for (int j = 0; j < imports.length; j++) {
                char[][] importName = imports[j];
                if (CharOperation.equals(typeName, importName[0])) {
                    // potentially use fully qualified type name
                    // if there is already something else with the same
                    // simple
                    // name imported
                    proposals.add(proposeType(packageName, simpleTypeName, modifiers, accessibility, typeName,
                            fullyQualifiedName, !CharOperation.equals(fullyQualifiedName, importName[1])));
                    continue next;
                }
            }

            if ((enclosingTypeNames == null || enclosingTypeNames.length == 0)
                    && CharOperation.equals(thisPackageName.toCharArray(), packageName)) {
                proposals.add(proposeType(packageName, simpleTypeName, modifiers, accessibility, typeName,
                        fullyQualifiedName, false));
                continue next;
            } else {
                char[] fullyQualifiedEnclosingTypeOrPackageName = null;

                if (((AcceptedType) onDemandFound.get(simpleTypeName)) == null) {
                    for (int j = 0; j < this.onDemandimports.length; j++) {
                        char[] importFlatName = onDemandimports[j];

                        if (fullyQualifiedEnclosingTypeOrPackageName == null) {
                            if (enclosingTypeNames != null && enclosingTypeNames.length != 0) {
                                fullyQualifiedEnclosingTypeOrPackageName = CharOperation.concat(packageName,
                                        flatEnclosingTypeNames, '.');
                            } else {
                                fullyQualifiedEnclosingTypeOrPackageName = packageName;
                            }
                        }
                        if (CharOperation.equals(fullyQualifiedEnclosingTypeOrPackageName, importFlatName)) {
                            // assume not static import
                            // if(importBinding.isStatic()) {
                            // if((modifiers &
                            // ClassFileConstants.AccStatic) != 0) {
                            // acceptedType.qualifiedTypeName =
                            // typeName;
                            // acceptedType.fullyQualifiedName =
                            // fullyQualifiedName;
                            // onDemandFound.put(
                            // simpleTypeName,
                            // acceptedType);
                            // continue next;
                            // }
                            // } else {
                            acceptedType.qualifiedTypeName = typeName;
                            acceptedType.fullyQualifiedName = fullyQualifiedName;
                            onDemandFound.put(simpleTypeName, acceptedType);
                            continue next;
                            // }
                        }
                    }
                    proposals.add(proposeType(
                            fullyQualifiedEnclosingTypeOrPackageName != null
                                    ? fullyQualifiedEnclosingTypeOrPackageName
                                    : packageName,
                            simpleTypeName, modifiers, accessibility, typeName, fullyQualifiedName, true));
                }
            }
        }
        char[][] keys = onDemandFound.keyTable;
        Object[] values = onDemandFound.valueTable;
        int max = keys.length;
        for (int i = 0; i < max; i++) {
            if ((i % CHECK_CANCEL_FREQUENCY) == 0)
                checkCancel();
            if (keys[i] != null) {
                AcceptedType value = (AcceptedType) values[i];
                if (value != null) {
                    proposals.add(proposeType(value.packageName, value.simpleTypeName, value.modifiers,
                            value.accessibility, value.qualifiedTypeName, value.fullyQualifiedName,
                            value.mustBeQualified));
                }
            }
        }
    } finally {
        this.acceptedTypes = null; // reset
    }
    return proposals;
}

From source file:org.eclipse.jdt.core.dom.CompilationUnitResolver.java

License:Open Source License

/**
 * Add the initial set of compilation units into the loop
 *  ->  build compilation unit declarations, their bindings and record their results.
 *///from  www.j  a  v  a  2  s.co  m
protected void beginToCompile(org.eclipse.jdt.internal.compiler.env.ICompilationUnit[] sourceUnits,
        String[] bindingKeys) {
    int sourceLength = sourceUnits.length;
    int keyLength = bindingKeys.length;
    int maxUnits = sourceLength + keyLength;
    this.totalUnits = 0;
    this.unitsToProcess = new CompilationUnitDeclaration[maxUnits];
    int index = 0;

    // walks the source units
    this.requestedSources = new HashtableOfObject();
    for (int i = 0; i < sourceLength; i++) {
        org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = sourceUnits[i];
        CompilationUnitDeclaration parsedUnit;
        CompilationResult unitResult = new CompilationResult(sourceUnit, index++, maxUnits,
                this.options.maxProblemsPerUnit);
        try {
            if (this.options.verbose) {
                this.out.println(
                        Messages.bind(Messages.compilation_request, new String[] { String.valueOf(index++ + 1),
                                String.valueOf(maxUnits), new String(sourceUnit.getFileName()) }));
            }
            // diet parsing for large collection of units
            if (this.totalUnits < this.parseThreshold) {
                parsedUnit = this.parser.parse(sourceUnit, unitResult);
            } else {
                parsedUnit = this.parser.dietParse(sourceUnit, unitResult);
            }
            // initial type binding creation
            this.lookupEnvironment.buildTypeBindings(parsedUnit, null /*no access restriction*/);
            addCompilationUnit(sourceUnit, parsedUnit);
            this.requestedSources.put(unitResult.getFileName(), sourceUnit);
            worked(1);
        } finally {
            sourceUnits[i] = null; // no longer hold onto the unit
        }
    }

    // walk the binding keys
    this.requestedKeys = new HashtableOfObject();
    for (int i = 0; i < keyLength; i++) {
        BindingKeyResolver resolver = new BindingKeyResolver(bindingKeys[i], this, this.lookupEnvironment);
        resolver.parse(true/*pause after fully qualified name*/);
        // If it doesn't have a type name, then it is either an array type, package or base type, which will definitely not have a compilation unit.
        // Skipping it will speed up performance because the call will open jars. (theodora)
        CompilationUnitDeclaration parsedUnit = resolver.hasTypeName()
                ? resolver.getCompilationUnitDeclaration()
                : null;
        if (parsedUnit != null) {
            char[] fileName = parsedUnit.compilationResult.getFileName();
            Object existing = this.requestedKeys.get(fileName);
            if (existing == null)
                this.requestedKeys.put(fileName, resolver);
            else if (existing instanceof ArrayList)
                ((ArrayList) existing).add(resolver);
            else {
                ArrayList list = new ArrayList();
                list.add(existing);
                list.add(resolver);
                this.requestedKeys.put(fileName, list);
            }

        } else {
            char[] key = resolver.hasTypeName() ? resolver.getKey().toCharArray() // binary binding
                    : CharOperation.concatWith(resolver.compoundName(), '.'); // package binding or base type binding
            this.requestedKeys.put(key, resolver);
        }
        worked(1);
    }

    // binding resolution
    this.lookupEnvironment.completeTypeBindings();
}