當前位置: 首頁>>代碼示例>>Java>>正文


Java IPackageFragmentRoot.createPackageFragment方法代碼示例

本文整理匯總了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());
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:25,代碼來源:DocumentLifeCycleHandlerTest.java

示例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());
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:29,代碼來源:DocumentLifeCycleHandlerTest.java

示例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());
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:42,代碼來源:DocumentLifeCycleHandlerTest.java

示例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();
}
 
開發者ID:capitalone,項目名稱:Hydrograph,代碼行數:45,代碼來源:SourceViewer.java

示例5: createPackage

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
public IPackageFragment createPackage(IPackageFragmentRoot fragmentRoot,
    String name) throws CoreException {
  return fragmentRoot.createPackageFragment(name, false, null);
}
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:5,代碼來源:JavaProjectKit.java

示例6: createPackage

import org.eclipse.jdt.core.IPackageFragmentRoot; //導入方法依賴的package包/類
public IPackageFragment createPackage(IPackageFragmentRoot fragmentRoot, String name) throws CoreException {
	return fragmentRoot.createPackageFragment(name, false, null);
}
 
開發者ID:eclipse,項目名稱:eclemma,代碼行數:4,代碼來源:JavaProjectKit.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:57,代碼來源:DocumentLifeCycleHandlerTest.java

示例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);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:58,代碼來源:DocumentLifeCycleHandlerTest.java


注:本文中的org.eclipse.jdt.core.IPackageFragmentRoot.createPackageFragment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。