Examples of BodyDeclaration


Examples of org.eclipse.jdt.core.dom.BodyDeclaration

  protected IStatus run(IProgressMonitor monitor) {
    try {
      final IPackageFragment pkg = (IPackageFragment) target;
      String uri = new String(source);
      Search search = CodeConjurer.getInstance().getActiveEditorSearch();
      final BodyDeclaration selectedElement = search.getSearchResult()
          .find(uri);

      // Insert class
      if (selectedElement.getNodeType() == BodyDeclaration.TYPE_DECLARATION) {
        monitor.beginTask("Insert class into package", 2);
        TypeDeclaration typeDec = (TypeDeclaration) selectedElement;

        String adapterCode = null;

        // If this is a result from test-driven search and an adapter is
        // present, use it.
        if (Integer.parseInt((String) typeDec
            .getProperty(ResultProperty.SEARCH_KIND.name())) == Search.TEST_DRIVEN_SEARCH) {
          adapterCode = (String) typeDec
              .getProperty(ResultProperty.TEST_RESULT.name());
          if (adapterCode.contains("<adapter>false</adapter>")) {
            adapterCode = null; // Only if an adapter is necessary,
                      // we leave this value set
          }
        }

        String name = typeDec.getName().toString();
        String sourceCode = (String) selectedElement
            .getProperty(ResultProperty.RAW_SOURCE.name());

        /** Indicates if an adapter was created */
        boolean adapted = false;

        /* Insert the adapter if the user wishes */
        if (Activator.getDefault().getPreferenceStore()
            .getBoolean(PreferenceConstants.P_SHOW_ADAPTER)) {
          if (adapterCode != null) {
            adapterCode = adapterCode
                .replace(
                    "merobase_auto_generated_package_for_adaptation",
                    pkg.getElementName());

            monitor.subTask("Insert adapter class");
            // Find out the name of the adapter
            ASTParser parser = ASTParser.newParser(AST.JLS3);
            parser.setSource(adapterCode.toCharArray());
            CompilationUnit astRoot = (CompilationUnit) parser
                .createAST(null);
            List<TypeDeclaration> typeList = astRoot.types();
            if (typeList != null && typeList.size() > 0) {
              TypeDeclaration adapterType = (TypeDeclaration) typeList
                  .get(0);
              insertType(pkg, adapterType.getName().toString(),
                  adapterCode, true, monitor);
            }
            monitor.worked(1);

            monitor.subTask("Check for adaptee package");
            IPackageFragmentRoot pkgRoot = (IPackageFragmentRoot) pkg
                .getParent();
            String pkgname = pkg.getElementName();
            // pkgRoot.open(monitor);
            IPackageFragment adapteePkg = pkgRoot
                .createPackageFragment(pkgname + "."
                    + "adaptee", true, monitor);

            monitor.subTask("Insert adaptee with functionality");
            /* Insert the adaptee class */
            insertType(adapteePkg, name, sourceCode, true, monitor);
            monitor.worked(1);

            logger.debug("Check for interfaces");

            for (Object typeDecO : typeDec.superInterfaceTypes()) {
              Type tDec = (Type) typeDecO;
              logger.debug("Implements " + tDec);
              StringBuilder iface = new StringBuilder("package "
                  + adapteePkg.getElementName() + ";"
                  + System.getProperty("line.separator"));
              iface.append(System.getProperty("line.separator")
                  + "/** Automatically generated interface dependency */"
                  + System.getProperty("line.separator"));
              iface.append("public interface " + tDec + "{}");
              // The interfaces should not be opened
              insertType(adapteePkg, tDec.toString(),
                  iface.toString(), false, monitor);
            }

            adapted = true;
          }
        }

        // Insert the result without adapter
        if (!adapted) {
          insertType(pkg, name, sourceCode, true, monitor);
          monitor.worked(1);
        }

      }
      if (selectedElement.getNodeType() == BodyDeclaration.METHOD_DECLARATION) {
        MethodDeclaration methodDec = (MethodDeclaration) selectedElement;
        IWorkbenchWindow window = PluginUI.getWindow();
        if (window == null)
          return Status.CANCEL_STATUS;
        Shell shell = window.getShell();
View Full Code Here

Examples of org.eclipse.jdt.core.dom.BodyDeclaration

   */
  @Override
  public void doubleClick(DoubleClickEvent event) {
    TreeViewer source = (TreeViewer) event.getSource();
    TreeSelection selection = (TreeSelection) event.getSelection();
    BodyDeclaration selectedElement = (BodyDeclaration) selection
        .getFirstElement();

    Object[] expanded = source.getExpandedElements();
    boolean isExpanded = false;
    for (Object elO : expanded) {
      BodyDeclaration el = (BodyDeclaration) elO;
      if (el.getProperty(ResultProperty.URI.name())
          .toString()
          .equals((selectedElement.getProperty(ResultProperty.URI
              .name())).toString())) {
        isExpanded = true;
      }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.BodyDeclaration

  protected IStatus run(IProgressMonitor monitor) {
    try {
      IPackageFragment pkg = (IPackageFragment) target.getParent();
      String uri = new String(source);
      Search search = CodeConjurer.getInstance().getActiveEditorSearch();
      BodyDeclaration selectedElement = search.getSearchResult()
          .find(uri);

      // Insert method
      if (selectedElement.getNodeType() == BodyDeclaration.METHOD_DECLARATION) {
        boolean overwrite = Activator.getDefault().getPreferenceStore()
            .getBoolean(PreferenceConstants.P_OVERWRITE_ON_INSERT);
        ICompilationUnit cpu = target.getWorkingCopy(null);
        // creation of DOM/AST from an ICompilationUnit
        ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(cpu);
        CompilationUnit astRoot = (CompilationUnit) parser
            .createAST(null);

        // creation of ASTRewrite
        astRoot.recordModifications();
        IMethod method = null;
        String content = createPreambule(selectedElement) + "\r\n"
            + selectedElement.toString();
        try {
          method = astRoot.getTypeRoot().findPrimaryType()
              .createMethod(content, null, overwrite, null);
        } catch (JavaModelException e) {
          logger.debug("Method could not be created: "
              + e.getLocalizedMessage());
        }

        if (method != null) {
          if (overwrite) {
            IMethod[] methods = astRoot.getTypeRoot()
                .findPrimaryType().findMethods(method);
            for (int i = 0; i < methods.length - 1; i++) {
              methods[i].delete(false, null);
            }
          }
        }

        // update of the compilation unit
        cpu.getBuffer().setContents(
            astRoot.getTypeRoot().findPrimaryType()
                .getCompilationUnit().getSource());
        cpu.reconcile(ICompilationUnit.NO_AST, false, null, null);
        cpu.commitWorkingCopy(false, null);
        return Status.OK_STATUS;
      }

      // Insert class
      if (selectedElement.getNodeType() == BodyDeclaration.TYPE_DECLARATION) {
        TypeDeclaration typeDec = (TypeDeclaration) selectedElement;
        String name = typeDec.getName().toString();
        String sourceCode = (String) selectedElement
            .getProperty(ResultProperty.RAW_SOURCE.name());

        // If a CompilatonUnit with the same name exists and is
        // opened, we must close it before overwrite.
        ICompilationUnit icu = pkg.getCompilationUnit(name + ".java");
View Full Code Here

Examples of org.eclipse.jdt.core.dom.BodyDeclaration

  public void dragStart(DragSourceEvent event) {
    selection = viewer.getTree().getSelection();
    if (selection == null || selection.length == 0) {
      event.doit = false;
    }
    BodyDeclaration selectedElement = (BodyDeclaration) selection[0]
        .getData();
    logger.debug("URI: "
        + selectedElement.getProperty(ResultProperty.URI.name()));
  }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.BodyDeclaration

  @Override
  public void dragSetData(DragSourceEvent event) {
    logger.debug(event.dataType + " requested by drop target.");

    try {
      BodyDeclaration selectedElement = (BodyDeclaration) selection[0]
          .getData();
      if (PluginTransfer.getInstance().isSupportedType(event.dataType)) {
        // For a PluginTransfer, we transmit the URI of the element.
        // The DropListener is responsible for handling this.
        Object uri = selectedElement.getProperty(ResultProperty.URI
            .name());
        if (uri != null)
          event.data = new PluginTransferData(
              "de.uni_mannheim.swt.codeconjurer.ui.dnd.pluginDropAction",
              (((String) uri).getBytes()));
        logger.debug("PluginTransfer triggered for " + uri);
      } else if (TextTransfer.getInstance().isSupportedType(
          event.dataType)) {
        // TextTransfer simply transfers the selected code element.
        String sourceLink = "@origin \r\n * "
            + selectedElement.getProperty(ResultProperty.SHORT_URL
                .name()) + "";
        String data = selectedElement.toString();
        if (data.startsWith("/**") && data.contains("*/")) {
          event.data = data.substring(0, data.indexOf("*/") - 2)
              + "\r\n * \r\n * " + sourceLink + "\r\n *"
              + data.substring(data.indexOf("*/"), data.length());
        } else {
          event.data = "/** " + sourceLink + "\r\n */"
              + selectedElement.toString();
        }
        logger.debug("TextTransfer triggered");
      }
    } catch (Exception e) {
      CrashReporter.reportException(e);
View Full Code Here

Examples of org.eclipse.jdt.core.dom.BodyDeclaration

      if (!Activator.getDefault().getPreferenceStore()
          .getBoolean(PreferenceConstants.P_SHOW_NEGATIVES)) {
        noShowNegatives = true;
      }
      for (ResultItem result : results) {
        BodyDeclaration typeRoot = result.getTypeRoot();
        if (noShowNegatives
            && result.getProperty(ResultProperty.TEST_RESULT)
                .startsWith("// No adapter created")) {
          logger.trace("Skip negative result.");
        } else {
          logger.trace("Add result.");
          if (typeRoot != null) {
            elements.add(typeRoot);
          }
        }
      }
    } else {
      for (ResultItem result : results) {
        BodyDeclaration typeRoot = result.getTypeRoot();
        if (typeRoot != null) {
          elements.add(typeRoot);
        }
      }
    }
View Full Code Here

Examples of org.eclipse.jdt.core.dom.BodyDeclaration

   * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.
   * Object)
   */
  @Override
  public Object[] getChildren(Object parentElement) {
    BodyDeclaration element = (BodyDeclaration) parentElement;
    ArrayList<MethodDeclaration> methods = new ArrayList<MethodDeclaration>();
    if (element.getNodeType() == ASTNode.TYPE_DECLARATION) {
      for (MethodDeclaration method : ((TypeDeclaration) element)
          .getMethods()) {
        // Copy properties from class to methods
        Set<?> properties = element.properties().keySet();
        for (String property : (String[]) properties
            .toArray(new String[element.properties().size()])) {
          method.setProperty(property, element.getProperty(property));
        }
        // Set a unique identifier (required for DND)
        String sign = "" + method.getReturnType2() + method.getName();
        for (Object p : method.parameters()) {
          sign += p.toString();
        }
        // Replace the copied parent's URI from above with a new URI
        // extended with the signature of the child and a mark
        method.setProperty(ResultProperty.URI.name(),
            method.getProperty(ResultProperty.URI.name())
                + CodeConjurer.URI_DELIMITER + sign);
        methods.add(method);
      }
      return methods.toArray();
    }
    if (element.getNodeType() == ASTNode.ENUM_DECLARATION) {
      for (Object declaration : ((EnumDeclaration) element)
          .bodyDeclarations()) {
        if (declaration instanceof MethodDeclaration) {
          MethodDeclaration method = (MethodDeclaration) declaration;
          // Copy properties from class to methods
          Set<?> properties = element.properties().keySet();
          for (String property : (String[]) properties
              .toArray(new String[element.properties().size()])) {
            method.setProperty(property,
                element.getProperty(property));
          }
          // Set a unique identifier (required for DND)
          String sign = "" + method.getReturnType2()
              + method.getName();
          for (Object p : method.parameters()) {
View Full Code Here

Examples of org.eclipse.jdt.core.dom.BodyDeclaration

   * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.
   * Object)
   */
  @Override
  public boolean hasChildren(Object parentElement) {
    BodyDeclaration element = (BodyDeclaration) parentElement;

    // Only AbstractTypeDeclarations may have children
    if (element.getNodeType() == ASTNode.TYPE_DECLARATION) {
      if (((TypeDeclaration) element).getMethods().length > 0) {
        return true;
      }
    }
    if (element.getNodeType() == ASTNode.ENUM_DECLARATION) {
      if (((EnumDeclaration) element).bodyDeclarations().size() > 0) {
        return true;
      }
    }

View Full Code Here

Examples of org.eclipse.jdt.core.dom.BodyDeclaration

  // private Logger logger = Logger.getLogger(ResultLabelProvider.class);

  @Override
  public Image getColumnImage(Object item, int columnIndex) {
    Image img = null;
    BodyDeclaration element = (BodyDeclaration) item;
    if (columnIndex == 0) {
      if (element.getNodeType() == ASTNode.TYPE_DECLARATION) {
        img = JavaUI.getSharedImages().getImage(
            ISharedImages.IMG_OBJS_CLASS_DEFAULT);
      }
      if (element.getNodeType() == ASTNode.ENUM_DECLARATION) {
        img = JavaUI.getSharedImages().getImage(
            ISharedImages.IMG_OBJS_ENUM);
      }
      if (element.getNodeType() == ASTNode.METHOD_DECLARATION) {
        MethodDeclaration method = (MethodDeclaration) element;
        if (method.isConstructor()) {
          img = JavaUI.getSharedImages().getImage(
              ISharedImages.IMG_OBJS_INNER_CLASS_DEFAULT);
        } else {
View Full Code Here

Examples of org.eclipse.jdt.core.dom.BodyDeclaration

    return img;
  }

  @Override
  public String getColumnText(Object item, int columnIndex) {
    BodyDeclaration element = (BodyDeclaration) item;
    if (element.getNodeType() == ASTNode.TYPE_DECLARATION) {
      if (columnIndex == 0) {
        return ((TypeDeclaration) element).getName()
            .getFullyQualifiedName();
      }
      if (columnIndex == 1) {
        String license = ""
            + element.getProperty(ResultProperty.LICENSE.name());
        if (!license.contains("null")) {
          return license;
        }
      }
      if (columnIndex == 2) {
        // Was testing / adaptation successful?
        if (((String) element.getProperty(ResultProperty.EXECUTABILITY
            .name())).equals(Executability.TESTED.value())) {
          // Set color to green if no adapter is necessary, yellow
          // otherwise
          if (((String) element
              .getProperty(ResultProperty.TEST_RESULT.name()))
              .startsWith("// No adapter necessary")) {
            return "TESTED";
          } else {
            return "ADAPTED";
          }
        } else {
          return "FAILED";
        }
      }
    }
    if (element.getNodeType() == ASTNode.ENUM_DECLARATION
        && columnIndex == 0) {
      return ((EnumDeclaration) element).getName()
          .getFullyQualifiedName();
    }
    if (element.getNodeType() == ASTNode.METHOD_DECLARATION
        && columnIndex == 0) {
      return ((MethodDeclaration) element).getName()
          .getFullyQualifiedName();
    }
    return null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.