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


Java ICompilationUnit.getCorrespondingResource方法代码示例

本文整理汇总了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;
}
 
开发者ID:Microsoft,项目名称:java-debug,代码行数:37,代码来源:JavaHotCodeReplaceProvider.java

示例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;
}
 
开发者ID:liaoziyang,项目名称:ContentAssist,代码行数:18,代码来源:ResourceMacro.java

示例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());
			}
		}
	}
}
 
开发者ID:aroog,项目名称:code,代码行数:47,代码来源:TraceToCodeUIAction.java


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