List of usage examples for org.eclipse.jdt.core IJavaProject getElementName
String getElementName();
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that making Javadoc changes to the source file TestClass2 cause the * workspace baseline to be updated.//from w ww . java 2 s .c o m * * This test adds a @noinstantiate tag to the source file TestClass2 */ public void testWPUpdateSourceTypeChanged() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IPackageFragmentRoot root = project.findPackageFragmentRoot( new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute()); assertNotNull("the 'src' package fragment root must exist", root); //$NON-NLS-1$ NullProgressMonitor monitor = new NullProgressMonitor(); IPackageFragment fragment = root.getPackageFragment("a.b.c"); //$NON-NLS-1$ FileUtils.importFileFromDirectory(SRC_LOC.append("TestClass2.java").toFile(), fragment.getPath(), monitor); //$NON-NLS-1$ ICompilationUnit element = (ICompilationUnit) project.findElement(new Path("a/b/c/TestClass2.java")); //$NON-NLS-1$ assertNotNull("TestClass2 must exist in the test project", element); //$NON-NLS-1$ updateTagInSource(element, "TestClass2", null, "@noinstantiate", false); //$NON-NLS-1$ //$NON-NLS-2$ IApiDescription desc = getTestProjectApiDescription(); assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$ IApiAnnotations annot = desc.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass2")); //$NON-NLS-1$ assertNotNull("the annotations for a.b.c.TestClass2 cannot be null", annot); //$NON-NLS-1$ assertTrue("there must be a noinstantiate setting for TestClass2", //$NON-NLS-1$ (annot.getRestrictions() & RestrictionModifiers.NO_INSTANTIATE) != 0); assertTrue("there must be a noextend setting for TestClass2", //$NON-NLS-1$ (annot.getRestrictions() & RestrictionModifiers.NO_EXTEND) != 0); }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that tags updated on an inner type are updated in the workspace * description.//from ww w . j a va2s. co m * * This test adds a @noinstantiate tag to an inner class in TestClass3 */ public void testWPUpdateSourceInnerTypeChanged() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IPackageFragmentRoot root = project.findPackageFragmentRoot( new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute()); assertNotNull("the 'src' package fragment root must exist", root); //$NON-NLS-1$ assertTestSource(root, TESTING_PACKAGE, "TestClass3"); //$NON-NLS-1$ ICompilationUnit element = (ICompilationUnit) project.findElement(new Path("a/b/c/TestClass3.java")); //$NON-NLS-1$ assertNotNull("TestClass3 must exist in the test project", element); //$NON-NLS-1$ updateTagInSource(element, "InnerTestClass3", null, "@noinstantiate", false); //$NON-NLS-1$ //$NON-NLS-2$ IApiDescription desc = getTestProjectApiDescription(); assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$ IApiAnnotations annot = desc.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass3$InnerTestClass3")); //$NON-NLS-1$ assertNotNull("the annotations for a.b.c.TestClass3$InnerTestClass3 cannot be null", annot); //$NON-NLS-1$ assertFalse("there must not be a noinstantiate setting for TestClass3$InnerTestClass3", //$NON-NLS-1$ (annot.getRestrictions() & RestrictionModifiers.NO_INSTANTIATE) != 0); assertFalse("there must not be a noextend setting for TestClass3$InnerTestClass3", //$NON-NLS-1$ (annot.getRestrictions() & RestrictionModifiers.NO_EXTEND) != 0); }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that changing the javadoc for a method updates the workspace * baseline// ww w.j a v a 2 s . c o m * * This test adds a @noextend tag to the method foo() in TestClass1 */ public void testWPUpdateSourceMethodChanged() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IPackageFragmentRoot root = project.findPackageFragmentRoot( new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute()); assertNotNull("the 'src' package fragment root must exist", root); //$NON-NLS-1$ assertTestSource(root, TESTING_PACKAGE, "TestClass1"); //$NON-NLS-1$ ICompilationUnit element = (ICompilationUnit) project.findElement(new Path("a/b/c/TestClass1.java")); //$NON-NLS-1$ assertNotNull("TestClass1 must exist in the test project", element); //$NON-NLS-1$ updateTagInSource(element, "foo", "()V", "@nooverride", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ IApiDescription desc = getTestProjectApiDescription(); assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$ IApiAnnotations annot = desc.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestClass1", "foo", "()V")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertNotNull("the annotations for foo() cannot be null", annot); //$NON-NLS-1$ assertTrue("there must be a nooverride setting for foo()", //$NON-NLS-1$ (annot.getRestrictions() & RestrictionModifiers.NO_OVERRIDE) != 0); }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that changing the javadoc for a field updates the workspace * baseline//w w w . j a v a2s . c o m * * This test adds a @noextend tag to the field 'field' in TestField9 */ public void testWPUpdateSourceFieldChanged() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IPackageFragmentRoot root = project.findPackageFragmentRoot( new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute()); assertNotNull("the 'src' package fragment root must exist", root); //$NON-NLS-1$ assertTestSource(root, TESTING_PACKAGE, "TestField9"); //$NON-NLS-1$ ICompilationUnit element = (ICompilationUnit) project.findElement(new Path("a/b/c/TestField9.java")); //$NON-NLS-1$ assertNotNull("TestField9 must exist in the test project", element); //$NON-NLS-1$ updateTagInSource(element, "field", null, "@noreference", false); //$NON-NLS-1$ //$NON-NLS-2$ IApiDescription desc = getTestProjectApiDescription(); assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$ IApiAnnotations annot = desc.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField9", "field")); //$NON-NLS-1$ //$NON-NLS-2$ assertNotNull("the annotations for 'field' cannot be null", annot); //$NON-NLS-1$ assertTrue("there must be a noreference setting for 'field'", //$NON-NLS-1$ (annot.getRestrictions() & RestrictionModifiers.NO_REFERENCE) != 0); }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that removing a tag from a method updates the workspace baseline * /*ww w . j a v a 2s .c om*/ * This test removes a @noextend tag to the method foo() in TestClass1 */ public void testWPUpdateSourceMethodRemoveTag() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IPackageFragmentRoot root = project.findPackageFragmentRoot( new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute()); assertNotNull("the 'src' package fragment root must exist", root); //$NON-NLS-1$ assertTestSource(root, TESTING_PACKAGE, "TestClass1"); //$NON-NLS-1$ ICompilationUnit element = (ICompilationUnit) project.findElement(new Path("a/b/c/TestClass1.java")); //$NON-NLS-1$ assertNotNull("TestClass1 must exist in the test project", element); //$NON-NLS-1$ updateTagInSource(element, "foo", "()V", "@nooverride", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ IApiDescription desc = getTestProjectApiDescription(); assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$ IApiAnnotations annot = desc.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestClass1", "foo", "()V")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertNotNull("the annotations for foo() cannot be null", annot); //$NON-NLS-1$ assertTrue("there must be no restrictions for foo()", annot.getRestrictions() == 0); //$NON-NLS-1$ }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that removing a tag from a type updates the workspace baseline * /*from w ww .ja va 2s. c om*/ * This test removes a @noinstantiate tag to an inner class in TestClass3 */ public void testWPUpdateSourceTypeRemoveTag() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IPackageFragmentRoot root = project.findPackageFragmentRoot( new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute()); assertNotNull("the 'src' package fragment root must exist", root); //$NON-NLS-1$ assertTestSource(root, TESTING_PACKAGE, "TestClass3"); //$NON-NLS-1$ ICompilationUnit element = (ICompilationUnit) project.findElement(new Path("a/b/c/TestClass3.java")); //$NON-NLS-1$ assertNotNull("TestClass3 must exist in the test project", element); //$NON-NLS-1$ updateTagInSource(element, "InnerTestClass3", null, "@noextend", true); //$NON-NLS-1$ //$NON-NLS-2$ IApiDescription desc = getTestProjectApiDescription(); assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$ IApiAnnotations annot = desc.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass3$InnerTestClass3")); //$NON-NLS-1$ assertNotNull("the annotations for 'InnerTestClass3' cannot be null", annot); //$NON-NLS-1$ assertTrue("there must be a no restrictions for 'InnerTestClass3'", //$NON-NLS-1$ (annot.getRestrictions() & RestrictionModifiers.NO_INSTANTIATE) == 0); }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that removing a tag from a field updates the workspace baseline * //from w w w .ja v a 2 s . c om * This test adds a @noextend tag to the field 'field' in TestField9 */ public void testWPUpdateSourceFieldRemoveTag() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IPackageFragmentRoot root = project.findPackageFragmentRoot( new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute()); assertNotNull("the 'src' package fragment root must exist", root); //$NON-NLS-1$ assertTestSource(root, TESTING_PACKAGE, "TestField9"); //$NON-NLS-1$ ICompilationUnit element = (ICompilationUnit) project.findElement(new Path("a/b/c/TestField9.java")); //$NON-NLS-1$ assertNotNull("TestField9 must exist in the test project", element); //$NON-NLS-1$ updateTagInSource(element, "field1", null, "@noreference", true); //$NON-NLS-1$ //$NON-NLS-2$ IApiDescription desc = getTestProjectApiDescription(); assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$ IApiAnnotations annot = desc.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField9", "field")); //$NON-NLS-1$ //$NON-NLS-2$ assertNotNull("the annotations for 'field' cannot be null", annot); //$NON-NLS-1$ assertTrue("there must be a no restrictions for 'field'", annot.getRestrictions() == 0); //$NON-NLS-1$ }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that a library added to the build and bundle class path of a * project causes the class file containers for the project to need to be * recomputed// ww w. j a v a 2 s . c o m * * @throws IOException * @throws InvocationTargetException * @throws CoreException */ public void testWPUpdateLibraryAddedToClasspath() throws Exception { IFolder folder = null; try { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IApiComponent component = getWorkspaceBaseline().getApiComponent(project.getElementName()); assertNotNull("the workspace component must exist", component); //$NON-NLS-1$ int before = component.getApiTypeContainers().length; // add to classpath folder = assertTestLibrary(project, new Path("libx"), "component.a_1.0.0.jar"); //$NON-NLS-1$ //$NON-NLS-2$ assertNotNull("The new library path should not be null", folder); //$NON-NLS-1$ // re-retrieve updated component component = getWorkspaceBaseline().getApiComponent(project.getElementName()); assertTrue("there must be more containers after the addition", //$NON-NLS-1$ before < component.getApiTypeContainers().length); } finally { if (folder != null) { FileUtils.delete(folder); } } }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests removing a library from the classpath of a project *//*from w w w. j ava 2 s.com*/ public void testWPUpdateLibraryRemovedFromClasspath() throws Exception { IPath libPath = null; try { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ // add to classpath IFolder folder = assertTestLibrary(project, new Path("libx"), "component.a_1.0.0.jar"); //$NON-NLS-1$ //$NON-NLS-2$ IApiComponent component = getWorkspaceBaseline().getApiComponent(project.getElementName()); assertNotNull("the workspace component must exist", component); //$NON-NLS-1$ int before = component.getApiTypeContainers().length; libPath = folder.getFullPath().append("component.a_1.0.0.jar"); //$NON-NLS-1$ // remove classpath entry ProjectUtils.removeFromClasspath(project, JavaCore.newLibraryEntry(libPath, null, null)); waitForAutoBuild(); // remove from bundle class path IBundleProjectService service = ProjectUtils.getBundleProjectService(); IBundleProjectDescription description = service.getDescription(project.getProject()); description.setBundleClasspath(new IBundleClasspathEntry[] { service.newBundleClasspathEntry(new Path(ProjectUtils.SRC_FOLDER), null, null) }); description.apply(null); waitForAutoBuild(); // retrieve updated component component = getWorkspaceBaseline().getApiComponent(project.getElementName()); assertTrue("there must be less containers after the removal", //$NON-NLS-1$ before > component.getApiTypeContainers().length); } finally { if (libPath != null) { FileUtils.delete(libPath.toOSString()); } } }
From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java
License:Open Source License
/** * Tests that changing the output folder settings for a project cause the * class file containers to be updated//ww w .j av a2s . c o m */ public void testWPUpdateDefaultOutputFolderChanged() throws Exception { IJavaProject project = getTestingProject(); assertNotNull("The testing project must exist", project); //$NON-NLS-1$ IContainer container = ProjectUtils.addFolderToProject(project.getProject(), "bin2"); //$NON-NLS-1$ assertNotNull("the new output folder cannot be null", container); //$NON-NLS-1$ IApiComponent component = getWorkspaceBaseline().getApiComponent(project.getElementName()); assertNotNull("the workspace component must exist", component); //$NON-NLS-1$ int before = component.getApiTypeContainers().length; project.setOutputLocation(container.getFullPath(), new NullProgressMonitor()); waitForAutoBuild(); assertTrue("there must be the same number of containers after the change", //$NON-NLS-1$ before == component.getApiTypeContainers().length); assertTrue("the new output location should be 'bin2'", //$NON-NLS-1$ "bin2".equalsIgnoreCase(project.getOutputLocation().toFile().getName())); //$NON-NLS-1$ }