当前位置: 首页>>代码示例>>Java>>正文


Java JavaElementUtil.getPackageAndSubpackages方法代码示例

本文整理汇总了Java中org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil.getPackageAndSubpackages方法的典型用法代码示例。如果您正苦于以下问题:Java JavaElementUtil.getPackageAndSubpackages方法的具体用法?Java JavaElementUtil.getPackageAndSubpackages怎么用?Java JavaElementUtil.getPackageAndSubpackages使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil的用法示例。


在下文中一共展示了JavaElementUtil.getPackageAndSubpackages方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChangedFiles

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
@Override
protected IFile[] getChangedFiles() throws CoreException {
  Set<IFile> combined = new HashSet<IFile>();
  combined.addAll(Arrays.asList(ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits())));
  if (fRenameSubpackages) {
    IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(fPackage);
    for (int i = 0; i < allPackages.length; i++) {
      combined.addAll(Arrays.asList(ResourceUtil.getFiles(allPackages[i].getCompilationUnits())));
    }
  } else {
    combined.addAll(Arrays.asList(ResourceUtil.getFiles(fPackage.getCompilationUnits())));
  }
  if (fQualifiedNameSearchResult != null)
    combined.addAll(Arrays.asList(fQualifiedNameSearchResult.getAllFiles()));
  return combined.toArray(new IFile[combined.size()]);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:RenamePackageProcessor.java

