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

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

Introduction

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

Prototype

public ObjectVector() 

Source Link

Usage

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

License:Open Source License

private void initializeIndexLocations() {
    IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
    // use a linked set to preserve the order during search: see bug 348507
    LinkedHashSet locations = new LinkedHashSet();
    IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
    if (focus == null) {
        for (int i = 0; i < projectsAndJars.length; i++) {
            IPath path = projectsAndJars[i];
            Object target = new File(path.toOSString());//JavaModel.getTarget(path, false/*don't check existence*/);
            if (target instanceof IFolder) // case of an external folder
                path = ((IFolder) target).getFullPath();
            locations.add(indexManager.computeIndexLocation(path));
        }//from  www .j  a  v a  2s . c  om
    } else {
        try {
            // See whether the state builder might be used to reduce the number of index locations

            // find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
            int length = projectsAndJars.length;
            JavaProject[] projectsCanSeeFocus = new JavaProject[length];
            SimpleSet visitedProjects = new SimpleSet(length);
            int projectIndex = 0;
            SimpleSet externalLibsToCheck = new SimpleSet(length);
            ObjectVector superTypes = new ObjectVector();
            IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
            char[][][] focusQualifiedNames = null;
            boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
            if (isAutoBuilding && focus instanceof IJavaProject) {
                focusQualifiedNames = getQualifiedNames(superTypes);
            }
            IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
            for (int i = 0; i < length; i++) {
                IPath path = projectsAndJars[i];
                JavaProject project = (JavaProject) getJavaProject(path, model);
                if (project != null) {
                    visitedProjects.add(project);
                    if (canSeeFocus(focuses, project, focusQualifiedNames)) {
                        locations.add(indexManager.computeIndexLocation(path));
                        projectsCanSeeFocus[projectIndex++] = project;
                    }
                } else {
                    externalLibsToCheck.add(path);
                }
            }
            for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
                IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
                for (int j = entries.length; --j >= 0;) {
                    IClasspathEntry entry = entries[j];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        IPath path = entry.getPath();
                        if (externalLibsToCheck.remove(path) != null) {
                            Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                            if (target instanceof IFolder) // case of an external folder
                                path = ((IFolder) target).getFullPath();
                            locations.add(indexManager.computeIndexLocation(path));
                        }
                    }
                }
            }
            // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
            if (externalLibsToCheck.elementSize > 0) {
                IJavaProject[] allProjects = model.getJavaProjects();
                for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
                    JavaProject project = (JavaProject) allProjects[i];
                    if (!visitedProjects.includes(project)) {
                        IClasspathEntry[] entries = project.getResolvedClasspath();
                        for (int j = entries.length; --j >= 0;) {
                            IClasspathEntry entry = entries[j];
                            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                                IPath path = entry.getPath();
                                if (externalLibsToCheck.remove(path) != null) {
                                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                                    if (target instanceof IFolder) // case of an external folder
                                        path = ((IFolder) target).getFullPath();
                                    locations.add(indexManager.computeIndexLocation(path));
                                }
                            }
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
            // ignored
        }
    }

    locations.remove(null); // Ensure no nulls
    this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]);
}

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

License:Open Source License

public void add(PossibleMatch possibleMatch) {
    IPath path = possibleMatch.openable.getPackageFragmentRoot().getPath();
    ObjectVector possibleMatches = (ObjectVector) this.rootsToPossibleMatches.get(path);
    if (possibleMatches != null) {
        PossibleMatch storedMatch = (PossibleMatch) possibleMatches.find(possibleMatch);
        if (storedMatch != null) {
            while (storedMatch.getSimilarMatch() != null) {
                storedMatch = storedMatch.getSimilarMatch();
            }//w w  w.j  a va 2s  .  c  o m
            storedMatch.setSimilarMatch(possibleMatch);
            return;
        }
    } else {
        this.rootsToPossibleMatches.put(path, possibleMatches = new ObjectVector());
    }

    possibleMatches.add(possibleMatch);
    this.elementCount++;
}

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

License:Apache License

