Search in sources :

Example 91 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project xtext-eclipse by eclipse.

the class XbaseLineBreakpoint method computeJavaProject.

// old working implementation copied from 3.8
private IJavaProject computeJavaProject(IJavaStackFrame stackFrame) {
    ILaunch launch = stackFrame.getLaunch();
    if (launch == null) {
        return null;
    }
    ISourceLocator locator = launch.getSourceLocator();
    if (locator == null)
        return null;
    Object sourceElement = null;
    try {
        if (locator instanceof ISourceLookupDirector && !stackFrame.isStatic()) {
            IJavaType thisType = stackFrame.getThis().getJavaType();
            if (thisType instanceof IJavaReferenceType) {
                String[] sourcePaths = ((IJavaReferenceType) thisType).getSourcePaths(null);
                if (sourcePaths != null && sourcePaths.length > 0) {
                    sourceElement = ((ISourceLookupDirector) locator).getSourceElement(sourcePaths[0]);
                }
            }
        }
    } catch (DebugException e) {
        DebugPlugin.log(e);
    }
    if (sourceElement == null) {
        sourceElement = locator.getSourceElement(stackFrame);
    }
    if (!(sourceElement instanceof IJavaElement) && sourceElement instanceof IAdaptable) {
        Object element = ((IAdaptable) sourceElement).getAdapter(IJavaElement.class);
        if (element != null) {
            sourceElement = element;
        }
    }
    if (sourceElement instanceof IJavaElement) {
        return ((IJavaElement) sourceElement).getJavaProject();
    } else if (sourceElement instanceof IResource) {
        IJavaProject project = JavaCore.create(((IResource) sourceElement).getProject());
        if (project.exists()) {
            return project;
        }
    }
    return null;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IAdaptable(org.eclipse.core.runtime.IAdaptable) ISourceLookupDirector(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector) IJavaReferenceType(org.eclipse.jdt.debug.core.IJavaReferenceType) DebugException(org.eclipse.debug.core.DebugException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJavaType(org.eclipse.jdt.debug.core.IJavaType) ILaunch(org.eclipse.debug.core.ILaunch) ISourceLocator(org.eclipse.debug.core.model.ISourceLocator) IResource(org.eclipse.core.resources.IResource)

Example 92 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project xtext-eclipse by eclipse.

the class JdtIndexedJvmTypeAccess method findAccessibleType.

@Override
protected EObject findAccessibleType(String fragment, ResourceSet resourceSet, Iterator<IEObjectDescription> fromIndex) throws UnknownNestedTypeException {
    // we know that the iterator is not empty thus we can directly obtain the handles et al without additional guards
    IJavaProject javaProject = javaProjectProvider.getJavaProject(resourceSet);
    List<String> allVisibleContainerHandles = Lists.newArrayList(javaProjectsState.getVisibleContainerHandles(javaProject.getHandleIdentifier()));
    // some models are not in source folders thus we also use the WorkspaceProjectsState (e.g. relevant for Xcore)
    allVisibleContainerHandles.addAll(plainProjectsState.getVisibleContainerHandles(javaProject.getElementName()));
    List<String> visibleContainerHandles = allVisibleContainerHandles;
    IEObjectDescription bestDescription = null;
    while (fromIndex.hasNext() && !visibleContainerHandles.isEmpty()) {
        // find the description that is the best match, e.g. the one that is in the container closest to the first
        IEObjectDescription description = fromIndex.next();
        URI trimFragment = description.getEObjectURI().trimFragment();
        String handle = javaProjectsState.getContainerHandle(trimFragment);
        int idx = visibleContainerHandles.indexOf(handle);
        if (idx >= 0) {
            bestDescription = description;
            // reduce the search scope - only check containers that are better than the current
            visibleContainerHandles = allVisibleContainerHandles.subList(0, idx);
        }
    }
    if (bestDescription != null) {
        return getAccessibleType(bestDescription, fragment, resourceSet);
    }
    return null;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 93 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project xtext-eclipse by eclipse.

the class JdtTypesProposalProvider method createSubTypeProposals.

@Override
public void createSubTypeProposals(final JvmType superType, ICompletionProposalFactory proposalFactory, ContentAssistContext context, EReference typeReference, final Filter filter, IValueConverter<String> valueConverter, ICompletionProposalAcceptor acceptor) {
    if (superType == null || superType.eIsProxy())
        return;
    if (superType.eResource() == null || superType.eResource().getResourceSet() == null)
        return;
    IJavaProject project = getProjectProvider().getJavaProject(superType.eResource().getResourceSet());
    if (project == null)
        return;
    final String superTypeIdentifier = superType.getIdentifier();
    // java.lang.Object - no need to create hierarchy scope
    if (Object.class.getName().equals(superTypeIdentifier)) {
        createTypeProposals(project, proposalFactory, context, typeReference, filter, valueConverter, acceptor);
        return;
    }
    try {
        final Set<String> superTypeNames = Sets.newHashSet();
        final IJdtTypeProvider provider = jdtTypeProviderFactory.createTypeProvider(superType.eResource().getResourceSet());
        IJavaSearchScope scope = createSearchScope(project, superType, superTypeNames);
        searchAndCreateProposals(scope, proposalFactory, context, typeReference, TypeMatchFilters.and(filter, new ITypesProposalProvider.Filter() {

            @Override
            public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
                if (path == null || path.endsWith(".class") || path.endsWith(".java")) {
                    // Java index match
                    String identifier = getIdentifier(packageName, simpleTypeName, enclosingTypeNames);
                    if (!superTypeNames.contains(identifier)) {
                        return true;
                    }
                    return false;
                } else {
                    // accept match from dirty state
                    String identifier = getIdentifier(packageName, simpleTypeName, enclosingTypeNames);
                    if (identifier.equals(superTypeIdentifier)) {
                        return true;
                    }
                    JvmType candidate = provider.findTypeByName(identifier, true);
                    if (superTypeCollector.collect(candidate).contains(superType)) {
                        return true;
                    }
                    return false;
                }
            }

            @Override
            public int getSearchFor() {
                return filter.getSearchFor();
            }
        }), valueConverter, acceptor);
    } catch (JavaModelException ex) {
    // ignore
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJdtTypeProvider(org.eclipse.xtext.common.types.access.jdt.IJdtTypeProvider) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) EObject(org.eclipse.emf.ecore.EObject) StyledString(org.eclipse.jface.viewers.StyledString) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 94 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project xtext-eclipse by eclipse.

the class XtextResourceSetBasedProjectProvider method getJavaProject.

@Override
public IJavaProject getJavaProject(ResourceSet resourceSet) {
    if (resourceSet instanceof XtextResourceSet) {
        XtextResourceSet xtextResourceSet = (XtextResourceSet) resourceSet;
        Object context = xtextResourceSet.getClasspathURIContext();
        if (context instanceof IJavaProject)
            return (IJavaProject) context;
    }
    return null;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 95 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project xtext-eclipse by eclipse.

the class ProjectAwareResourceDescriptionsProvider method getProjectName.

@Override
protected String getProjectName(final ResourceSet resourceSet) {
    final IJavaProject javaProject = this.projectProvider.getJavaProject(resourceSet);
    String _elementName = null;
    if (javaProject != null) {
        _elementName = javaProject.getElementName();
    }
    return _elementName;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)743 IProject (org.eclipse.core.resources.IProject)178 IFile (org.eclipse.core.resources.IFile)149 Test (org.junit.Test)146 CoreException (org.eclipse.core.runtime.CoreException)127 JavaModelException (org.eclipse.jdt.core.JavaModelException)124 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)110 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)103 ArrayList (java.util.ArrayList)87 IFolder (org.eclipse.core.resources.IFolder)78 IResource (org.eclipse.core.resources.IResource)75 IJavaElement (org.eclipse.jdt.core.IJavaElement)63 IType (org.eclipse.jdt.core.IType)63 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)62 Path (org.eclipse.core.runtime.Path)57 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)56 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)47 StringInputStream (org.eclipse.xtext.util.StringInputStream)39 HashMap (java.util.HashMap)38