@Override
 public List<ICompletionProposal> computeCompletionProposals(
     ContentAssistInvocationContext context, IProgressMonitor monitor) {
   final List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
   if (context instanceof JavaContentAssistInvocationContext) {
     final JavaContentAssistInvocationContext javaContext =
         (JavaContentAssistInvocationContext) context;
     final IJavaProject javaProject = javaContext.getProject();
     try {
       final IJaxrsMetamodel metamodel = JaxrsMetamodelLocator.get(javaProject);
       // skip if the JAX-RS Nature is not configured for this project
       if (metamodel == null) {
         return Collections.emptyList();
       }
       final IJavaElement invocationElement =
           javaContext.getCompilationUnit().getElementAt(context.getInvocationOffset());
       if (invocationElement.getElementType() == IJavaElement.TYPE) {
         final ITypedRegion region = new TypedRegion(javaContext.getInvocationOffset(), 0, null);
         // proposals.add(new MethodParametersCompletionProposal("Foo !", new StyledString("Foo!"),
         // region, icon, (IMember) invocationElement));
       }
     } catch (CoreException e) {
       Logger.error("Failed to compute completion proposal", e);
     }
   }
   return proposals;
 }
 /** {@inheritDoc} */
 @Override
 public final List<ICompletionProposal> computeCompletionProposals(
     final ContentAssistInvocationContext context, final IProgressMonitor monitor) {
   JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context;
   try {
     CompilationUnit compilationUnit = resolveContextualCompilationUnit(monitor, javaContext);
     IJavaElement invocationElement =
         javaContext.getCompilationUnit().getElementAt(context.getInvocationOffset());
     if (invocationElement.getElementType() == IJavaElement.METHOD) {
       IAnnotationBinding annotationBinding =
           resolveContextualAnnotationBinding(javaContext, compilationUnit);
       // completion proposal on @PathParam method annotation
       if (annotationBinding != null
           && PathParam.class
               .getName()
               .equals(JdtUtils.resolveAnnotationFullyQualifiedName(annotationBinding))) {
         return internalComputePathParamProposals(
             javaContext, annotationBinding, (IMethod) invocationElement, compilationUnit);
       }
     }
   } catch (Exception e) {
     Logger.error("Failed to compute completion proposal", e);
   }
   return Collections.emptyList();
 }
  // @Override
  public List<ICompletionProposal> computeCompletionProposals(
      ContentAssistInvocationContext context, IProgressMonitor monitor) {
    if (!(context instanceof JavaContentAssistInvocationContext)) {
      return Collections.emptyList();
    }
    JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context;

    ICompilationUnit cu = javaContext.getCompilationUnit();
    int offset = context.getInvocationOffset();
    JavadocDmdlFinder finder = new JavadocDmdlFinder(cu, offset);

    List<ModelDefinition> modelList = finder.getModel();
    List<ICompletionProposal> list = new ArrayList<ICompletionProposal>(modelList.size());
    for (ModelDefinition model : modelList) {
      {
        String s = ModelUtil.getDecodedDescription(model);
        if (s != null) {
          CompletionProposal proposal = new CompletionProposal(s, offset, 0, s.length());
          list.add(proposal);
        }
      }
      {
        String s = model.getName();
        CompletionProposal proposal = new CompletionProposal(s, offset, 0, s.length());
        list.add(proposal);
      }
    }
    return list;
  }
  @Override
  public List<ICompletionProposal> computeCompletionProposals(
      final ContentAssistInvocationContext context, final IProgressMonitor monitor) {
    final List<ICompletionProposal> list = new ArrayList<ICompletionProposal>();
    boolean extendContext = false;
    try {
      if (context instanceof JavaContentAssistInvocationContext) {
        final ITextViewer viewer = context.getViewer();
        final List<ScriptVariable> scriptVariables = getScriptVariables(viewer);
        if (scriptVariables.isEmpty()) {
          return list;
        }
        final CompletionContext coreContext =
            ((JavaContentAssistInvocationContext) context).getCoreContext();
        if (coreContext != null && !coreContext.isExtended()) {
          // must use reflection to set the fields
          ReflectionUtils.setPrivateField(
              InternalCompletionContext.class, "isExtended", coreContext, true);
          extendContext = true;
        }
        final ICompilationUnit unit =
            ((JavaContentAssistInvocationContext) context).getCompilationUnit();
        if (unit instanceof GroovyCompilationUnit) {
          if (((GroovyCompilationUnit) unit).getModuleNode() == null) {
            return Collections.emptyList();
          }
          final ContentAssistContext assistContext =
              new GroovyCompletionProposalComputer()
                  .createContentAssistContext(
                      (GroovyCompilationUnit) unit,
                      context.getInvocationOffset(),
                      context.getDocument());
          CharSequence prefix = null;
          try {
            prefix = context.computeIdentifierPrefix();
          } catch (final BadLocationException e) {
            BonitaStudioLog.error(e);
          }

          if (assistContext != null && assistContext.completionNode instanceof VariableExpression) {
            try {
              final VariableExpression expr = (VariableExpression) assistContext.completionNode;
              if (scriptVariables != null) {
                for (final ScriptVariable f : scriptVariables) {
                  if (expr.getName().equals(f.getName())) {
                    final IType type = javaProject.findType(f.getType());
                    if (type == null) {
                      return list;
                    }
                    for (final IMethod m : type.getMethods()) {
                      if (m.getElementName().startsWith(prefix.toString())) {
                        final GroovyCompletionProposal proposal =
                            new GroovyCompletionProposal(
                                CompletionProposal.METHOD_REF, context.getInvocationOffset());
                        proposal.setName(m.getElementName().toCharArray());
                        proposal.setCompletion(
                            m.getElementName().substring(prefix.length()).toCharArray());
                        proposal.setFlags(m.getFlags());

                        if (prefix.length() == m.getElementName().length()) {
                          proposal.setReplaceRange(
                              context.getInvocationOffset(), context.getInvocationOffset());
                          proposal.setReceiverRange(0, 0);
                        } else {
                          proposal.setReplaceRange(
                              context.getInvocationOffset() - prefix.length(),
                              context.getInvocationOffset());
                          proposal.setReceiverRange(prefix.length(), prefix.length());
                        }

                        final char[][] parametersArray =
                            new char[m.getParameterNames().length][256];
                        final List<Parameter> parameters = new ArrayList<Parameter>();
                        for (int i = 0; i < m.getParameterNames().length; i++) {
                          parametersArray[i] = m.getParameterNames()[i].toCharArray();
                          parameters.add(
                              new Parameter(
                                  ClassHelper.make(
                                      Signature.getSignatureSimpleName(m.getParameterTypes()[i])),
                                  m.getParameterNames()[i]));
                        }

                        final ClassNode classNode =
                            ClassHelper.make(m.getDeclaringType().getFullyQualifiedName());
                        proposal.setDeclarationSignature(
                            ProposalUtils.createTypeSignature(classNode));
                        proposal.setParameterNames(parametersArray);
                        if (m.getDeclaringType().getFullyQualifiedName().equals(f.getType())) {
                          proposal.setRelevance(100);
                        }

                        final MethodNode methodNode =
                            new MethodNode(
                                m.getElementName(),
                                m.getFlags(),
                                ClassHelper.make(
                                    Signature.getSignatureSimpleName(m.getReturnType())),
                                parameters.toArray(new Parameter[parameters.size()]),
                                new ClassNode[0],
                                null);
                        final char[] methodSignature =
                            ProposalUtils.createMethodSignature(methodNode);
                        proposal.setSignature(methodSignature);

                        final GroovyJavaGuessingCompletionProposal groovyProposal =
                            GroovyJavaGuessingCompletionProposal.createProposal(
                                proposal,
                                (JavaContentAssistInvocationContext) context,
                                true,
                                "Groovy",
                                ProposalFormattingOptions.newFromOptions());
                        if (groovyProposal != null) {
                          list.add(groovyProposal);
                        }
                      }
                    }
                  }
                }
              }
            } catch (final JavaModelException e) {
              BonitaStudioLog.error(e);
            }
          }
        }

        return list;
      }
    } finally {
      final CompletionContext coreContext =
          ((JavaContentAssistInvocationContext) context).getCoreContext();
      if (extendContext && coreContext != null && coreContext.isExtended()) {
        // must use reflection to set the fields
        ReflectionUtils.setPrivateField(
            InternalCompletionContext.class, "isExtended", coreContext, false);
      }
    }

    return Collections.emptyList();
  }
  @Override
  public List<ICompletionProposal> computeCompletionProposals(
      ContentAssistInvocationContext context, IProgressMonitor monitor) {
    Map tags = DoclipsePlugin.getDoclipseProject().getAllTags();
    List vResult = new ArrayList();
    int offset = context.getInvocationOffset();
    JavadocContentAssistInvocationContext javadoc = (JavadocContentAssistInvocationContext) context;
    IJavaElement element = null;
    try {
      element = javadoc.getCompilationUnit().getElementAt(offset);
    } catch (JavaModelException e) {
      e.printStackTrace();
      return new ArrayList<ICompletionProposal>();
    }
    m_document = context.getDocument();
    try {
      // Locate if we are on a method, a class, etc...

      // Let's see if we are trying to complete on a tag or on
      // an attribute. First, locate where the @ sign started.
      String pref = Utils.locateWordThatStartsWithAt(m_document, offset);
      if (pref == null) {
        return new ArrayList<ICompletionProposal>();
      }
      //
      // Determine what the user is trying to complete on:
      // - tag name
      // - attribute name
      // - attribute value
      // TagFragment will do all the dirty parsing for us.
      //

      ITagFragment tf = TagFragmentFactory.newTagFragment(pref);
      String fragment = tf.getFragment();
      if (tf.completesOnTagName()) {
        for (Iterator it = tags.values().iterator(); it.hasNext(); ) {
          Tag tag = (Tag) it.next();
          String tagName = tag.getName();
          boolean starts = tagName.startsWith(fragment);
          boolean matchTarget = matchTarget(tag, element);
          if (starts && matchTarget) {
            vResult.add(new TagCompletionProposal(tag.getName(), tag.getDoc()));
          }
        }

      } else if (tf.completesOnAttribute()) {
        String tagName = tf.getTagName();
        Tag tag = (Tag) tags.get(tagName);
        if (null != tag) {
          Collection attributes = tag.getAttributes();
          for (Iterator it = attributes.iterator(); it.hasNext(); ) {
            Attribute a = (Attribute) it.next();
            String attributeName = a.getName();
            if (tf.hasAttr(attributeName)) {
              continue;
            }
            String doc = a.getDoc();
            if (attributeName.startsWith(fragment)) {
              vResult.add(new AttributeCompletionProposal(tagName, attributeName, doc));
            }
          }
        }
      } else {
        String tagName = tf.getTagName();
        Tag tag = (Tag) tags.get(tagName);
        if (null != tag) {
          Attribute a = tag.getAttribute(tf.getAttributeName());
          if (null != a) {
            String[] allowed = a.getAllowed();
            for (int i = 0; i < allowed.length; i++) {
              vResult.add(new AttributeValueCompletionProposal(tagName, allowed[i]));
            }
          }
        }
      }
    } catch (BadLocationException ex) {
      ex.printStackTrace();
    }
    return vResult;
  }