/** {@inheritDoc} */
  public IHyperlink createHyperlink(
      String name,
      String target,
      Node node,
      Node parentNode,
      IDocument document,
      ITextViewer textViewer,
      IRegion hyperlinkRegion,
      IRegion cursor) {
    String parentName = null;
    if (parentNode != null) {
      parentName = parentNode.getNodeName();
    }

    List<String> propertyPaths = new ArrayList<String>();
    hyperlinkRegion =
        BeansEditorUtils.extractPropertyPathFromCursorPosition(
            hyperlinkRegion, cursor, target, propertyPaths);
    if ("bean".equals(parentName) && StringUtils.hasText(target)) {
      IFile file = BeansEditorUtils.getFile(document);
      String className =
          BeansEditorUtils.getClassNameForBean(file, node.getOwnerDocument(), parentNode);
      IType type = JdtUtils.getJavaType(file.getProject(), className);

      if (type != null) {
        IBeansConfig config = BeansCorePlugin.getModel().getConfig(file);
        if (config != null && parentNode instanceof Element) {
          IModelElement element = BeansModelUtils.getModelElement((Element) parentNode, config);
          int argIndex = getArgumentIndex(node);
          if (argIndex >= 0) {
            if (element instanceof IBean) {
              IBean bean = (IBean) element;
              int count = bean.getConstructorArguments().size();
              if (count > 0) {
                try {
                  Set<IMethod> methods = Introspector.getConstructors(type, count, false);
                  Iterator<IMethod> iter = methods.iterator();
                  while (iter.hasNext()) {
                    IMethod candidate = iter.next();
                    if (target.equalsIgnoreCase(candidate.getParameterNames()[argIndex])) {
                      // return new JavaElementHyperlink(hyperlinkRegion,
                      // candidate.getParameters()[argIndex]);
                      // TODO: just a temporary workaround for making this Eclipse 3.6 compatible
                      return new JavaElementHyperlink(hyperlinkRegion, candidate);
                    }
                  }
                } catch (JavaModelException e) {
                  // do nothing
                }
              }
            }
          }
        }
      }
    }
    return null;
  }
コード例 #2
0
 private boolean foundInXml(String problemId, ValidationProblemAttribute... attributes) {
   if (attributes != null && "UNDEFINED_REFERENCED_BEAN".equals(problemId)) {
     for (ValidationProblemAttribute attribute : attributes) {
       if ("BEAN".equals(attribute.getKey())) {
         String beanName = (String) attribute.getValue();
         return BeansEditorUtils.getFirstReferenceableNodeById(document, beanName, file) != null;
       }
     }
   }
   return false;
 }