Package org.eclipse.jdt.core.dom

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


    ITableLabelProvider, ITableColorProvider {

  @Override
  public Image getColumnImage(Object item, int columnIndex) {
    Image img = null;
    BodyDeclaration element = (BodyDeclaration) item;
    if (element.getNodeType() == ASTNode.TYPE_DECLARATION) {
      img = JavaUI.getSharedImages().getImage(
          ISharedImages.IMG_OBJS_CLASS);
    }
    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


    return img;
  }

  @Override
  public String getColumnText(Object item, int columnIndex) {
    BodyDeclaration element = (BodyDeclaration) item;
    if (element.getNodeType() == ASTNode.TYPE_DECLARATION) {
      return ((TypeDeclaration) element).getName()
          .getFullyQualifiedName();
    }
    if (element.getNodeType() == ASTNode.METHOD_DECLARATION) {
      return ((MethodDeclaration) element).getName()
          .getFullyQualifiedName();
    }
    return null;
  }
View Full Code Here

    return null;
  }

  @Override
  public Color getForeground(Object item, int columnIndex) {
    BodyDeclaration element = (BodyDeclaration) item;
    Color color = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
    String source = element.toString();
    if (source != null && !source.equals("")) {
      color = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
    } else {
      color = Display.getCurrent().getSystemColor(SWT.COLOR_GRAY);
    }
View Full Code Here

  protected IStatus run(IProgressMonitor monitor) {
    try {
      IPackageFragment pkg = (IPackageFragment) target;
      String uri = new String(source);
      Search search = CodeConjurer.getInstance().getActiveEditorSearch();
      BodyDeclaration selectedElement = search.getSearchResult()
          .find(uri);
      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

   */
  protected void setPreview() {
    resultTree.refresh();
    TreeItem selection = resultTree.getSelectedElement();
    if (selection != null) {
      BodyDeclaration selected = (BodyDeclaration) selection.getData();
      // Show the source code of the selection
      if (preview != null) {
        if (selected != null) {
          String previewCode = "";
          String adapterCode = "";
          if (selected.getNodeType() == BodyDeclaration.TYPE_DECLARATION) {
            previewCode = (String) selected
                .getProperty(ResultProperty.RAW_SOURCE.name());
            adapterCode = (String) selected
                .getProperty(ResultProperty.TEST_RESULT.name());
          } else {
            previewCode = selected.toString();
            adapterCode = "// Adapter not available";
          }
          boolean showAdapter = Activator.getDefault()
              .getPreferenceStore()
              .getBoolean(PreferenceConstants.P_SHOW_ADAPTER);
          String searchKind = selected.getProperty(
              ResultProperty.SEARCH_KIND.name()).toString();
          if (showAdapter
              && searchKind.equals(String
                  .valueOf(Search.TEST_DRIVEN_SEARCH))) {
            preview.setCode(adapterCode);
View Full Code Here

    } else {
      shortUrl = uri;
    }
    ResultItem result = getResultItem(shortUrl);
    if (result != null) {
      BodyDeclaration declaration = result.find(uri);
      return declaration;
    } else {
      return null;
    }
  }
View Full Code Here

   *         compilation unit was created from, or null if it was not created
   *         from a Java type root.
   */
  public BodyDeclaration getTypeRoot() {
    if (resultCompilationUnit != null) {
      BodyDeclaration declaration = null;
      for (Object typeObject : resultCompilationUnit.types()) {
        BodyDeclaration typeBodyDec = (BodyDeclaration) typeObject;
        if (typeBodyDec.getNodeType() == BodyDeclaration.TYPE_DECLARATION) {
          TypeDeclaration type = (TypeDeclaration) typeBodyDec;
          String typeName = type.getName().getFullyQualifiedName();
          String reportedName = getProperty(ResultProperty.NAME);
          if (typeName.equals(reportedName))
            declaration = type;
        }
        if (typeBodyDec.getNodeType() == BodyDeclaration.ENUM_DECLARATION) {
          EnumDeclaration type = (EnumDeclaration) typeBodyDec;
          if (type.getName().getFullyQualifiedName()
              .equals(getProperty(ResultProperty.NAME)))
            declaration = type;
        }
View Full Code Here

  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

   */
  @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

  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

TOP

Related Classes of org.eclipse.jdt.core.dom.BodyDeclaration

Copyright © 2018 www.massapicom. 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.