當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。