本文整理汇总了Java中org.eclipse.jdt.core.IPackageFragmentRoot.createPackageFragment方法的典型用法代码示例。如果您正苦于以下问题:Java IPackageFragmentRoot.createPackageFragment方法的具体用法?Java IPackageFragmentRoot.createPackageFragment怎么用?Java IPackageFragmentRoot.createPackageFragment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IPackageFragmentRoot
的用法示例。
在下文中一共展示了IPackageFragmentRoot.createPackageFragment方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDidOpenStandaloneFile
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
@Test
public void testDidOpenStandaloneFile() throws Exception {
IJavaProject javaProject = newDefaultProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null);
// @formatter:off
String standaloneFileContent =
"package java;\n"+
"public class Foo extends UnknownType {"+
" public void method1(){\n"+
" super.whatever();"+
" }\n"+
"}";
// @formatter:on
ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null);
openDocument(cu1, cu1.getSource(), 1);
List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(1, diagnosticReports.size());
PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
assertEquals(0, diagParam.getDiagnostics().size());
}
示例2: testDidOpenStandaloneFileWithSyntaxError
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
@Test
public void testDidOpenStandaloneFileWithSyntaxError() throws Exception {
IJavaProject javaProject = newDefaultProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null);
// @formatter:off
String standaloneFileContent =
"package java;\n"+
"public class Foo extends UnknownType {\n"+
" public void method1(){\n"+
" super.whatever()\n"+
" }\n"+
"}";
// @formatter:on
ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null);
openDocument(cu1, cu1.getSource(), 1);
List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(1, diagnosticReports.size());
PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
assertEquals("Unexpected number of errors " + diagParam.getDiagnostics(), 1, diagParam.getDiagnostics().size());
Diagnostic d = diagParam.getDiagnostics().get(0);
assertEquals("Syntax error, insert \";\" to complete BlockStatements", d.getMessage());
assertRange(3, 17, 18, d.getRange());
}
示例3: testDidOpenStandaloneFileWithNonSyntaxErrors
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
@Test
public void testDidOpenStandaloneFileWithNonSyntaxErrors() throws Exception {
IJavaProject javaProject = newDefaultProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("java", false, null);
// @formatter:off
String standaloneFileContent =
"package java;\n"+
"public class Foo {\n"+
" public static void notThis(){\n"+
" System.out.println(this);\n"+
" }\n"+
" public void method1(){\n"+
" }\n"+
" public void method1(){\n"+
" }\n"+
"}";
// @formatter:on
ICompilationUnit cu1 = pack1.createCompilationUnit("Foo.java", standaloneFileContent, false, null);
openDocument(cu1, cu1.getSource(), 1);
List<PublishDiagnosticsParams> diagnosticReports = getClientRequests("publishDiagnostics");
assertEquals(1, diagnosticReports.size());
PublishDiagnosticsParams diagParam = diagnosticReports.get(0);
assertEquals("Unexpected number of errors " + diagParam.getDiagnostics(), 3, diagParam.getDiagnostics().size());
Diagnostic d = diagParam.getDiagnostics().get(0);
assertEquals("Cannot use this in a static context", d.getMessage());
assertRange(3, 21, 25, d.getRange());
d = diagParam.getDiagnostics().get(1);
assertEquals("Duplicate method method1() in type Foo", d.getMessage());
assertRange(5, 13, 22, d.getRange());
d = diagParam.getDiagnostics().get(2);
assertEquals("Duplicate method method1() in type Foo", d.getMessage());
assertRange(7, 13, 22, d.getRange());
}
示例4: SourceViewer
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
public SourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler,
boolean showAnnotationsOverview, int styles, IAnnotationAccess annotationAccess, ISharedTextColors sharedColors,
IDocument document)
{
super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, SWT.BOLD);
int id = currentId++;
filename = VIEWER_CLASS_NAME + id++ + ".java";
this.sharedColors=sharedColors;
this.annotationAccess=annotationAccess;
this.fOverviewRuler=overviewRuler;
oldAnnotations= new HashMap<ProjectionAnnotation, Position>();
IJavaProject javaProject = JavaCore.create(BuildExpressionEditorDataSturcture.INSTANCE.getCurrentProject());
try
{
IPackageFragmentRoot[] ipackageFragmentRootList=javaProject.getPackageFragmentRoots();
IPackageFragmentRoot ipackageFragmentRoot=null;
for(IPackageFragmentRoot tempIpackageFragmentRoot:ipackageFragmentRootList)
{
if(tempIpackageFragmentRoot.getKind()==IPackageFragmentRoot.K_SOURCE
&& StringUtils.equals(PathConstant.TEMP_BUILD_PATH_SETTINGS_FOLDER,tempIpackageFragmentRoot.getPath().removeFirstSegments(1).toString()))
{
ipackageFragmentRoot=tempIpackageFragmentRoot;
break;
}
}
IPackageFragment compilationUnitPackage= ipackageFragmentRoot.createPackageFragment(HYDROGRAPH_COMPILATIONUNIT_PACKAGE, true, new NullProgressMonitor());
compilatioUnit= compilationUnitPackage.createCompilationUnit(filename,document.get(),true, new NullProgressMonitor());
}
catch (Exception exception) {
LOGGER.warn("Exception occurred while initializing source viewer", exception);
} finally {
if (javaProject != null) {
try {
javaProject.close();
} catch (JavaModelException javaModelException) {
LOGGER.warn("Exception occurred while closing java-project", javaModelException);
}
}
}
initializeViewer(document);
updateContents();
}
示例5: createPackage
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
public IPackageFragment createPackage(IPackageFragmentRoot fragmentRoot,
String name) throws CoreException {
return fragmentRoot.createPackageFragment(name, false, null);
}
示例6: createPackage
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
public IPackageFragment createPackage(IPackageFragmentRoot fragmentRoot, String name) throws CoreException {
return fragmentRoot.createPackageFragment(name, false, null);
}
示例7: testBasicBufferLifeCycle
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
@Test
public void testBasicBufferLifeCycle() throws Exception {
IJavaProject javaProject = newEmptyProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E123 {\n");
buf.append("}\n");
ICompilationUnit cu1 = pack1.createCompilationUnit("E123.java", buf.toString(), false, null);
assertEquals(false, cu1.isWorkingCopy());
assertEquals(false, cu1.hasUnsavedChanges());
assertNewProblemReported();
assertEquals(0, sharedASTProvider.getCacheSize());
assertNewASTsCreated(0);
openDocument(cu1, cu1.getSource(), 1);
assertEquals(true, cu1.isWorkingCopy());
assertEquals(false, cu1.hasUnsavedChanges());
assertNewProblemReported(new ExpectedProblemReport(cu1, 0));
assertEquals(1, sharedASTProvider.getCacheSize());
assertNewASTsCreated(1);
buf = new StringBuilder();
buf.append("package test1;\n");
buf.append("public class E123 {\n");
buf.append(" X x;\n");
buf.append("}\n");
changeDocumentFull(cu1, buf.toString(), 2);
assertEquals(true, cu1.isWorkingCopy());
assertEquals(true, cu1.hasUnsavedChanges());
assertNewProblemReported(new ExpectedProblemReport(cu1, 1));
assertEquals(1, sharedASTProvider.getCacheSize());
assertNewASTsCreated(1);
saveDocument(cu1);
assertEquals(true, cu1.isWorkingCopy());
assertEquals(false, cu1.hasUnsavedChanges());
assertNewProblemReported();
assertEquals(1, sharedASTProvider.getCacheSize());
assertNewASTsCreated(0);
closeDocument(cu1);
assertEquals(false, cu1.isWorkingCopy());
assertEquals(false, cu1.hasUnsavedChanges());
assertNewProblemReported();
assertEquals(0, sharedASTProvider.getCacheSize());
assertNewASTsCreated(0);
}
示例8: testIncrementalChangeDocument
import org.eclipse.jdt.core.IPackageFragmentRoot; //导入方法依赖的package包/类
@Test
public void testIncrementalChangeDocument() throws Exception {
IJavaProject javaProject = newEmptyProject();
IPackageFragmentRoot sourceFolder = javaProject.getPackageFragmentRoot(javaProject.getProject().getFolder("src"));
IPackageFragment pack1 = sourceFolder.createPackageFragment("test1", false, null);
StringBuilder buf = new StringBuilder();
String BEGIN_PART = "package test1;\n";
String TO_BE_CHANGED_PART = "public class E123 {\n";
String END_PART = "}\n";
buf.append(BEGIN_PART);
buf.append(TO_BE_CHANGED_PART);
buf.append(END_PART);
ICompilationUnit cu1 = pack1.createCompilationUnit("E123.java", buf.toString(), false, null);
assertEquals(false, cu1.isWorkingCopy());
assertEquals(false, cu1.hasUnsavedChanges());
assertNewProblemReported();
assertEquals(0, sharedASTProvider.getCacheSize());
assertNewASTsCreated(0);
openDocument(cu1, cu1.getSource(), 1);
assertEquals(true, cu1.isWorkingCopy());
assertEquals(false, cu1.hasUnsavedChanges());
assertNewProblemReported(new ExpectedProblemReport(cu1, 0));
assertEquals(1, sharedASTProvider.getCacheSize());
assertNewASTsCreated(1);
buf = new StringBuilder();
buf.append(TO_BE_CHANGED_PART);
buf.append(" X x;\n");
changeDocumentIncrementally(cu1, buf.toString(), 2, BEGIN_PART.length(), TO_BE_CHANGED_PART.length());
assertEquals(true, cu1.isWorkingCopy());
assertEquals(true, cu1.hasUnsavedChanges());
assertNewProblemReported(new ExpectedProblemReport(cu1, 1));
assertEquals(1, sharedASTProvider.getCacheSize());
assertNewASTsCreated(1);
saveDocument(cu1);
assertEquals(true, cu1.isWorkingCopy());
assertEquals(false, cu1.hasUnsavedChanges());
assertNewProblemReported();
assertEquals(1, sharedASTProvider.getCacheSize());
assertNewASTsCreated(0);
closeDocument(cu1);
assertEquals(false, cu1.isWorkingCopy());
assertEquals(false, cu1.hasUnsavedChanges());
assertNewProblemReported();
assertEquals(0, sharedASTProvider.getCacheSize());
assertNewASTsCreated(0);
}