/**
  * Tests that making Javadoc changes to the source file TestClass2 cause the workspace baseline to
  * be updated.
  *
  * <p>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);
   IPackageFragmentRoot root =
       project.findPackageFragmentRoot(
           new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute());
   assertNotNull("the 'src' package fragment root must exist", root);
   NullProgressMonitor monitor = new NullProgressMonitor();
   IPackageFragment fragment = root.getPackageFragment("a.b.c");
   FileUtils.importFileFromDirectory(
       SRC_LOC.append("TestClass2.java").toFile(), fragment.getPath(), monitor);
   ICompilationUnit element =
       (ICompilationUnit) project.findElement(new Path("a/b/c/TestClass2.java"));
   assertNotNull("TestClass2 must exist in the test project", element);
   updateTagInSource(element, "TestClass2", null, "@noinstantiate", false);
   IApiDescription desc = getTestProjectApiDescription();
   assertNotNull("the testing project api description must exist", desc);
   IApiAnnotations annot = desc.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass2"));
   assertNotNull("the annotations for a.b.c.TestClass2 cannot be null", annot);
   assertTrue(
       "there must be a noinstantiate setting for TestClass2",
       (annot.getRestrictions() & RestrictionModifiers.NO_INSTANTIATE) != 0);
   assertTrue(
       "there must be a noextend setting for TestClass2",
       (annot.getRestrictions() & RestrictionModifiers.NO_EXTEND) != 0);
 }
 /**
  * Returns whether the given type has API visibility.
  *
  * @param type type
  * @return whether the given type has API visibility
  */
 private boolean isAPIType(IApiType type) throws CoreException {
   IApiDescription description = type.getApiComponent().getApiDescription();
   IApiAnnotations annotations = description.resolveAnnotations(type.getHandle());
   if (annotations == null) {
     // top level non-public top can have no annotations - they are not
     // API
     return false;
   }
   return VisibilityModifiers.isAPI(annotations.getVisibility());
 }
 /**
  * Asserts if the given restriction is on the specified source
  *
  * @param packagename
  * @param sourcename
  */
 public void assertSourceResctriction(String packagename, String sourcename, int restriction)
     throws CoreException {
   IApiDescription desc = getTestProjectApiDescription();
   assertNotNull("the testing project api description must exist", desc);
   IApiAnnotations annot =
       desc.resolveAnnotations(Factory.typeDescriptor(packagename + "." + sourcename));
   assertNotNull(
       "the annotations for " + packagename + "." + sourcename + " cannot be null", annot);
   assertTrue(
       "there must be a noinstantiate setting for TestClass1",
       annot.getRestrictions() == restriction);
 }
  /** Tests that adding a package does not update the workspace baseline */
  public void testWPUpdatePackageAdded() throws Exception {
    IJavaProject project = getTestingProject();
    assertNotNull("The testing project must exist", project);

    // add the package
    assertTestPackage(
        project,
        new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute(),
        "a.test1.c.d");

    IApiDescription desc = getTestProjectApiDescription();
    assertNotNull("the testing project api description must exist", desc);
    IApiAnnotations annot = desc.resolveAnnotations(Factory.packageDescriptor("a.test1.c.d"));
    assertNotNull("the annotations for package " + TESTING_PACKAGE + " should exist", annot);
  }
 /**
  * Tests that removing a source file from an API aware project causes the workspace description to
  * be updated
  */
 public void testWPUpdateSourceRemoved() throws Exception {
   IJavaProject project = getTestingProject();
   assertNotNull("The testing project must exist", project);
   IPackageFragmentRoot root =
       project.findPackageFragmentRoot(
           new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute());
   assertNotNull("the 'src' package fragment root must exist", root);
   assertTestSource(root, TESTING_PACKAGE, "TestClass1");
   IJavaElement element = project.findElement(new Path("a/b/c/TestClass1.java"));
   assertNotNull("the class a.b.c.TestClass1 must exist in the project", element);
   element.getResource().delete(true, new NullProgressMonitor());
   IApiDescription desc = getTestProjectApiDescription();
   assertNotNull("the testing project api description must exist", desc);
   IApiAnnotations annot = desc.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass1"));
   assertNull("the annotations for a.b.c.TestClass1 should no longer be present", annot);
 }
  /**
   * Tests that removing a package updates the workspace baseline This test removes the a.b.c
   * package being used in all tests thus far, and should be run last
   */
  public void testWPUpdatePackageRemoved() throws Exception {
    IJavaProject project = getTestingProject();
    assertNotNull("The testing project must exist", project);

    // add the package
    IPath srcroot =
        new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute();
    IPackageFragment fragment = assertTestPackage(project, srcroot, "a.test2");
    assertNotNull("the package " + TESTING_PACKAGE + " must exist", fragment);

    // remove the package
    fragment.delete(true, new NullProgressMonitor());

    IApiDescription desc = getTestProjectApiDescription();
    assertNotNull("the testing project api description must exist", desc);
    IApiAnnotations annot = desc.resolveAnnotations(Factory.packageDescriptor("a.test2"));
    assertNull("the annotations for package " + TESTING_PACKAGE + " should not exist", annot);
  }
 /**
  * Tests that removing a tag from a field updates the workspace baseline
  *
  * <p>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);
   IPackageFragmentRoot root =
       project.findPackageFragmentRoot(
           new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute());
   assertNotNull("the 'src' package fragment root must exist", root);
   assertTestSource(root, TESTING_PACKAGE, "TestField9");
   ICompilationUnit element =
       (ICompilationUnit) project.findElement(new Path("a/b/c/TestField9.java"));
   assertNotNull("TestField9 must exist in the test project", element);
   updateTagInSource(element, "field1", null, "@noreference", true);
   IApiDescription desc = getTestProjectApiDescription();
   assertNotNull("the testing project api description must exist", desc);
   IApiAnnotations annot =
       desc.resolveAnnotations(Factory.fieldDescriptor("a.b.c.TestField9", "field"));
   assertNotNull("the annotations for 'field' cannot be null", annot);
   assertTrue("there must be a no restrictions for 'field'", annot.getRestrictions() == 0);
 }
 /**
  * Tests that removing a tag from a type updates the workspace baseline
  *
  * <p>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);
   IPackageFragmentRoot root =
       project.findPackageFragmentRoot(
           new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute());
   assertNotNull("the 'src' package fragment root must exist", root);
   assertTestSource(root, TESTING_PACKAGE, "TestClass3");
   ICompilationUnit element =
       (ICompilationUnit) project.findElement(new Path("a/b/c/TestClass3.java"));
   assertNotNull("TestClass3 must exist in the test project", element);
   updateTagInSource(element, "InnerTestClass3", null, "@noextend", true);
   IApiDescription desc = getTestProjectApiDescription();
   assertNotNull("the testing project api description must exist", desc);
   IApiAnnotations annot =
       desc.resolveAnnotations(Factory.typeDescriptor("a.b.c.TestClass3$InnerTestClass3"));
   assertNotNull("the annotations for 'InnerTestClass3' cannot be null", annot);
   assertTrue(
       "there must be a no restrictions for 'InnerTestClass3'",
       (annot.getRestrictions() & RestrictionModifiers.NO_INSTANTIATE) == 0);
 }
 /**
  * Tests that changing the javadoc for a method updates the workspace baseline
  *
  * <p>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);
   IPackageFragmentRoot root =
       project.findPackageFragmentRoot(
           new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute());
   assertNotNull("the 'src' package fragment root must exist", root);
   assertTestSource(root, TESTING_PACKAGE, "TestClass1");
   ICompilationUnit element =
       (ICompilationUnit) project.findElement(new Path("a/b/c/TestClass1.java"));
   assertNotNull("TestClass1 must exist in the test project", element);
   updateTagInSource(element, "foo", "()V", "@nooverride", false);
   IApiDescription desc = getTestProjectApiDescription();
   assertNotNull("the testing project api description must exist", desc);
   IApiAnnotations annot =
       desc.resolveAnnotations(Factory.methodDescriptor("a.b.c.TestClass1", "foo", "()V"));
   assertNotNull("the annotations for foo() cannot be null", annot);
   assertTrue(
       "there must be a nooverride setting for foo()",
       (annot.getRestrictions() & RestrictionModifiers.NO_OVERRIDE) != 0);
 }
Пример #10
0
 /**
  * Processes the tags for the given {@link IElementDescriptor}
  *
  * @param descriptor the descriptor
  * @param tags the listing of tags from the AST
  * @param type one of <code>CLASS</code> or <code>INTERFACE</code>
  * @param member one of <code>METHOD</code> or <code>FIELD</code> or <code>NONE</code>
  */
 protected void processTags(IElementDescriptor descriptor, List tags, int type, int member) {
   JavadocTagManager jtm = ApiPlugin.getJavadocTagManager();
   TagElement tag = null;
   String tagname = null;
   int restrictions = RestrictionModifiers.NO_RESTRICTIONS;
   for (Iterator iter = tags.iterator(); iter.hasNext(); ) {
     tag = (TagElement) iter.next();
     tagname = tag.getTagName();
     restrictions |= jtm.getRestrictionsForTag(tagname, type, member);
   }
   if (restrictions != RestrictionModifiers.NO_RESTRICTIONS) {
     IElementDescriptor ldesc = descriptor;
     if (ldesc.getElementType() == IElementDescriptor.METHOD) {
       try {
         ldesc = resolveMethod((IMethodDescriptor) ldesc);
       } catch (CoreException e) {
         fException = e;
       }
     }
     fDescription.setRestrictions(ldesc, restrictions);
   }
 }