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;
}
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;
}
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
}
}
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;
}
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;
}
Aggregations