本文整理汇总了Java中org.eclipse.jdt.core.ICompilationUnit.getResource方法的典型用法代码示例。如果您正苦于以下问题:Java ICompilationUnit.getResource方法的具体用法?Java ICompilationUnit.getResource怎么用?Java ICompilationUnit.getResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.ICompilationUnit
的用法示例。
在下文中一共展示了ICompilationUnit.getResource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDummyClass
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static IFile createDummyClass(IJavaProject project) throws CoreException, IOException {
String clazz = "import org.graphwalker.core.machine.ExecutionContext ; public class Dummy extends org.gw4e.core.machine.ExecutionContext {}";
IFolder folder = project.getProject().getFolder("src/test/java");
IPackageFragmentRoot srcFolder = project.getPackageFragmentRoot(folder);
IPackageFragment pkg = srcFolder.getPackageFragment("");
ICompilationUnit cu = pkg.createCompilationUnit("Dummy.java", clazz, false, new NullProgressMonitor());
cu.save(new NullProgressMonitor (), true);
return (IFile) cu.getResource();
}
示例2: createDummyClassWitherror
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static IFile createDummyClassWitherror(IJavaProject project) throws CoreException, IOException {
String clazz = "import org.graphwalker.core.machine.ExecutionContext ; public class Dummy1 extends org.gw4e.core.machine.ExecutionContext {}";
IFolder folder = project.getProject().getFolder("src/test/java");
IPackageFragmentRoot srcFolder = project.getPackageFragmentRoot(folder);
IPackageFragment pkg = srcFolder.getPackageFragment("");
ICompilationUnit cu = pkg.createCompilationUnit("Dummy.java", clazz, false, new NullProgressMonitor());
cu.save(new NullProgressMonitor (), true);
return (IFile) cu.getResource();
}
示例3: createBuffer
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
@Override
public IBuffer createBuffer(ICompilationUnit workingCopy) {
ICompilationUnit original= workingCopy.getPrimary();
IResource resource= original.getResource();
if (resource instanceof IFile) {
return new DocumentAdapter(workingCopy, (IFile)resource);
}
return DocumentAdapter.Null;
}
示例4: getFile
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static IFile getFile(ICompilationUnit cu) {
IResource resource = cu.getResource();
if (resource != null && resource.getType() == IResource.FILE) {
return (IFile) resource;
} else {
return null;
}
}
示例5: isDefaultProject
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
public static boolean isDefaultProject(ICompilationUnit unit) {
return unit != null && unit.getResource() != null && unit.getResource().getProject().equals(JavaLanguageServerPlugin.getProjectsManager().getDefaultProject());
}
示例6: checkPackageDeclaration
import org.eclipse.jdt.core.ICompilationUnit; //导入方法依赖的package包/类
private ICompilationUnit checkPackageDeclaration(String uri, ICompilationUnit unit) {
if (unit.getResource() != null && unit.getJavaProject() != null && unit.getJavaProject().getProject().getName().equals(ProjectsManager.DEFAULT_PROJECT_NAME)) {
try {
CompilationUnit astRoot = SharedASTProvider.getInstance().getAST(unit, new NullProgressMonitor());
IProblem[] problems = astRoot.getProblems();
for (IProblem problem : problems) {
if (problem.getID() == IProblem.PackageIsNotExpectedPackage) {
IResource file = unit.getResource();
boolean toRemove = file.isLinked();
if (toRemove) {
IPath path = file.getParent().getProjectRelativePath();
if (path.segmentCount() > 0 && JDTUtils.SRC.equals(path.segments()[0])) {
String packageNameResource = path.removeFirstSegments(1).toString().replace(JDTUtils.PATH_SEPARATOR, JDTUtils.PERIOD);
path = file.getLocation();
if (path != null && path.segmentCount() > 0) {
path = path.removeLastSegments(1);
String pathStr = path.toString().replace(JDTUtils.PATH_SEPARATOR, JDTUtils.PERIOD);
if (pathStr.endsWith(packageNameResource)) {
toRemove = false;
}
}
}
}
if (toRemove) {
file.delete(true, new NullProgressMonitor());
sharedASTProvider.invalidate(unit);
unit.discardWorkingCopy();
unit = JDTUtils.resolveCompilationUnit(uri);
unit.becomeWorkingCopy(new NullProgressMonitor());
triggerValidation(unit);
}
break;
}
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
return unit;
}