use of org.eclipse.jdt.core.ClasspathContainerInitializer in project che by eclipse.
the class ReorgCorrectionsSubProcessor method canModifyAccessRules.
private static boolean canModifyAccessRules(IBinding binding) {
IJavaElement element = binding.getJavaElement();
if (element == null)
return false;
IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element);
if (root == null)
return false;
try {
IClasspathEntry classpathEntry = root.getRawClasspathEntry();
if (classpathEntry == null)
return false;
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
return true;
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
ClasspathContainerInitializer classpathContainerInitializer = JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0));
IStatus status = classpathContainerInitializer.getAccessRulesStatus(classpathEntry.getPath(), root.getJavaProject());
return status.isOK();
}
} catch (JavaModelException e) {
return false;
}
return false;
}
use of org.eclipse.jdt.core.ClasspathContainerInitializer in project che by eclipse.
the class JavaElementLabels method getContainerEntryLabel.
/**
* Returns the label of a classpath container.
* The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
*
* @param containerPath the path of the container
* @param project the project the container is resolved in
* @return the label of the classpath container
* @throws JavaModelException when resolving of the container failed
*/
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project);
if (container != null) {
return Strings.markLTR(container.getDescription());
}
ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
if (initializer != null) {
return Strings.markLTR(initializer.getDescription(containerPath, project));
}
return BasicElementLabels.getPathLabel(containerPath, false);
}
use of org.eclipse.jdt.core.ClasspathContainerInitializer in project che by eclipse.
the class JavaElementLabels method getStyledContainerEntryLabel.
/**
* Returns the styled label of a classpath container.
* The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
*
* @param containerPath the path of the container
* @param project the project the container is resolved in
* @return the label of the classpath container
*
* @since 3.4
*/
public static StyledString getStyledContainerEntryLabel(IPath containerPath, IJavaProject project) {
try {
IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project);
String description = null;
if (container != null) {
description = container.getDescription();
}
if (description == null) {
ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
if (initializer != null) {
description = initializer.getDescription(containerPath, project);
}
}
if (description != null) {
StyledString str = new StyledString(description);
// }
return Strings.markLTR(str);
}
} catch (JavaModelException e) {
// ignore
}
return new StyledString(BasicElementLabels.getPathLabel(containerPath, false));
}
use of org.eclipse.jdt.core.ClasspathContainerInitializer in project che by eclipse.
the class JavaModelManager method initializeContainer.
private IClasspathContainer initializeContainer(IJavaProject project, IPath containerPath) throws JavaModelException {
ClasspathContainerInitializer initializer = containerInitializersCache.get(containerPath.segment(0));
IClasspathContainer container = null;
if (initializer != null) {
// avoid initialization cycles
containerPut(project, containerPath, CONTAINER_INITIALIZATION_IN_PROGRESS);
try {
initializer.initialize(containerPath, project);
// if (monitor != null)
// monitor.subTask(""); //$NON-NLS-1$
// retrieve value (if initialization was successful)
container = containerBeingInitializedGet(project, containerPath);
if (container == null && containerGet(project, containerPath) == null) {
// initializer failed to do its job: redirect to the failure container
container = initializer.getFailureContainer(containerPath, project);
// if (container == null) {
// if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
// verbose_container_null_failure_container(project, containerPath, initializer);
// return null; // break cycle
// }
// if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
// verbose_container_using_failure_container(project, containerPath, initializer);
containerPut(project, containerPath, container);
}
} catch (CoreException e) {
if (e instanceof JavaModelException) {
throw (JavaModelException) e;
} else {
throw new JavaModelException(e);
}
}
} else {
// create a dummy initializer and get the default failure container
container = (new ClasspathContainerInitializer() {
public void initialize(IPath path, IJavaProject javaProject) throws CoreException {
// not used
}
}).getFailureContainer(containerPath, project);
}
return container;
}
use of org.eclipse.jdt.core.ClasspathContainerInitializer in project bndtools by bndtools.
the class BndContainerInitializer method suggestClasspathContainerUpdate.
/**
* Suggests whether an update request on the classpath container, if there is one, should be made.
*
* @param javaProject
* The java project of interest. Must not be null.
* @throws CoreException
*/
public static boolean suggestClasspathContainerUpdate(IJavaProject javaProject) throws Exception {
if (getClasspathContainer(javaProject) == null) {
// project does not have a BndContainer
return false;
}
ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(BndtoolsConstants.BND_CLASSPATH_ID.segment(0));
if (initializer == null) {
return false;
}
IProject project = javaProject.getProject();
Updater updater = new Updater(project, javaProject);
return updater.suggestClasspathContainerUpdate();
}
Aggregations