public GroovyProposalTypeSearchRequestor(ContentAssistContext context,
        JavaContentAssistInvocationContext javaContext, int exprStart, int replaceLength, NameLookup nameLookup,
        IProgressMonitor monitor) {//  w w w .j a  v a2  s .  c o  m

    this.context = context;
    this.offset = exprStart;
    this.javaContext = javaContext;
    this.module = context.unit.getModuleNode();
    this.unit = context.unit;
    this.replaceLength = replaceLength;
    this.actualCompletionPosition = context.completionLocation;
    this.monitor = monitor;
    this.acceptedTypes = new ObjectVector();
    importCachesInitialized = false;
    this.nameLookup = nameLookup;
    this.isImport = context.location == ContentAssistLocation.IMPORT;
    this.shouldAcceptConstructors = context.location == ContentAssistLocation.CONSTRUCTOR
            || context.location == ContentAssistLocation.METHOD_CONTEXT;
    // if contextOnly, then do not insert any text, only show context
    // information
    this.contextOnly = context.location == ContentAssistLocation.METHOD_CONTEXT;
    this.completionExpression = context.location == ContentAssistLocation.METHOD_CONTEXT
            ? ((MethodInfoContentAssistContext) context).methodName
            : context.completionExpression;
    groovyRewriter = new GroovyImportRewriteFactory(this.unit, this.module);
    try {
        allTypesInUnit = unit.getAllTypes();
    } catch (JavaModelException e) {
        GroovyCore.logException("Problem with type completion", e);
        allTypesInUnit = new IType[0];
    }
}

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

License:Apache License

public void acceptConstructor(int modifiers, char[] simpleTypeName, int parameterCount, char[] signature,
        char[][] parameterTypes, char[][] parameterNames, int typeModifiers, char[] packageName, int extraFlags,
        String path, AccessRestriction accessRestriction) {

    if (shouldAcceptConstructors) {

        // does not check cancellation for every types to avoid performance
        // loss/*w  ww. j  a  va2 s.  c o m*/
        if ((this.foundConstructorsCount % (CHECK_CANCEL_FREQUENCY)) == 0)
            checkCancel();
        this.foundConstructorsCount++;

        if ((typeModifiers & ClassFileConstants.AccEnum) != 0)
            return;

        int accessibility = IAccessRule.K_ACCESSIBLE;
        if (accessRestriction != null) {
            switch (accessRestriction.getProblemId()) {
            case IProblem.ForbiddenReference:
                // forbidden references are removed
                return;
            case IProblem.DiscouragedReference:
                // discouraged references have lower priority
                accessibility = IAccessRule.K_DISCOURAGED;
                break;
            }
        }

        if (signature == null) {
            // signature = Signature.createArraySignature(typeSignature,
            // arrayCount)
        }

        if (this.acceptedConstructors == null) {
            this.acceptedConstructors = new ObjectVector();
        }
        this.acceptedConstructors
                .add(new AcceptedConstructor(modifiers, simpleTypeName, parameterCount, signature,
                        parameterTypes, parameterNames, typeModifiers, packageName, extraFlags, accessibility));
    }

}

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

License:Apache License

public void acceptType(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, int modifiers,
        AccessRestriction accessRestriction) {
    // does not check cancellation for every types to avoid performance
    // loss//from  w w w .  ja  va2 s . c o  m
    if ((this.foundTypesCount % CHECK_CANCEL_FREQUENCY) == 0)
        checkCancel();
    this.foundTypesCount++;

    // ignore synthetic
    if (CharOperation.contains('$', simpleTypeName)) {
        return;
    }

    int accessibility = IAccessRule.K_ACCESSIBLE;
    if (accessRestriction != null) {
        switch (accessRestriction.getProblemId()) {
        case IProblem.ForbiddenReference:
            // forbidden references are removed
            return;
        case IProblem.DiscouragedReference:
            // discouraged references have a lower priority
            accessibility = IAccessRule.K_DISCOURAGED;
            break;
        }
    }

    if (this.acceptedTypes == null) {
        this.acceptedTypes = new ObjectVector();
    }
    this.acceptedTypes
            .add(new AcceptedType(packageName, simpleTypeName, enclosingTypeNames, modifiers, accessibility));
}

From source file:org.eclipse.che.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Returns (local/all) the package fragment roots identified by the given project's classpath.
 * Note: this follows project classpath references to find required project contributions,
 * eliminating duplicates silently.//from w ww  .  j a v  a  2  s  .co m
 * Only works with resolved entries
 *
 * @param resolvedClasspath
 *         IClasspathEntry[]
 * @param retrieveExportedRoots
 *         boolean
 * @return IPackageFragmentRoot[]
 * @throws JavaModelException
 */
public IPackageFragmentRoot[] computePackageFragmentRoots(IClasspathEntry[] resolvedClasspath,
        boolean retrieveExportedRoots, Map rootToResolvedEntries) throws JavaModelException {

    ObjectVector accumulatedRoots = new ObjectVector();
    computePackageFragmentRoots(resolvedClasspath, accumulatedRoots, new HashSet(5), // rootIDs
            null, // inside original project
            retrieveExportedRoots, rootToResolvedEntries);
    IPackageFragmentRoot[] rootArray = new IPackageFragmentRoot[accumulatedRoots.size()];
    accumulatedRoots.copyInto(rootArray);
    return rootArray;
}

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