示例2: createUndoChange

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
@Override
protected Change createUndoChange(long stampToRestore) throws CoreException {
  IPackageFragment pack = getPackage();
  if (pack == null) return new NullChange();
  Map<IResource, Long> stamps = new HashMap<IResource, Long>();
  if (!fRenameSubpackages) {
    addStamps(stamps, pack.getCompilationUnits());
  } else {
    IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(pack);
    for (int i = 0; i < allPackages.length; i++) {
      IPackageFragment currentPackage = allPackages[i];
      addStamps(stamps, currentPackage.getCompilationUnits());
    }
  }
  return new RenamePackageChange(
      createNewPath(), getNewName(), getOldName(), stampToRestore, stamps, fRenameSubpackages);
  // Note: This reverse change only works if the renamePackage change did
  // not merge the source package into an existing target.
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:RenamePackageChange.java

示例3: getChangedFiles

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
@Override
protected IFile[] getChangedFiles() throws CoreException {
	Set<IFile> combined= new HashSet<IFile>();
	combined.addAll(Arrays.asList(ResourceUtil.getFiles(fChangeManager.getAllCompilationUnits())));
	if (fRenameSubpackages) {
		IPackageFragment[] allPackages= JavaElementUtil.getPackageAndSubpackages(fPackage);
		for (int i= 0; i < allPackages.length; i++) {
			combined.addAll(Arrays.asList(ResourceUtil.getFiles(allPackages[i].getCompilationUnits())));
		}
	} else {
		combined.addAll(Arrays.asList(ResourceUtil.getFiles(fPackage.getCompilationUnits())));
	}
	if (fQualifiedNameSearchResult != null)
		combined.addAll(Arrays.asList(fQualifiedNameSearchResult.getAllFiles()));
	return combined.toArray(new IFile[combined.size()]);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:RenamePackageProcessor.java

示例4: createUndoChange

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
@Override
protected Change createUndoChange(long stampToRestore) throws CoreException {
	IPackageFragment pack= getPackage();
	if (pack == null)
		return new NullChange();
	Map<IResource, Long> stamps= new HashMap<IResource, Long>();
	if (!fRenameSubpackages) {
		addStamps(stamps, pack.getCompilationUnits());
	} else {
		IPackageFragment[] allPackages= JavaElementUtil.getPackageAndSubpackages(pack);
		for (int i= 0; i < allPackages.length; i++) {
			IPackageFragment currentPackage= allPackages[i];
			addStamps(stamps, currentPackage.getCompilationUnits());
		}
	}
	return new RenamePackageChange(createNewPath(), getNewName(), getOldName(), stampToRestore, stamps, fRenameSubpackages);
	// Note: This reverse change only works if the renamePackage change did
	// not merge the source package into an existing target.
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:20,代码来源:RenamePackageChange.java

示例5: checkPackageInCurrentRoot

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
private RefactoringStatus checkPackageInCurrentRoot(String newName) throws CoreException {
  if (fRenameSubpackages) {
    String currentName = getCurrentElementName();
    if (isAncestorPackage(currentName, newName)) {
      // renaming to subpackage (a -> a.b) is always OK, since all subpackages are also renamed
      return null;
    }
    if (!isAncestorPackage(newName, currentName)) {
      // renaming to an unrelated package
      if (!isPackageNameOkInRoot(newName, getPackageFragmentRoot())) {
        return RefactoringStatus.createFatalErrorStatus(
            RefactoringCoreMessages.RenamePackageRefactoring_package_exists);
      }
    }
    // renaming to superpackage (a.b -> a) or another package is OK iff
    // 'a.b' does not contain any subpackage that would collide with another subpackage of 'a'
    // (e.g. a.b.c collides if a.c already exists, but a.b.b does not collide with a.b)
    IPackageFragment[] packsToRename = JavaElementUtil.getPackageAndSubpackages(fPackage);
    for (int i = 0; i < packsToRename.length; i++) {
      IPackageFragment pack = packsToRename[i];
      String newPack = newName + pack.getElementName().substring(currentName.length());
      if (!isAncestorPackage(currentName, newPack)
          && !isPackageNameOkInRoot(newPack, getPackageFragmentRoot())) {
        String msg =
            Messages.format(
                RefactoringCoreMessages.RenamePackageProcessor_subpackage_collides,
                BasicElementLabels.getJavaElementName(newPack));
        return RefactoringStatus.createFatalErrorStatus(msg);
      }
    }
    return null;

  } else if (!isPackageNameOkInRoot(newName, getPackageFragmentRoot())) {
    return RefactoringStatus.createFatalErrorStatus(
        RefactoringCoreMessages.RenamePackageRefactoring_package_exists);
  } else {
    return null;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:40,代码来源:RenamePackageProcessor.java

示例6: doRename

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
@Override
protected void doRename(IProgressMonitor pm) throws CoreException {
  IPackageFragment pack = getPackage();
  if (pack == null) return;

  if (!fRenameSubpackages) {
    renamePackage(pack, pm, createNewPath(), getNewName());

  } else {
    IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(pack);
    Arrays.sort(
        allPackages,
        new Comparator<IPackageFragment>() {
          public int compare(IPackageFragment o1, IPackageFragment o2) {
            String p1 = o1.getElementName();
            String p2 = o2.getElementName();
            return p1.compareTo(p2);
          }
        });
    int count = allPackages.length;
    pm.beginTask("", count); // $NON-NLS-1$
    // When renaming to subpackage (a -> a.b), do it inside-out:
    boolean insideOut = getNewName().startsWith(getOldName());
    try {
      for (int i = 0; i < count; i++) {
        IPackageFragment currentPackage = allPackages[insideOut ? count - i - 1 : i];
        renamePackage(
            currentPackage,
            new SubProgressMonitor(pm, 1),
            createNewPath(currentPackage),
            getNewName(currentPackage));
      }
    } finally {
      pm.done();
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:38,代码来源:RenamePackageChange.java

示例7: checkPackageInCurrentRoot

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
private RefactoringStatus checkPackageInCurrentRoot(String newName) throws CoreException {
	if (fRenameSubpackages) {
		String currentName= getCurrentElementName();
		if (isAncestorPackage(currentName, newName)) {
			// renaming to subpackage (a -> a.b) is always OK, since all subpackages are also renamed
			return null;
		}
		if (! isAncestorPackage(newName, currentName)) {
			// renaming to an unrelated package
			if (! isPackageNameOkInRoot(newName, getPackageFragmentRoot())) {
				return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenamePackageRefactoring_package_exists);
			}
		}
		// renaming to superpackage (a.b -> a) or another package is OK iff
		// 'a.b' does not contain any subpackage that would collide with another subpackage of 'a'
		// (e.g. a.b.c collides if a.c already exists, but a.b.b does not collide with a.b)
		IPackageFragment[] packsToRename= JavaElementUtil.getPackageAndSubpackages(fPackage);
		for (int i = 0; i < packsToRename.length; i++) {
			IPackageFragment pack = packsToRename[i];
			String newPack= newName + pack.getElementName().substring(currentName.length());
			if (! isAncestorPackage(currentName, newPack) && ! isPackageNameOkInRoot(newPack, getPackageFragmentRoot())) {
				String msg= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_subpackage_collides, BasicElementLabels.getJavaElementName(newPack));
				return RefactoringStatus.createFatalErrorStatus(msg);
			}
		}
		return null;

	} else if (! isPackageNameOkInRoot(newName, getPackageFragmentRoot())) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.RenamePackageRefactoring_package_exists);
	} else {
		return null;
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:34,代码来源:RenamePackageProcessor.java

示例8: canRemoveCompletely

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
/**
 * Returns true if this initially selected package is really deletable
 * (if it has non-selected sub packages, it may only be cleared).
 * @param pack the package
 * @return  true if this initially selected package is really deletable
 * @throws JavaModelException
 */
private boolean canRemoveCompletely(IPackageFragment pack) throws JavaModelException {
	final IPackageFragment[] subPackages= JavaElementUtil.getPackageAndSubpackages(pack);
	for (int i= 0; i < subPackages.length; i++) {
		if (!(subPackages[i].equals(pack)) && !(fPackagesToDelete.contains(subPackages[i])))
			return false;
	}
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:DeleteModifications.java

示例9: canRemoveCompletely

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
/**
 * @param pack the package to delete
 * @param packagesToDelete all packages to delete
 * @return true if this initially selected package is really deletable
 * (if it has non-selected subpackages, it may only be cleared).
 * @throws JavaModelException should not happen
 */
private boolean canRemoveCompletely(IPackageFragment pack, List<IPackageFragment> packagesToDelete) throws JavaModelException {
	final IPackageFragment[] subPackages= JavaElementUtil.getPackageAndSubpackages(pack);
	for (int i= 0; i < subPackages.length; i++) {
		if (!subPackages[i].equals(pack) && !packagesToDelete.contains(subPackages[i]))
			return false;
	}
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:JavaDeleteProcessor.java

示例10: doRename

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
@Override
protected void doRename(IProgressMonitor pm) throws CoreException {
	IPackageFragment pack= getPackage();
	if (pack == null)
		return;

	if (!fRenameSubpackages) {
		renamePackage(pack, pm, createNewPath(), getNewName());

	} else {
		IPackageFragment[] allPackages= JavaElementUtil.getPackageAndSubpackages(pack);
		Arrays.sort(allPackages, new Comparator<IPackageFragment>() {
			public int compare(IPackageFragment o1, IPackageFragment o2) {
				String p1= o1.getElementName();
				String p2= o2.getElementName();
				return p1.compareTo(p2);
			}
		});
		int count= allPackages.length;
		pm.beginTask("", count); //$NON-NLS-1$
		// When renaming to subpackage (a -> a.b), do it inside-out:
		boolean insideOut= getNewName().startsWith(getOldName());
		try {
			for (int i= 0; i < count; i++) {
				IPackageFragment currentPackage= allPackages[insideOut ? count - i - 1 : i];
				renamePackage(currentPackage, new SubProgressMonitor(pm, 1), createNewPath(currentPackage), getNewName(currentPackage));
			}
		} finally {
			pm.done();
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:33,代码来源:RenamePackageChange.java

示例11: isValid

import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil; //导入方法依赖的package包/类
@Override
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
	pm.beginTask("", 2); //$NON-NLS-1$
	RefactoringStatus result;
	try {
		result= new RefactoringStatus();
		IJavaElement element= (IJavaElement) getModifiedElement();
		// don't check for read-only since we don't go through
		// validate edit.
		result.merge(super.isValid(new SubProgressMonitor(pm, 1)));
		if (result.hasFatalError())
			return result;
		if (element != null && element.exists() && element instanceof IPackageFragment) {
			IPackageFragment pack= (IPackageFragment) element;
			if (fRenameSubpackages) {
				IPackageFragment[] allPackages= JavaElementUtil.getPackageAndSubpackages(pack);
				SubProgressMonitor subPm= new SubProgressMonitor(pm, 1);
				subPm.beginTask("", allPackages.length); //$NON-NLS-1$
				for (int i= 0; i < allPackages.length; i++) {
					// don't check for read-only since we don't go through
					// validate edit.
					checkIfModifiable(result, allPackages[i].getResource(), VALIDATE_NOT_DIRTY);
					if (result.hasFatalError())
						return result;
					isValid(result, allPackages[i], new SubProgressMonitor(subPm, 1));
				}
			} else {
				isValid(result, pack, new SubProgressMonitor(pm, 1));
			}
		}
	} finally {
		pm.done();
	}
	return result;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:RenamePackageChange.java


注:本文中的org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil.getPackageAndSubpackages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。