本文整理汇总了Java中org.eclipse.jdt.core.IJavaModel.getJavaProject方法的典型用法代码示例。如果您正苦于以下问题:Java IJavaModel.getJavaProject方法的具体用法?Java IJavaModel.getJavaProject怎么用?Java IJavaModel.getJavaProject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IJavaModel
的用法示例。
在下文中一共展示了IJavaModel.getJavaProject方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJavaProject
import org.eclipse.jdt.core.IJavaModel; //导入方法依赖的package包/类
public static IJavaProject getJavaProject(String projectName) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if (workspace == null) {
System.out.println("No workspace");
return null;
}
IWorkspaceRoot root = workspace.getRoot();
if (root == null) {
System.out.println("No workspace root");
return null;
}
IJavaModel javacore = JavaCore.create(root);// this gets you the java version of the workspace
IJavaProject project = null;
if (javacore != null) {
project = javacore.getJavaProject(projectName); // this returns the specified project
}
WorkspaceUtilities.javaProject = project;
return project;
}
示例2: testFindSdkFor_GwtUserProject
import org.eclipse.jdt.core.IJavaModel; //导入方法依赖的package包/类
/**
* Tests that we find an {@link com.google.gdt.eclipse.core.sdk.Sdk} on the
* gwt-user project.
*
* @throws Exception
*/
public void testFindSdkFor_GwtUserProject() throws Exception {
GwtRuntimeTestUtilities.importGwtSourceProjects();
try {
IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
IJavaProject javaProject = javaModel.getJavaProject("gwt-user");
GwtSdk sdk = GwtSdk.findSdkFor(javaProject);
IClasspathEntry gwtUserEntry =
JavaCore.newSourceEntry(
javaModel.getJavaProject("gwt-user").getPath().append("core/src"),
new IPath[] {new Path("**/super/**")});
/*
* NOTE: Passing null for the IClasspathAttribute array tickles a bug in
* eclipse 3.3.
*/
IClasspathEntry gwtDevEntry =
JavaCore.newProjectEntry(javaModel.getJavaProject("gwt-dev").getPath(), null, false,
new IClasspathAttribute[0] /* */, false);
IClasspathEntry[] expected = new IClasspathEntry[] {gwtUserEntry, gwtDevEntry};
assertEquals(expected, sdk.getClasspathEntries());
} finally {
GwtRuntimeTestUtilities.removeGwtSourceProjects();
}
}
示例3: getJavaProject
import org.eclipse.jdt.core.IJavaModel; //导入方法依赖的package包/类
private static IJavaProject getJavaProject(final IContainer container) {
if (container != null) {
if (container instanceof IProject) {
final IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
return model.getJavaProject(container.getName());
}
return getJavaProject(container.getParent());
}
return null;
}
示例4: chooseJavaProject
import org.eclipse.jdt.core.IJavaModel; //导入方法依赖的package包/类
/**
* Displays a project chooser dialog which lists all available projects with the Android nature.
* <p/>
* The list of project is built from Android flagged projects currently opened in the workspace.
*
* @param projectName If non null and not empty, represents the name of an Android project
* that will be selected by default.
* @param message Message for the dialog box. Can be null in which case a default message
* is displayed.
* @return the project chosen by the user in the dialog, or null if the dialog was canceled.
*/
public IJavaProject chooseJavaProject(String projectName, String message) {
ILabelProvider labelProvider = new JavaElementLabelProvider(
JavaElementLabelProvider.SHOW_DEFAULT);
ElementListSelectionDialog dialog = new ElementListSelectionDialog(
mParentShell, labelProvider);
dialog.setTitle("Project Selection");
if (message == null) {
message = "Please select a project";
}
dialog.setMessage(message);
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IJavaModel javaModel = JavaCore.create(workspaceRoot);
// set the elements in the dialog. These are opened android projects.
dialog.setElements(getAguiProjects(javaModel));
// look for the project matching the given project name
IJavaProject javaProject = null;
if (projectName != null && projectName.length() > 0) {
javaProject = javaModel.getJavaProject(projectName);
}
// if we found it, we set the initial selection in the dialog to this one.
if (javaProject != null) {
dialog.setInitialSelections(new Object[] { javaProject });
}
// open the dialog and return the object selected if OK was clicked, or null otherwise
if (dialog.open() == Window.OK) {
return (IJavaProject) dialog.getFirstResult();
}
return null;
}
示例5: getJavaProject
import org.eclipse.jdt.core.IJavaModel; //导入方法依赖的package包/类
/**
* Return the {@link IJavaProject} corresponding to the project name in the project
* name text field, or null if the text does not match a project name.
* @param javaModel the Java Model object corresponding for the current workspace root.
* @return a IJavaProject object or null.
*/
protected IJavaProject getJavaProject(IJavaModel javaModel) {
String projectName = mProjText.getText().trim();
if (projectName.length() < 1) {
return null;
}
return javaModel.getJavaProject(projectName);
}
示例6: getJavaProject
import org.eclipse.jdt.core.IJavaModel; //导入方法依赖的package包/类
/**
* Returns the java project that corresponds to the given path. Returns null if the path doesn't
* correspond to a project.
*/
private static IJavaProject getJavaProject(IPath path, IJavaModel model) {
IJavaProject project = model.getJavaProject(path.toOSString() /*.lastSegment()*/);
if (project.exists()) {
return project;
}
return null;
}
示例7: getJavaProject
import org.eclipse.jdt.core.IJavaModel; //导入方法依赖的package包/类
public IJavaProject getJavaProject(String projectName) {
if (projectName != null && projectName.length() > 0) {
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IJavaModel javaModel = JavaCore.create(workspaceRoot);
return javaModel.getJavaProject(projectName);
} else {
return null;
}
}
示例8: testFindSdkFor_GwtDevProject
import org.eclipse.jdt.core.IJavaModel; //导入方法依赖的package包/类
/**
* Tests that we find an {@link com.google.gdt.eclipse.core.sdk.Sdk} on the
* gwt-user project. Note this test uses gwt-dev instead of gwt-dev-${PLAT} as
* the dev project name.
*/
public void testFindSdkFor_GwtDevProject() throws Exception {
GwtRuntimeTestUtilities.importGwtSourceProjects();
try {
IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
IJavaProject javaProject = javaModel.getJavaProject("gwt-dev");
GwtSdk sdk = GwtSdk.findSdkFor(javaProject);
IClasspathEntry[] entries = sdk.getClasspathEntries();
assertEquals(new IClasspathEntry[] {JavaCore.newSourceEntry(javaModel.getJavaProject(
"gwt-dev").getPath().append("core/src"))}, entries);
} finally {
GwtRuntimeTestUtilities.removeGwtSourceProjects();
}
}
示例9: getMemberType
import org.eclipse.jdt.core.IJavaModel; //导入方法依赖的package包/类
private static IType getMemberType(String projectName, String pack, String name) {
// IWorkspaceRoot root = JavaPlugin.getWorkspace().getRoot();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IJavaModel model = JavaCore.create(root);
IJavaProject project = model.getJavaProject(projectName);
IType member = null;
try {
member = project.findType(pack, name);
} catch (JavaModelException e1) {
// return uninitialized member !!!
// e1.printStackTrace();
}
return member;
}