use of org.eclipse.jdt.core.IJavaModel in project liferay-ide by liferay.
the class ProjectSelectionDialog method createDialogArea.
/**
* (non-Javadoc) Method declared on Dialog.
*/
protected Control createDialogArea(Composite parent) {
// page group
Composite composite = (Composite) super.createDialogArea(parent);
Font font = parent.getFont();
composite.setFont(font);
createMessageArea(composite);
fTableViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
fTableViewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
updateOKButtonState(event);
}
});
addSelectionButtons(composite);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.heightHint = _sizingSelectionWidgetHeight;
data.widthHint = _sizingSelectionWidgetWidth;
fTableViewer.getTable().setLayoutData(data);
fTableViewer.setLabelProvider(new JavaElementLabelProvider());
fTableViewer.setContentProvider(getContentProvider());
fTableViewer.setComparator(new JavaElementComparator());
fTableViewer.getControl().setFont(font);
updateFilter(true);
IJavaModel input = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
fTableViewer.setInput(input);
initialize();
_selectionChanged(new Object[0]);
Dialog.applyDialogFont(composite);
return composite;
}
use of org.eclipse.jdt.core.IJavaModel in project mdw-designer by CenturyLinkCloud.
the class JavaSourceHyperlink method getJavaElement.
/**
* find the source element in the project
*
* @param type
* @return the source element
* @throws JavaModelException
* @throws CoreException
*/
protected Object getJavaElement(String type) throws JavaModelException, CoreException {
Object element = null;
if (project == null) {
cantFindSourceWarning();
return null;
}
if (element == null) {
QualifiedName qName = new QualifiedName(MdwPlugin.getPluginId(), "MdwSourceLookupAllJavaProjects");
String setting = project.getProject().getPersistentProperty(qName);
boolean check = (setting != null && Boolean.valueOf(setting));
if (!check) {
String msg = "Can't locate source code for:\n" + getTypeName() + (project == null ? "" : " in project " + project.getProject().getName());
String toggleMessage = "Look in all workspace Java projects for this deployment.";
MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(MdwPlugin.getShell(), "Java Source Lookup", msg, toggleMessage, false, null, null);
check = dialog.getToggleState();
project.getProject().setPersistentProperty(qName, String.valueOf(check));
}
if (check) {
IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
for (IJavaProject javaProj : javaModel.getJavaProjects()) {
Object javaElem = getJavaElement(javaProj, type);
if (javaElem != null) {
element = javaElem;
break;
}
}
}
}
return element;
}
use of org.eclipse.jdt.core.IJavaModel in project eclipse-integration-commons by spring-projects.
the class JdtUtils method getAllDependingJavaProjects.
/**
* Checks if the given <code>type</code> implements/extends
* <code>className</code>.
*/
// public static boolean doesImplement(IResource resource, IType type,
// String className) {
// if (resource == null || type == null || className == null) {
// return false;
// }
// if (className.startsWith("java.") || className.startsWith("javax.")) {
// try {
// ClassLoader cls = getClassLoader(resource.getProject(), null);
// Class<?> typeClass = cls.loadClass(type.getFullyQualifiedName('$'));
// Class<?> interfaceClass = cls.loadClass(className);
// return typeClass.equals(interfaceClass) ||
// interfaceClass.isAssignableFrom(typeClass);
// }
// catch (Throwable e) {
// // ignore this and fall back to JDT does implement checks
// }
// }
// return doesImplementWithJdt(resource, type, className);
// }
// public static IType getAjdtType(IProject project, String className) {
// IJavaProject javaProject = getJavaProject(project);
// if (IS_AJDT_PRESENT && javaProject != null && className != null) {
//
// try {
// IType type = null;
//
// // First look for the type in the project
// if (isAjdtProject(project)) {
// type = AjdtUtils.getAjdtType(project, className);
// if (type != null) {
// return type;
// }
// }
//
// // Then look for the type in the referenced Java projects
// for (IProject refProject : project.getReferencedProjects()) {
// if (isAjdtProject(refProject)) {
// type = AjdtUtils.getAjdtType(refProject, className);
// if (type != null) {
// return type;
// }
// }
// }
// }
// catch (CoreException e) {
// StatusHandler.log(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID,
// "Error getting Java type '"
// + className + "'", e));
// }
// }
// return null;
// }
public static List<IJavaProject> getAllDependingJavaProjects(IJavaProject project) {
List<IJavaProject> javaProjects = new ArrayList<IJavaProject>();
IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
if (model != null) {
try {
String[] names = project.getRequiredProjectNames();
IJavaProject[] projects = model.getJavaProjects();
for (IJavaProject project2 : projects) {
for (String name2 : names) {
String name = project2.getProject().getName();
if (name.equals(name2)) {
javaProjects.add(project2);
}
}
}
} catch (JavaModelException exception) {
}
}
return javaProjects;
}
use of org.eclipse.jdt.core.IJavaModel in project che by eclipse.
the class DeltaProcessingState method getRootInfos.
private HashMap[] getRootInfos(boolean usePreviousSession) {
HashMap newRoots = new HashMap();
HashMap newOtherRoots = new HashMap();
HashMap newSourceAttachments = new HashMap();
HashMap newProjectDependencies = new HashMap();
IJavaModel model = manager.getJavaModel();
IJavaProject[] projects;
try {
projects = model.getJavaProjects();
} catch (JavaModelException e) {
// nothing can be done
return null;
}
for (int i = 0, length = projects.length; i < length; i++) {
JavaProject project = (JavaProject) projects[i];
IClasspathEntry[] classpath;
try {
// if (usePreviousSession) {
// PerProjectInfo perProjectInfo = project.getPerProjectInfo();
// project.resolveClasspath(perProjectInfo, true/*use previous session values*/, false/*don't add classpath change*/);
// classpath = perProjectInfo.resolvedClasspath;
// } else {
classpath = project.getResolvedClasspath();
// }
} catch (JavaModelException e) {
// continue with next project
continue;
}
for (int j = 0, classpathLength = classpath.length; j < classpathLength; j++) {
IClasspathEntry entry = classpath[j];
if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
// TODO (jerome) reuse handle
IJavaProject key = model.getJavaProject(entry.getPath().segment(0));
IJavaProject[] dependents = (IJavaProject[]) newProjectDependencies.get(key);
if (dependents == null) {
dependents = new IJavaProject[] { project };
} else {
int dependentsLength = dependents.length;
System.arraycopy(dependents, 0, dependents = new IJavaProject[dependentsLength + 1], 0, dependentsLength);
dependents[dependentsLength] = project;
}
newProjectDependencies.put(key, dependents);
continue;
}
// root path
IPath path = entry.getPath();
if (newRoots.get(path) == null) {
newRoots.put(path, new DeltaProcessor.RootInfo(project, path, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars(), entry.getEntryKind()));
} else {
ArrayList rootList = (ArrayList) newOtherRoots.get(path);
if (rootList == null) {
rootList = new ArrayList();
newOtherRoots.put(path, rootList);
}
rootList.add(new DeltaProcessor.RootInfo(project, path, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars(), entry.getEntryKind()));
}
// source attachment path
if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY)
continue;
String propertyString = null;
// try {
// propertyString = Util.getSourceAttachmentProperty(path);
// } catch (JavaModelException e) {
// e.printStackTrace();
// }
IPath sourceAttachmentPath;
if (propertyString != null) {
int index = propertyString.lastIndexOf(PackageFragmentRoot.ATTACHMENT_PROPERTY_DELIMITER);
sourceAttachmentPath = (index < 0) ? new Path(propertyString) : new Path(propertyString.substring(0, index));
} else {
sourceAttachmentPath = entry.getSourceAttachmentPath();
}
if (sourceAttachmentPath != null) {
newSourceAttachments.put(sourceAttachmentPath, path);
}
}
}
return new HashMap[] { newRoots, newOtherRoots, newSourceAttachments, newProjectDependencies };
}
use of org.eclipse.jdt.core.IJavaModel in project che by eclipse.
the class JavaSearchScope method add.
/**
* Add a path to current java search scope or all project fragment roots if null.
* Use project resolved classpath to retrieve and store access restriction on each classpath entry.
* Recurse if dependent projects are found.
* @param javaProject Project used to get resolved classpath entries
* @param pathToAdd Path to add in case of single element or null if user want to add all project package fragment roots
* @param includeMask Mask to apply on classpath entries
* @param projectsToBeAdded Set to avoid infinite recursion
* @param visitedProjects Set to avoid adding twice the same project
* @param referringEntry Project raw entry in referring project classpath
* @throws JavaModelException May happen while getting java model info
*/
void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded, HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException {
IProject project = javaProject.getProject();
if (!project.isAccessible() || !visitedProjects.add(project))
return;
IPath projectPath = project.getFullPath();
String projectPathString = projectPath.toString();
addEnclosingProjectOrJar(projectPath);
IClasspathEntry[] entries = javaProject.getResolvedClasspath();
IJavaModel model = javaProject.getJavaModel();
JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo();
for (int i = 0, length = entries.length; i < length; i++) {
IClasspathEntry entry = entries[i];
AccessRuleSet access = null;
ClasspathEntry cpEntry = (ClasspathEntry) entry;
if (referringEntry != null) {
// Source folder are implicitly exported.
if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
continue;
}
cpEntry = cpEntry.combineWith((ClasspathEntry) referringEntry);
// cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry);
}
access = cpEntry.getAccessRuleSet();
switch(entry.getEntryKind()) {
case IClasspathEntry.CPE_LIBRARY:
IClasspathEntry rawEntry = null;
Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries;
if (rootPathToRawEntries != null) {
rawEntry = (IClasspathEntry) rootPathToRawEntries.get(entry.getPath());
}
if (rawEntry == null)
break;
rawKind: switch(rawEntry.getEntryKind()) {
case IClasspathEntry.CPE_LIBRARY:
case IClasspathEntry.CPE_VARIABLE:
if ((includeMask & APPLICATION_LIBRARIES) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
//$NON-NLS-1$
add(projectPath.toString(), "", pathToString, false, /*not a package*/
access);
addEnclosingProjectOrJar(entry.getPath());
}
}
break;
case IClasspathEntry.CPE_CONTAINER:
IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject);
if (container == null)
break;
switch(container.getKind()) {
case IClasspathContainer.K_APPLICATION:
if ((includeMask & APPLICATION_LIBRARIES) == 0)
break rawKind;
break;
case IClasspathContainer.K_SYSTEM:
case IClasspathContainer.K_DEFAULT_SYSTEM:
if ((includeMask & SYSTEM_LIBRARIES) == 0)
break rawKind;
break;
default:
break rawKind;
}
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
Object target = JavaModel.getTarget(path, false);
if (// case of an external folder
target instanceof IFolder)
path = ((IFolder) target).getFullPath();
String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
//$NON-NLS-1$
add(projectPath.toString(), "", pathToString, false, /*not a package*/
access);
addEnclosingProjectOrJar(entry.getPath());
}
break;
}
break;
case IClasspathEntry.CPE_PROJECT:
if ((includeMask & REFERENCED_PROJECTS) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
JavaProject referencedProject = (JavaProject) model.getJavaProject(path.toOSString());
if (!projectsToBeAdded.contains(referencedProject)) {
// do not recurse if depending project was used to create the scope
add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry);
}
}
}
break;
case IClasspathEntry.CPE_SOURCE:
if ((includeMask & SOURCES) != 0) {
IPath path = entry.getPath();
if (pathToAdd == null || pathToAdd.equals(path)) {
add(projectPath.toString(), Util.relativePath(path, projectPath.segmentCount()), projectPathString, false, /*not a package*/
access);
}
}
break;
}
}
}
Aggregations