Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IPackageFragment


      getFolder("src/main/resources/test");
      moduleFile.move(new Path("/TestProject/src/main/resources/test/Module.gwt.xml"), true, null);
    }
    // OK, really "source" package
    {
      IPackageFragment pkg = m_testProject.getPackage("test.client");
      assertTrue(Utils.isModuleSourcePackage(pkg));
    }
  }
View Full Code Here


   * IProgressMonitor)
   */
  @Override
  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");
        if (icu != null && icu.isWorkingCopy()) {
          icu.close();
        }

        // Create the compilationUnit
        final ICompilationUnit icu2 = pkg
            .createCompilationUnit(
                name + ".java",
                sourceCode,
                Activator
                    .getDefault()
                    .getPreferenceStore()
                    .getBoolean(
                        PreferenceConstants.P_OVERWRITE_ON_INSERT),
                null);

        icu2.createPackageDeclaration(pkg.getElementName(), null);

        IFile input = (IFile) icu2.getResource();
        final IEditorInput editorInput = new FileEditorInput(input);
        final IEditorDescriptor desc = PlatformUI.getWorkbench()
            .getEditorRegistry().getDefaultEditor(input.getName());
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  @Override
  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 + "{}");
View Full Code Here

   * IProgressMonitor)
   */
  @Override
  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");
        if (icu != null && icu.isWorkingCopy()) {
          icu.close();
        }

        // Create the compilationUnit
        final ICompilationUnit icu2 = pkg
            .createCompilationUnit(
                name + ".java",
                sourceCode,
                Activator
                    .getDefault()
                    .getPreferenceStore()
                    .getBoolean(
                        PreferenceConstants.P_OVERWRITE_ON_INSERT),
                null);

        icu2.createPackageDeclaration(pkg.getElementName(), null);

        IFile input = (IFile) icu2.getResource();
        final IEditorInput editorInput = new FileEditorInput(input);
        final IEditorDescriptor desc = PlatformUI.getWorkbench()
            .getEditorRegistry().getDefaultEditor(input.getName());
View Full Code Here

    return null;
  }

  private ICompilationUnit findCompilationUnit(String[] pkgName, String cuName, PackageFragmentRoot root) {
    if (!root.isArchive()) {
      IPackageFragment pkg = root.getPackageFragment(pkgName);
      try {
        ICompilationUnit[] cus = pkg.getCompilationUnits();
        for (int j = 0, length = cus.length; j < length; j++) {
          ICompilationUnit cu = cus[j];
          if (Util.equalsIgnoreJavaLikeExtension(cu.getElementName(), cuName))
            return cu;
        }
View Full Code Here

          } catch (JavaModelException npe) {
            continue; // the package fragment root is not present;
          }
          int elementCount = list.length;
          for (int j = 0; j < elementCount; j++) {
            IPackageFragment packageFragment = (IPackageFragment) list[j];
            if (nameMatches(name, packageFragment, false)) {
              return packageFragment;
            }
          }
        }
View Full Code Here

            ? CharOperation.match(lowercaseName, Util.concatCompoundNameToCharArray(pkgName), false)
            : Util.startsWithIgnoreCase(pkgName, splittedName, partialMatch));
          if (match) {
            Object value = this.packageFragments.valueTable[i];
            if (value instanceof PackageFragmentRoot) {
              IPackageFragment pkg = ((PackageFragmentRoot) value).getPackageFragment(pkgName);
              if (oneFragment == null) {
                oneFragment = new IPackageFragment[] {pkg};
              } else {
                if (pkgs == null) {
                  pkgs = new ArrayList();
                  pkgs.add(oneFragment[0]);
                }
                pkgs.add(pkg);
              }
            } else {
              IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value;
              for (int j = 0, length2 = roots.length; j < length2; j++) {
                PackageFragmentRoot root = (PackageFragmentRoot) roots[j];
                IPackageFragment pkg = root.getPackageFragment(pkgName);
                if (oneFragment == null) {
                  oneFragment = new IPackageFragment[] {pkg};
                } else {
                  if (pkgs == null) {
                    pkgs = new ArrayList();
View Full Code Here

      this.nameLookup = ((JavaProject) projects[i]).newNameLookup(this.workingCopies);
      IPackageFragment[] packageFragments = this.nameLookup.findPackageFragments(new String(pkgPattern.pkgName), false, true);
      int pLength = packageFragments == null ? 0 : packageFragments.length;
      // Report matches avoiding duplicate names
      for (int p=0; p<pLength; p++) {
        IPackageFragment fragment = packageFragments[p];
        if (packages.addIfNotIncluded(fragment) == null) continue;
        if (encloses(fragment)) {
          IResource resource = fragment.getResource();
          if (resource == null) // case of a file in an external jar
            resource = javaProject.getProject();
          try {
            if (encloses(fragment)) {
              SearchMatch match = new PackageDeclarationMatch(fragment, SearchMatch.A_ACCURATE, -1, -1, participant, resource);
View Full Code Here

          int segments = path.segmentCount();
          while (elements.hasNext()) {
            IFolder f = (IFolder) elements.next();
            IPath relativePath = f.getFullPath().removeFirstSegments(segments);
            String[] pkgName = relativePath.segments();
            IPackageFragment pkg = root.getPackageFragment(pkgName);
            if (!Util.isExcluded(pkg))
              fragments.add(pkg);
          }
        }
      }
View Full Code Here

        || (newOutputLocation != null && !newOutputLocation.equals(this.oldOutputLocation))) {
      try {
        ArrayList added = determineAffectedPackageFragments(this.oldOutputLocation);
        Iterator iter = added.iterator();
        while (iter.hasNext()){
          IPackageFragment frag= (IPackageFragment)iter.next();
          ((IPackageFragmentRoot)frag.getParent()).close();
          delta.added(frag);
        }

        // see if this will cause any package fragments to be removed
        ArrayList removed = determineAffectedPackageFragments(newOutputLocation);
        iter = removed.iterator();
        while (iter.hasNext()) {
          IPackageFragment frag= (IPackageFragment)iter.next();
          ((IPackageFragmentRoot)frag.getParent()).close();
          delta.removed(frag);
        }
      } catch (JavaModelException e) {
        if (DeltaProcessor.VERBOSE)
          e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.IPackageFragment

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.