当前位置: 首页>>代码示例>>Java>>正文


Java IJavaProject类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.IJavaProject的典型用法代码示例。如果您正苦于以下问题:Java IJavaProject类的具体用法?Java IJavaProject怎么用?Java IJavaProject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IJavaProject类属于org.eclipse.jdt.core包,在下文中一共展示了IJavaProject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEnrichClass

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
@Test
public void testEnrichClass() throws Exception {
	IJavaProject pj = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME,true,false);
	
	IFile impl = ProjectHelper.createDummyClass (pj);
	ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(impl);
	IMethod m = compilationUnit.getTypes() [0].getMethod("runFunctionalTest",new String[0]);
	assertFalse (m.exists());

	IFile file = (IFile) ResourceManager.getResource(pj.getProject().getFullPath().append("src/test/resources/Simple.json").toString());
	ResourceContext context =  GenerationFactory.getResourceContext(file);
	ClassExtension ce = context.getClassExtension();
	ce.setGenerateRunFunctionalTest(true);
	ce.setStartElementForJunitTest("start_app");	
	TestResourceGeneration trg = new TestResourceGeneration(context);	 
	JDTManager.enrichClass(impl, trg, new NullProgressMonitor());
	
	m = compilationUnit.getTypes() [0].getMethod("runFunctionalTest",new String[0]);
	assertTrue (m.exists());
	
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:22,代码来源:JDTManagerTest.java

示例2: addJunit4Libraries

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * Add JUnit libraries to the passed project
 * 
 * @param project
 * @throws JavaModelException
 */
