/*
  * (non-Javadoc)
  * @see
  * org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom
  * .Javadoc)
  */
 @Override
 public boolean visit(Javadoc node) {
   Set<String> tagnames = ApiPlugin.getJavadocTagManager().getAllTagNames();
   List<TagElement> tags = node.tags();
   if (fExistingTags == null) {
     fExistingTags = new HashMap<String, Boolean>(tags.size());
   }
   String name = null;
   for (TagElement tag : tags) {
     name = tag.getTagName();
     if (name == null) {
       continue;
     }
     if (tagnames.contains(name)) {
       // only add existing API tools tags
       fExistingTags.put(name, Boolean.valueOf(tag.fragments().isEmpty()));
     }
   }
   return false;
 }
Exemple #2
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);
   }
 }
 /**
  * Computes all of the Javadoc completion proposals
  *
  * @param jcontext
  * @param corecontext
  * @return the complete list of Javadoc completion proposals or an empty list, never <code>null
  *     </code>
  * @since 1.0.500
  */
 List<ICompletionProposal> computeJavadocProposals(
     JavaContentAssistInvocationContext jcontext, CompletionContext corecontext) {
   ICompilationUnit cunit = jcontext.getCompilationUnit();
   if (cunit != null) {
     try {
       int offset = jcontext.getInvocationOffset();
       IJavaElement element = cunit.getElementAt(offset);
       if (!isVisible(element)) {
         return Collections.EMPTY_LIST;
       }
       ImageDescriptor imagedesc =
           jcontext
               .getLabelProvider()
               .createImageDescriptor(
                   org.eclipse.jdt.core.CompletionProposal.create(
                       org.eclipse.jdt.core.CompletionProposal.JAVADOC_BLOCK_TAG, offset));
       fImageHandle = (imagedesc == null ? null : imagedesc.createImage());
       int type = getType(element);
       int member = IApiJavadocTag.MEMBER_NONE;
       switch (element.getElementType()) {
         case IJavaElement.METHOD:
           {
             IMethod method = (IMethod) element;
             member = IApiJavadocTag.MEMBER_METHOD;
             if (method.isConstructor()) {
               member = IApiJavadocTag.MEMBER_CONSTRUCTOR;
             }
             break;
           }
         case IJavaElement.FIELD:
           {
             member = IApiJavadocTag.MEMBER_FIELD;
             break;
           }
         default:
           break;
       }
       IApiJavadocTag[] tags = ApiPlugin.getJavadocTagManager().getTagsForType(type, member);
       int tagcount = tags.length;
       if (tagcount > 0) {
         ArrayList<ICompletionProposal> list = null;
         collectExistingTags(element, jcontext);
         String completiontext = null;
         int tokenstart = corecontext.getTokenStart();
         int length = offset - tokenstart;
         for (int i = 0; i < tagcount; i++) {
           if (!acceptTag(tags[i], element)) {
             continue;
           }
           completiontext = tags[i].getCompleteTag(type, member);
           if (appliesToContext(
               jcontext.getDocument(), completiontext, tokenstart, (length > 0 ? length : 1))) {
             if (list == null) {
               list = new ArrayList<ICompletionProposal>(tagcount - i);
             }
             list.add(
                 new APIToolsJavadocCompletionProposal(
                     corecontext, completiontext, tags[i].getTagName(), fImageHandle));
           }
         }
         if (list != null) {
           return list;
         }
       }
     } catch (JavaModelException e) {
       fErrorMessage = e.getMessage();
     }
   }
   return Collections.EMPTY_LIST;
 }