License:Open Source License

private void initializeIndexLocations() {
    IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
    // use a linked set to preserve the order during search: see bug 348507
    LinkedHashSet locations = new LinkedHashSet();
    IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
    if (focus == null) {
        for (int i = 0; i < projectsAndJars.length; i++) {
            IPath path = projectsAndJars[i];
            Object target = new File(path.toOSString());//JavaModel.getTarget(path, false/*don't check existence*/);
            if (target instanceof IFolder) // case of an external folder
                path = ((IFolder) target).getFullPath();
            locations.add(indexManager.computeIndexLocation(path));
        }//from ww w.j av a  2  s.co m
    } else {
        try {
            // See whether the state builder might be used to reduce the number of index locations

            // find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
            int length = projectsAndJars.length;
            JavaProject[] projectsCanSeeFocus = new JavaProject[length];
            SimpleSet visitedProjects = new SimpleSet(length);
            int projectIndex = 0;
            SimpleSet externalLibsToCheck = new SimpleSet(length);
            ObjectVector superTypes = new ObjectVector();
            IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
            char[][][] focusQualifiedNames = null;
            boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
            if (isAutoBuilding && focus instanceof IJavaProject) {
                focusQualifiedNames = getQualifiedNames(superTypes);
            }
            IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
            for (int i = 0; i < length; i++) {
                IPath path = projectsAndJars[i];
                JavaProject project = (JavaProject) getJavaProject(path, model);
                if (project != null) {
                    visitedProjects.add(project);
                    int canSeeFocus = canSeeFocus(focuses, project, focusQualifiedNames);
                    if (canSeeFocus == PROJECT_CAN_SEE_FOCUS) {
                        locations.add(indexManager.computeIndexLocation(path));
                    }
                    if (canSeeFocus != PROJECT_CAN_NOT_SEE_FOCUS) {
                        projectsCanSeeFocus[projectIndex++] = project;
                    }
                } else {
                    externalLibsToCheck.add(path);
                }
            }
            for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
                IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
                for (int j = entries.length; --j >= 0;) {
                    IClasspathEntry entry = entries[j];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        IPath path = entry.getPath();
                        if (externalLibsToCheck.remove(path) != null) {
                            Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                            if (target instanceof IFolder) // case of an external folder
                                path = ((IFolder) target).getFullPath();
                            locations.add(indexManager.computeIndexLocation(path));
                        }
                    }
                }
            }
            // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
            if (externalLibsToCheck.elementSize > 0) {
                IJavaProject[] allProjects = model.getJavaProjects();
                for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
                    JavaProject project = (JavaProject) allProjects[i];
                    if (!visitedProjects.includes(project)) {
                        IClasspathEntry[] entries = project.getResolvedClasspath();
                        for (int j = entries.length; --j >= 0;) {
                            IClasspathEntry entry = entries[j];
                            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                                IPath path = entry.getPath();
                                if (externalLibsToCheck.remove(path) != null) {
                                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                                    if (target instanceof IFolder) // case of an external folder
                                        path = ((IFolder) target).getFullPath();
                                    locations.add(indexManager.computeIndexLocation(path));
                                }
                            }
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
            // ignored
        }
    }

    locations.remove(null); // Ensure no nulls
    this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]);
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * This is a helper method returning the expanded classpath for the project, as a list of classpath entries,
 * where all classpath variable entries have been resolved and substituted with their final target entries.
 * All project exports have been appended to project entries.
 * @return IClasspathEntry[]// w  ww  . j  a v a2s .  co  m
 * @throws JavaModelException
 */
public IClasspathEntry[] getExpandedClasspath() throws JavaModelException {

    ObjectVector accumulatedEntries = new ObjectVector();
    computeExpandedClasspath(null, new HashSet(5), accumulatedEntries);

    IClasspathEntry[] expandedPath = new IClasspathEntry[accumulatedEntries.size()];
    accumulatedEntries.copyInto(expandedPath);

    return expandedPath;
}

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

License:Open Source License

private IPackageFragmentRoot[] getSourceFolders(JavaProject javaProject) throws JavaModelException {
    /*//from   w w w  .  j  a va  2 s  .co m
     * IJavaProject#getAllPackageFragmentRoots will open all references archives to read the JDK version from
     * the first class file it finds. This isn't necessary for our case thus we try to avoid this by copying a lot of 
     * code. 
     */
    ObjectVector result = new ObjectVector();
    collectSourcePackageFragmentRoots(javaProject, Sets.<String>newHashSet(), null, result);
    IPackageFragmentRoot[] rootArray = new IPackageFragmentRoot[result.size()];
    result.copyInto(rootArray);
    return rootArray;
}