本文整理汇总了Java中org.eclipse.jdt.core.ICompilationUnit.getCorrespondingResource方法的典型用法代码示例。如果您正苦于以下问题:Java ICompilationUnit.getCorrespondingResource方法的具体用法?Java ICompilationUnit.getCorrespondingResource怎么用?Java ICompilationUnit.getCorrespondingResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ICompilationUnit
的用法示例。
在下文中一共展示了ICompilationUnit.getCorrespondingResource方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSourceFile
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的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: getEncoding
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
* Returns the encoding of the changed source code.
* @param elem the changed resource
* @return the encoding of the source code, or <code>null</code>
*/
private String getEncoding(IJavaElement elem) {
if (elem instanceof ICompilationUnit) {
ICompilationUnit cu = (ICompilationUnit)elem;
try {
IFile file = (IFile)cu.getCorrespondingResource();
return file.getCharset();
} catch (CoreException e) {
}
}
return null;
}
示例3: run
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
/**
* required by the IWorkbenchWindowActionDelegate interface
*
*/
public void run(IAction action) {
Crystal crystal = Crystal.getInstance();
PrintWriter output = crystal.userOut();
if(baseTraceabilityObject!=null){
Iterator<ICompilationUnit> unitIterator = crystal.getCompilationUnitIterator();
ICompilationUnit compUnit = null;
for (; unitIterator.hasNext();) {
compUnit = unitIterator.next();
if (compUnit == null) {
output.println("AbstractCompilationUnitAnalysis: null CompilationUnit");
continue;
}
// Retrieve the path of this compilation unit, and output it
if (DEBUG_OUTPUT_PATHS) {
try {
IResource resource = compUnit.getCorrespondingResource();
if (resource != null) {
IPath path = resource.getLocation();
if (path != null) {
output.println(path.toPortableString());
}
}
}
catch (JavaModelException e) {
output.println("AbstractCompilationUnitAnalysis: Unable to retrieve path of CompilationUnit"
+ compUnit.getElementName());
}
}
// Obtain the AST for this CompilationUnit and analyze it
ASTNode node = crystal.getASTNodeFromCompilationUnit(compUnit);
if ((node != null) && (node instanceof CompilationUnit)) {
analyzeCompilationUnit((CompilationUnit) node, compUnit);
}
else {
output.println("AbstractCompilationUnitAnalysis: Could not retrieve the ASTNode for CompilationUnit "
+ compUnit.getElementName());
}
}
}
}