本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}