當前位置: 首頁>>代碼示例>>Java>>正文


Java IJavaProject.findElement方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.IJavaProject.findElement方法的典型用法代碼示例。如果您正苦於以下問題:Java IJavaProject.findElement方法的具體用法?Java IJavaProject.findElement怎麽用?Java IJavaProject.findElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.IJavaProject的用法示例。


在下文中一共展示了IJavaProject.findElement方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getSourceFile

import org.eclipse.jdt.core.IJavaProject; //導入方法依賴的package包/類
/**
 * Returns the source file associated with the given type, or <code>null</code>
 * if no source file could be found.
 *
 * @param project
 *            the java project containing the classfile
 * @param qualifiedName
 *            fully qualified name of the type, slash delimited
 * @param sourceAttribute
 *            debug source attribute, or <code>null</code> if none
 */
private IResource getSourceFile(IJavaProject project, String qualifiedName, String sourceAttribute) {
    String name = null;
    IJavaElement element = null;
    try {
        if (sourceAttribute == null) {
            element = findElement(qualifiedName, project);
        } else {
            int i = qualifiedName.lastIndexOf('/');
            if (i > 0) {
                name = qualifiedName.substring(0, i + 1);
                name = name + sourceAttribute;
            } else {
                name = sourceAttribute;
            }
            element = project.findElement(new Path(name));
        }
        if (element instanceof ICompilationUnit) {
            ICompilationUnit cu = (ICompilationUnit) element;
            return cu.getCorrespondingResource();
        }
    } catch (CoreException e) {
        logger.log(Level.INFO, "Failed to get source file with exception" + e.getMessage(), e);
    }
    return null;
}
 
開發者ID:Microsoft,項目名稱:java-debug,代碼行數:37,代碼來源:JavaHotCodeReplaceProvider.java

示例2: 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

示例3: testGetPackageFragmentRoot

import org.eclipse.jdt.core.IJavaProject; //導入方法依賴的package包/類
@Test
public void testGetPackageFragmentRoot() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true, false);
	ResourceManager.createFile(project.getProject().getName(), "src/test/resources", "mypkg/subpkg", "test.java",
			"");
	IPackageFragment frag = (IPackageFragment) project.findElement(new Path("mypkg/subpkg"));

	IPackageFragmentRoot pfr = ResourceManager.getPackageFragmentRoot(project.getProject(), frag);
	assertNotNull(pfr);
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:11,代碼來源:ResourceManagerTest.java

示例4: testGetPackageFragment

import org.eclipse.jdt.core.IJavaProject; //導入方法依賴的package包/類
@Test
public void testGetPackageFragment() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true, false);
	ResourceManager.createFile(project.getProject().getName(), "src/test/resources", "mypkg/subpkg", "test.java",
			"");
	IPackageFragment pf = ResourceManager.getPackageFragment(project.getProject(),
			new Path("src/test/resources/mypkg/subpkg"));
	assertNotNull(pf);

	IPackageFragment frag = (IPackageFragment) project.findElement(new Path("mypkg/subpkg"));
	IPackageFragmentRoot pfr = ResourceManager.getPackageFragmentRoot(project.getProject(), frag);
	pf = ResourceManager.getPackageFragment(project.getProject(), pfr.getPath().removeFirstSegments(1));
	assertNotNull(pf);
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:15,代碼來源:ResourceManagerTest.java

示例5: testGetSelectedPathInProject

import org.eclipse.jdt.core.IJavaProject; //導入方法依賴的package包/類
@Test
public void testGetSelectedPathInProject() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true, false);
	ResourceManager.createFile(project.getProject().getName(), "src/test/resources", "mypkg/subpkg", "test.java",
			"");

	IPackageFragment frag = (IPackageFragment) project.findElement(new Path("mypkg/subpkg"));
	IPackageFragmentRoot pfr = ResourceManager.getPackageFragmentRoot(project.getProject(), frag);
	String s = ResourceManager.getSelectedPathInProject(pfr);
	assertEquals("src/test/resources", s);
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:12,代碼來源:ResourceManagerTest.java

示例6: testIsPackageFragmentRoot

import org.eclipse.jdt.core.IJavaProject; //導入方法依賴的package包/類
@Test
public void testIsPackageFragmentRoot() throws Exception {
	IJavaProject project = ProjectHelper.getOrCreateSimpleGW4EProject(PROJECT_NAME, true, false);
	ResourceManager.createFile(project.getProject().getName(), "src/test/resources", "mypkg/subpkg", "test.java",
			"");

	IPackageFragment frag = (IPackageFragment) project.findElement(new Path("mypkg/subpkg"));
	IPackageFragmentRoot pfr = ResourceManager.getPackageFragmentRoot(project.getProject(), frag);

	boolean b = ResourceManager.isPackageFragmentRoot(pfr);
	assertTrue(b);

	b = ResourceManager.isPackageFragmentRoot(project);
	assertFalse(b);
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:16,代碼來源:ResourceManagerTest.java


注:本文中的org.eclipse.jdt.core.IJavaProject.findElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。