/** {@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
 /** {@inheritDoc} */
 public void cleanup(IResource resource, IProgressMonitor monitor) throws CoreException {
   if (BeansCoreUtils.isBeansConfig(resource) && resource instanceof IFile) {
     IBeansConfig beansConfig = BeansCorePlugin.getModel().getConfig((IFile) resource);
     for (IBean bean : beansConfig.getBeans()) {
       BeansMetadataPlugin.getMetadataModel().clearBeanMetadata(bean);
       BeansMetadataPlugin.getMetadataModel().clearBeanProperties(bean);
     }
     // Notify that the model has changed.
     // ((BeansModel) BeansCorePlugin.getModel()).notifyListeners(beansConfig, Type.CHANGED);
   }
 }
コード例 #3
0
    @Override
    protected boolean selectFile(IFile element) {

      if ("pom.xml".equals(element.getName())) {
        return false;
      }

      IBeansProject project = BeansCorePlugin.getModel().getProject(element.getProject());
      if (project != null) {
        IBeansConfig beansConfig = project.getConfig(element);
        return beansConfig == null;
      }
      return false;
    }
コード例 #4
0
 @Override
 public String getText(Object element) {
   String label = super.getText(element);
   if (element instanceof IFile) {
     IBeansConfig bc = BeansCorePlugin.getModel().getConfig((IFile) element, true);
     if (bc instanceof IImportedBeansConfig) {
       label += " [imported]";
     }
     if (bc != null && bc.getType() == IBeansConfig.Type.AUTO_DETECTED) {
       label += " [auto detected]";
     }
   } else if (element instanceof ZipEntryStorage) {
     return ((ZipEntryStorage) element).getEntryName();
   }
   if (label != null && label.startsWith(IBeansConfig.EXTERNAL_FILE_NAME_PREFIX)) {
     label = label.substring(IBeansConfig.EXTERNAL_FILE_NAME_PREFIX.length());
   }
   return label;
 }