Example usage for org.eclipse.jdt.core IJavaProject getJavaModel

List of usage examples for org.eclipse.jdt.core IJavaProject getJavaModel

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getJavaModel.

Prototype

IJavaModel getJavaModel();

Source Link

Document

Returns the Java model.

Usage

From source file:org.switchyard.tools.ui.editor.diagram.binding.AbstractSYBindingComposite.java

License:Open Source License

/**
 * @param shell Shell for the window//from   www  . ja v  a  2  s  . c  om
 * @param superTypeName supertype to search for
 * @param project project to look in
 * @return IType the type created
 * @throws JavaModelException exception thrown
 */
public IType selectType(Shell shell, String superTypeName, IProject project) throws JavaModelException {
    IJavaSearchScope searchScope = null;
    if (project != null && superTypeName != null && !superTypeName.equals("java.lang.Object")) { //$NON-NLS-1$
        IJavaProject javaProject = JavaCore.create(project);
        IType superType = javaProject.findType(superTypeName);
        if (superType != null) {
            searchScope = SearchEngine.createHierarchyScope(superType);
        }
    } else if (project != null) {
        IJavaProject javaProject = JavaCore.create(project);
        searchScope = SearchEngine.createJavaSearchScope(javaProject.getJavaModel().getChildren());
    } else {
        searchScope = SearchEngine.createWorkspaceScope();
    }
    SelectionDialog dialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), searchScope,
            IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES, false);
    dialog.setTitle("Select entries");
    dialog.setMessage("Matching items");
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
        return null;
    }
    Object[] types = dialog.getResult();
    if (types == null || types.length == 0) {
        return null;
    }
    return (IType) types[0];
}

From source file:org.switchyard.tools.ui.editor.diagram.binding.MessageComposerComposite.java

License:Open Source License

/**
 * @param shell Shell for the window//w  ww.  j a v a 2  s  .  com
 * @param superTypeName supertype to search for
 * @param project project to look in
 * @return IType the type created
 * @throws JavaModelException exception thrown
 */
public IType selectType(Shell shell, String superTypeName, IProject project) throws JavaModelException {
    IJavaSearchScope searchScope = null;
    if (project != null && superTypeName != null && !superTypeName.equals("java.lang.Object")) { //$NON-NLS-1$
        IJavaProject javaProject = JavaCore.create(project);
        IType superType = javaProject.findType(superTypeName);
        if (superType != null) {
            searchScope = SearchEngine.createHierarchyScope(superType);
        }
    } else if (project != null) {
        IJavaProject javaProject = JavaCore.create(project);
        searchScope = SearchEngine.createJavaSearchScope(javaProject.getJavaModel().getChildren());
    } else {
        searchScope = SearchEngine.createWorkspaceScope();
    }
    SelectionDialog dialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), searchScope,
            IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES, false);
    dialog.setTitle(Messages.title_selectEntries);
    dialog.setMessage(Messages.description_matchingItems);
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
        return null;
    }
    Object[] types = dialog.getResult();
    if (types == null || types.length == 0) {
        return null;
    }
    return (IType) types[0];
}

From source file:org.switchyard.tools.ui.editor.diagram.shared.JavaInterfaceSelectionComposite.java

License:Open Source License

/**
 * @param shell Shell for the window/* w  ww.ja  va 2  s.c o m*/
 * @param superTypeName supertype to search for
 * @param project project to look in
 * @return IType the type created
 * @throws JavaModelException exception thrown
 */
public IType selectType(Shell shell, String superTypeName, IProject project) throws JavaModelException {
    IJavaSearchScope searchScope = null;
    if (project == null) {
        ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService()
                .getSelection();
        IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
        if (selection instanceof IStructuredSelection) {
            selectionToPass = (IStructuredSelection) selection;
            if (selectionToPass.getFirstElement() instanceof IFile) {
                project = ((IFile) selectionToPass.getFirstElement()).getProject();
            }
        }
    }
    if (project != null && superTypeName != null && !superTypeName.equals("java.lang.Object")) { //$NON-NLS-1$
        IJavaProject javaProject = JavaCore.create(project);
        IType superType = javaProject.findType(superTypeName);
        if (superType != null) {
            searchScope = SearchEngine.createHierarchyScope(superType);
        }
    } else if (project != null) {
        IJavaProject javaProject = JavaCore.create(project);
        searchScope = SearchEngine.createJavaSearchScope(javaProject.getJavaModel().getChildren());
    } else {
        searchScope = SearchEngine.createWorkspaceScope();
    }
    SelectionDialog dialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), searchScope,
            IJavaElementSearchConstants.CONSIDER_INTERFACES, false);
    dialog.setTitle(Messages.title_selectEntries);
    dialog.setMessage(Messages.description_matchingItems);
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
        return null;
    }
    Object[] types = dialog.getResult();
    if (types == null || types.length == 0) {
        return null;
    }
    return (IType) types[0];
}

From source file:runjettyrun.tabs.action.AddClassFolderAction.java

License:Open Source License

/**
 * Adds all projects required by <code>proj</code> to the list
 * <code>res</code>/*from  w w  w  . ja  va2  s . com*/
 *
 * @param proj the project for which to compute required
 *  projects
 * @param res the list to add all required projects too
 */
protected void collectRequiredProjects(IJavaProject proj, List<IJavaProject> res) throws JavaModelException {
    if (!res.contains(proj)) {
        res.add(proj);

        IJavaModel model = proj.getJavaModel();

        IClasspathEntry[] entries = proj.getRawClasspath();
        for (int i = 0; i < entries.length; i++) {
            IClasspathEntry curr = entries[i];
            if (curr.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IJavaProject ref = model.getJavaProject(curr.getPath().segment(0));
                if (ref.exists()) {
                    collectRequiredProjects(ref, res);
                }
            }
        }
    }
}

From source file:tod.plugin.TODPluginUtils.java

License:Open Source License

/**
 * Searches for declarations of the given name and kind in the whole workspace. 
 *//*  www.  j a  v  a 2  s  .c o  m*/
public static List searchDeclarations(List<IJavaProject> aJavaProject, String aName, int aKind)
        throws CoreException {
    // Recursively add referenced projects (because Eclipse doesn't recursively include non-exported referenced projects) 
    Set<IJavaProject> theProjects = new HashSet<IJavaProject>();
    Stack<IJavaProject> theWorkingList = new ArrayStack<IJavaProject>();
    for (IJavaProject theProject : aJavaProject)
        theWorkingList.push(theProject);

    while (!theWorkingList.isEmpty()) {
        IJavaProject theProject = theWorkingList.pop();
        theProjects.add(theProject);

        IJavaModel theJavaModel = theProject.getJavaModel();
        IClasspathEntry[] theEntries = theProject.getResolvedClasspath(true);
        for (IClasspathEntry theEntry : theEntries)
            if (theEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                IJavaProject theReferencedProject = theJavaModel
                        .getJavaProject(theEntry.getPath().lastSegment());
                if (theReferencedProject.exists() && !theProjects.contains(theReferencedProject))
                    theWorkingList.push(theReferencedProject);
            }
    }

    SearchPattern thePattern = SearchPattern.createPattern(aName.replace('$', '.'), aKind,
            IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);

    IJavaSearchScope theScope = SearchEngine
            .createJavaSearchScope(theProjects.toArray(new IJavaElement[theProjects.size()]), true);

    SearchEngine theSearchEngine = new SearchEngine();
    SimpleResultCollector theCollector = new SimpleResultCollector();

    theSearchEngine.search(thePattern, PARTICIPANTS, theScope, theCollector, null);

    return theCollector.getResults();
}