private static void addJunit4Libraries(IProject project) throws JavaModelException {
	IClasspathEntry entry = JavaCore.newContainerEntry(JUnitCore.JUNIT4_CONTAINER_PATH);
	IJavaProject javaProject = JavaCore.create(project);
	IClasspathEntry[] entries = javaProject.getRawClasspath();
	boolean junitFound = false;
	String s = entry.getPath().toString();
	for (int i = 0; i < entries.length; i++) {
		if (entries[i].getPath().toString().indexOf(s) != -1) {
			junitFound = true;
			break;
		}
	}
	if (!junitFound) {
		IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
		System.arraycopy(entries, 0, newEntries, 0, entries.length);
		newEntries[entries.length] = entry;
		javaProject.setRawClasspath(newEntries, null);
	}
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:26,代码来源:ClasspathManager.java

示例3: collectAllCompilationUnits

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * Collects all compilation units within the project.
 * @return the collection of the compilation units
 */
public static List<ICompilationUnit> collectAllCompilationUnits() {
    List<ICompilationUnit> units = new ArrayList<ICompilationUnit>();
    
    try {
        IProject[] projects =  getWorkspace().getRoot().getProjects();
        for (int i = 0; i < projects.length; i++) {
            IJavaProject project = (IJavaProject)JavaCore.create((IProject)projects[i]);
            
            IPackageFragment[] packages = project.getPackageFragments();
            for (int j = 0; j < packages.length; j++) {
                
                ICompilationUnit[] cus = packages[j].getCompilationUnits();
                for (int k = 0; k < cus.length; k++) {
                    IResource res = cus[k].getResource();
                    if (res.getType() == IResource.FILE) {
                        String name = cus[k].getPath().toString();
                        if (name.endsWith(".java")) { 
                            units.add(cus[k]);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    
    return units;
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:34,代码来源:WorkspaceUtilities.java

示例4: findClassesWithAnnotation

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * @param projectName
 * @return
 * @throws JavaModelException
 */
private static List<IType> findClassesWithAnnotation(String projectName, Class annotationClass, String attributName,
		boolean valued) throws JavaModelException {
	List<IType> classList = new ArrayList<IType>();
	IProject project = ResourceManager.getProject(projectName);
	IJavaProject javaProject = JavaCore.create(project);
	IPackageFragment[] packages = javaProject.getPackageFragments();
	for (IPackageFragment packageFragment : packages) {
		for (final ICompilationUnit compilationUnit : packageFragment.getCompilationUnits()) {
			if (compilationUnit.exists()) {
				IType type = getClassesWithAnnotation(compilationUnit, annotationClass, attributName, valued);
				if (type != null)
					classList.add(type);
			}
		}
	}
	return classList;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:23,代码来源:JDTManager.java

示例5: getGW4EProjects

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
public static IJavaProject[] getGW4EProjects() {
	IJavaProject[] projects;
	try {
		projects = JavaCore.create(ResourceManager.getWorkspaceRoot()).getJavaProjects();
	} catch (JavaModelException e) {
		ResourceManager.logException(e);
		projects = new IJavaProject[0];
	}
	List<IJavaProject> gwps = new ArrayList<IJavaProject>();
	for (int i = 0; i < projects.length; i++) {
		if (GW4ENature.hasGW4ENature(projects[i].getProject())) {
			gwps.add(projects[i]);
		}
	}

	IJavaProject[] gwprojects = new IJavaProject[gwps.size()];
	gwps.toArray(gwprojects);
	return gwprojects;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:20,代码来源:GraphWalkerContextManager.java

示例6: chooseGW4EProject

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
public static IJavaProject chooseGW4EProject(IJavaProject javaProject) {
	Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
	IJavaProject[] projects = getGW4EProjects();
	ILabelProvider labelProvider = new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT);
	ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, labelProvider);
	dialog.setTitle(MessageUtil.getString("projectdialog_title"));
	dialog.setMessage(MessageUtil.getString("projectdialog_message"));
	dialog.setElements(projects);

	if (javaProject != null) {
		dialog.setInitialSelections(new Object[] { javaProject });
	}
	if (dialog.open() == Window.OK) {
		return (IJavaProject) dialog.getFirstResult();
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:18,代码来源:GraphWalkerContextManager.java

示例7: getIFileFromQualifiedName

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * @param project
 * @param qualifiedName
 * @return
 * @throws CoreException
 */
public static IFile getIFileFromQualifiedName(String projectname, String qualifiedName) throws CoreException {
	IProject project = getProject(projectname);
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragment[] pkgs = jproject.getPackageFragments();
	String spath = qualifiedName.replace(".", "/");
	for (int i = 0; i < pkgs.length; i++) {
		if (pkgs[i].getKind() != IPackageFragmentRoot.K_SOURCE)
			continue;
		IPath path = pkgs[i].getPath().append(spath);
		IFile iFile = (IFile) ResourceManager.getResource(path.toString() + ".java");
		if (iFile != null && iFile.exists())
			return iFile;
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:22,代码来源:ResourceManager.java

示例8: getFilteredSourceFolders

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * @param projectName
 * @return the direct child folders of the project
 * @throws CoreException
 */
public static List<String> getFilteredSourceFolders(String projectName, String[] excludes) throws CoreException {
	List<String> ret = new ArrayList<String>();
	IJavaProject javaProject = (IJavaProject) JavaCore.create(getProject(projectName));
	IClasspathEntry[] entries = javaProject.getRawClasspath();
	for (int i = 0; i < entries.length; i++) {
		IClasspathEntry entry = entries[i];
		if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
			IPath path = entry.getPath().makeRelativeTo(new Path(projectName));
			boolean isExcluded = false;
			for (int j = 0; j < excludes.length; j++) {

				if (excludes[j].equalsIgnoreCase(path.toString())) {
					isExcluded = true;
					break;
				}
			}
			if (!isExcluded) {
				String p = path.toString();
				ret.add(p);
			}
		}
	}

	return ret;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:31,代码来源:ResourceManager.java

示例9: getMarkers

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
public static IMarker[] getMarkers(IJavaProject project, int problemID) throws CoreException {
	IMarker[] markers = project.getProject().findMarkers(GW4EBuilder.MARKER_TYPE, true, IResource.DEPTH_INFINITE);
	List<IMarker> ms = new ArrayList<IMarker>();
	for (IMarker iMarker : markers) {
		Object attr = iMarker.getAttribute(IJavaModelMarker.ID);
		Integer pbid = (Integer) attr;
		if (pbid == null)
			continue;
		if (pbid.equals(problemID)) {
			ms.add(iMarker);
		}
	}
	IMarker[] ret = new IMarker[ms.size()];
	ms.toArray(ret);
	return ret;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:17,代码来源:ProjectHelper.java

示例10: getPathWithinPackageFragment

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * Return a path relative to its package fragment root
 * 
 * @param project
 * @param path
 * @return
 * @throws JavaModelException
 */
public static IPath getPathWithinPackageFragment(IResource ifile) throws JavaModelException {
	IProject project = ifile.getProject();
	IPath path = ifile.getFullPath();
	String[] segments = path.segments();
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragment[] pkgs = jproject.getPackageFragments();
	IPath p = new Path("/");
	for (int i = 0; i < segments.length; i++) {
		for (int j = 0; j < pkgs.length; j++) {
			if (pkgs[j].getPath().equals(p)) {
				IPath ret = path.makeRelativeTo(pkgs[j].getPath());
				return ret;
			}
		}
		p = p.append(segments[i]);
	}
	return null;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:27,代码来源:ResourceManager.java

示例11: getSelectedPathInProject

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * Lets get the path of hat have been selected in the UI - the complete path
 * a path is something like "src/main/resources"
 * 
 * @param receiver
 * @return
 */
public static String getSelectedPathInProject(Object receiver) {
	if (!ResourceManager.isPackageFragmentRoot(receiver)) {
		return null;
	}
	IPackageFragmentRoot pkg = (IPackageFragmentRoot) receiver;

	IJavaProject javaProject = pkg.getJavaProject();
	if (javaProject == null)
		return null;

	IProject project = javaProject.getProject();

	if (!GW4ENature.hasGW4ENature(project))
		return null;

	String projectName = pkg.getJavaProject().getElementName();
	int pos = projectName.length();
	String input = pkg.getPath().toString().substring(pos + 2);
	return input;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:28,代码来源:ResourceManager.java

示例12: isFileInFolders

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * Return whether the resource is in of the passed folders
 * 
 * @param resource
 * @param folders
 * @return
 */
public static boolean isFileInFolders(IFile resource, String[] folders) {
	if (resource == null)
		return false;
	IProject p = resource.getProject();
	IJavaProject javaProject = JavaCore.create(p);
	for (int i = 0; i < folders.length; i++) {
		IPath folderPath = javaProject.getPath().append(folders[i]);
		String allowedPAth = folderPath.toString();
		String resourcePath = resource.getFullPath().toString();
		if (resourcePath.startsWith(allowedPAth)) {
			return true;
		}
	}
	return false;
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:23,代码来源:ResourceManager.java

示例13: assertHasSourceFolders

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
public void assertHasSourceFolders(String[] folders) throws JavaModelException {
	IProject project = getRoot().getProject(this.projectName);
	IJavaProject jproject = JavaCore.create(project);
	IPackageFragmentRoot[] pkgs = jproject.getPackageFragmentRoots();

	for (int i = 0; i < folders.length; i++) {
		String folder = folders[i];
		boolean found = false;
		for (int j = 0; j < pkgs.length; j++) {
			IPackageFragmentRoot pkg = pkgs[j];
			IPath path = new Path("/").append(this.projectName).append(folder);
			if (pkg.getPath().toString().equalsIgnoreCase(path.toString())) {
				found = true;
			}
			;
		}
		assertTrue("Expected folder: " + folder, found);
	}
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:20,代码来源:GW4EProject.java

示例14: findElement

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * Returns the class file or compilation unit containing the given fully
 * qualified name in the specified project. All registered java like file
 * extensions are considered.
 *
 * @param qualifiedTypeName
 *            fully qualified type name
 * @param project
 *            project to search in
 * @return class file or compilation unit or <code>null</code>
 * @throws CoreException
 *             if an exception occurs
 */
public static IJavaElement findElement(String qualifiedTypeName, IJavaProject project) throws CoreException {
    String path = qualifiedTypeName;

    final String[] javaLikeExtensions = JavaCore.getJavaLikeExtensions();
    int pos = path.indexOf('$');
    if (pos != -1) {
        path = path.substring(0, pos);
    }
    path = path.replace('.', IPath.SEPARATOR);
    path += "."; //$NON-NLS-1$
    for (String ext : javaLikeExtensions) {
        IJavaElement element = project.findElement(new Path(path + ext));
        if (element != null) {
            return element;
        }
    }
    return null;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:32,代码来源:JavaHotCodeReplaceProvider.java

示例15: getProjectMap

import org.eclipse.jdt.core.IJavaProject; //导入依赖的package包/类
/**
 * Obtient la map Project vers Projet Java du workspace courant.
 * 
 * @return Map des projets.
 */
public static JavaProjectMap getProjectMap() {
	JavaProjectMap projects = new JavaProjectMap();

	/* Racine du workspace courant. */
	IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();

	/* Parcourt les projets de la racine. */
	for (IProject project : wsRoot.getProjects()) {

		/* Vérication que le projet est un projet Java accessible. */
		if (!project.isAccessible() || !JdtUtils.isJavaProject(project)) {
			continue;
		}

		/* Obtient l'AST du projet. */
		IJavaProject javaProject = JavaCore.create(project);
		projects.put(project, javaProject);
	}
	return projects;
}
 
开发者ID:sebez,项目名称:vertigo-chroma-kspplugin,代码行数:26,代码来源:ResourceUtils.java


注:本文中的org.eclipse.jdt.core.IJavaProject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。