List of usage examples for org.eclipse.jdt.internal.core PackageFragmentRoot fullInclusionPatternChars
public char[][] fullInclusionPatternChars()
From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java
License:Open Source License
/** * @see Openable/*from w w w .j a v a 2s .c o m*/ */ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, File underlyingResource) throws JavaModelException { // add compilation units/class files from resources HashSet vChildren = new HashSet(); int kind = getKind(); PackageFragmentRoot root = getPackageFragmentRoot(); char[][] inclusionPatterns = root.fullInclusionPatternChars(); char[][] exclusionPatterns = root.fullExclusionPatternChars(); File[] members = underlyingResource.listFiles(); { int length = members.length; if (length > 0) { IJavaProject project = getJavaProject(); String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); for (int i = 0; i < length; i++) { File child = members[i]; if (child.isFile() && !Util.isExcluded(new Path(child.getAbsolutePath()), inclusionPatterns, exclusionPatterns, false)) { IJavaElement childElement; if (kind == IPackageFragmentRoot.K_SOURCE && Util.isValidCompilationUnitName(child.getName(), sourceLevel, complianceLevel)) { childElement = new CompilationUnit(this, manager, child.getName(), DefaultWorkingCopyOwner.PRIMARY); vChildren.add(childElement); } else if (kind == IPackageFragmentRoot.K_BINARY && Util.isValidClassFileName(child.getName(), sourceLevel, complianceLevel)) { childElement = getClassFile(child.getName()); vChildren.add(childElement); } } } } } if (kind == IPackageFragmentRoot.K_SOURCE) { // add primary compilation units ICompilationUnit[] primaryCompilationUnits = getCompilationUnits(DefaultWorkingCopyOwner.PRIMARY); for (int i = 0, length = primaryCompilationUnits.length; i < length; i++) { ICompilationUnit primary = primaryCompilationUnits[i]; vChildren.add(primary); } } IJavaElement[] children = new IJavaElement[vChildren.size()]; vChildren.toArray(children); info.setChildren(children); return true; }
From source file:org.eclipse.jdt.internal.core.CopyResourceElementsOperation.java
License:Open Source License
/** * Creates any destination package fragment(s) which do not exists yet. * Return true if a read-only package fragment has been found among package fragments, false otherwise *///from w ww.j a va 2 s. c o m private boolean createNeededPackageFragments(IContainer sourceFolder, PackageFragmentRoot root, String[] newFragName, boolean moveFolder) throws JavaModelException { boolean containsReadOnlyPackageFragment = false; IContainer parentFolder = (IContainer) root.resource(); JavaElementDelta projectDelta = null; String[] sideEffectPackageName = null; char[][] inclusionPatterns = root.fullInclusionPatternChars(); char[][] exclusionPatterns = root.fullExclusionPatternChars(); for (int i = 0; i < newFragName.length; i++) { String subFolderName = newFragName[i]; sideEffectPackageName = Util.arrayConcat(sideEffectPackageName, subFolderName); IResource subFolder = parentFolder.findMember(subFolderName); if (subFolder == null) { // create deepest folder only if not a move (folder will be moved in processPackageFragmentResource) if (!(moveFolder && i == newFragName.length - 1)) { createFolder(parentFolder, subFolderName, this.force); } parentFolder = parentFolder.getFolder(new Path(subFolderName)); sourceFolder = sourceFolder.getFolder(new Path(subFolderName)); if (Util.isReadOnly(sourceFolder)) { containsReadOnlyPackageFragment = true; } IPackageFragment sideEffectPackage = root.getPackageFragment(sideEffectPackageName); if (i < newFragName.length - 1 // all but the last one are side effect packages && !Util.isExcluded(parentFolder, inclusionPatterns, exclusionPatterns)) { if (projectDelta == null) { projectDelta = getDeltaFor(root.getJavaProject()); } projectDelta.added(sideEffectPackage); } this.createdElements.add(sideEffectPackage); } else { parentFolder = (IContainer) subFolder; } } return containsReadOnlyPackageFragment; }
From source file:org.eclipse.jdt.internal.core.CopyResourceElementsOperation.java
License:Open Source License
/** * Copies/moves a package fragment with the name <code>newName</code> * to the destination package.<br> * * @exception JavaModelException if the operation is unable to * complete//from ww w . jav a 2s . c o m */ private void processPackageFragmentResource(PackageFragment source, PackageFragmentRoot root, String newName) throws JavaModelException { try { String[] newFragName = (newName == null) ? source.names : Util.getTrimmedSimpleNames(newName); PackageFragment newFrag = root.getPackageFragment(newFragName); IResource[] resources = collectResourcesOfInterest(source); // if isMove() can we move the folder itself ? (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=22458) boolean shouldMoveFolder = isMove() && !newFrag.resource().exists(); // if new pkg fragment exists, it is an override IFolder srcFolder = (IFolder) source.resource(); IPath destPath = newFrag.getPath(); if (shouldMoveFolder) { // check if destination is not included in source if (srcFolder.getFullPath().isPrefixOf(destPath)) { shouldMoveFolder = false; } else { // check if there are no sub-packages IResource[] members = srcFolder.members(); for (int i = 0; i < members.length; i++) { if (members[i] instanceof IFolder) { shouldMoveFolder = false; break; } } } } boolean containsReadOnlySubPackageFragments = createNeededPackageFragments( (IContainer) source.parent.resource(), root, newFragName, shouldMoveFolder); boolean sourceIsReadOnly = Util.isReadOnly(srcFolder); // Process resources if (shouldMoveFolder) { // move underlying resource // TODO Revisit once bug 43044 is fixed if (sourceIsReadOnly) { Util.setReadOnly(srcFolder, false); } srcFolder.move(destPath, this.force, true /* keep history */, getSubProgressMonitor(1)); if (sourceIsReadOnly) { Util.setReadOnly(srcFolder, true); } setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE); } else { // process the leaf resources if (resources.length > 0) { if (isRename()) { if (!destPath.equals(source.getPath())) { moveResources(resources, destPath); } } else if (isMove()) { // we need to delete this resource if this operation wants to override existing resources for (int i = 0, max = resources.length; i < max; i++) { IResource destinationResource = ResourcesPlugin.getWorkspace().getRoot() .findMember(destPath.append(resources[i].getName())); if (destinationResource != null) { if (this.force) { deleteResource(destinationResource, IResource.KEEP_HISTORY); } else { throw new JavaModelException( new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.status_nameCollision, destinationResource.getFullPath().toString()))); } } } moveResources(resources, destPath); } else { // we need to delete this resource if this operation wants to override existing resources for (int i = 0, max = resources.length; i < max; i++) { IResource destinationResource = ResourcesPlugin.getWorkspace().getRoot() .findMember(destPath.append(resources[i].getName())); if (destinationResource != null) { if (this.force) { // we need to delete this resource if this operation wants to override existing resources deleteResource(destinationResource, IResource.KEEP_HISTORY); } else { throw new JavaModelException( new JavaModelStatus(IJavaModelStatusConstants.NAME_COLLISION, Messages.bind(Messages.status_nameCollision, destinationResource.getFullPath().toString()))); } } } copyResources(resources, destPath); } } } // Update package statement in compilation unit if needed if (!Util.equalArraysOrNull(newFragName, source.names)) { // if package has been renamed, update the compilation units char[][] inclusionPatterns = root.fullInclusionPatternChars(); char[][] exclusionPatterns = root.fullExclusionPatternChars(); for (int i = 0; i < resources.length; i++) { String resourceName = resources[i].getName(); if (Util.isJavaLikeFileName(resourceName)) { // we only consider potential compilation units ICompilationUnit cu = newFrag.getCompilationUnit(resourceName); if (Util.isExcluded(cu.getPath(), inclusionPatterns, exclusionPatterns, false/*not a folder*/)) continue; this.parser.setSource(cu); CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor); AST ast = astCU.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); updatePackageStatement(astCU, newFragName, rewrite, cu); TextEdit edits = rewrite.rewriteAST(); applyTextEdit(cu, edits); cu.save(null, false); } } } // Discard empty old package (if still empty after the rename) boolean isEmpty = true; if (isMove()) { // delete remaining files in this package (.class file in the case where Proj=src=bin) // in case of a copy updateReadOnlyPackageFragmentsForMove((IContainer) source.parent.resource(), root, newFragName, sourceIsReadOnly); if (srcFolder.exists()) { IResource[] remaining = srcFolder.members(); for (int i = 0, length = remaining.length; i < length; i++) { IResource file = remaining[i]; if (file instanceof IFile) { if (Util.isReadOnly(file)) { Util.setReadOnly(file, false); } deleteResource(file, IResource.FORCE | IResource.KEEP_HISTORY); } else { isEmpty = false; } } } if (isEmpty) { IResource rootResource; // check if source is included in destination if (destPath.isPrefixOf(srcFolder.getFullPath())) { rootResource = newFrag.resource(); } else { rootResource = source.parent.resource(); } // delete recursively empty folders deleteEmptyPackageFragment(source, false, rootResource); } } else if (containsReadOnlySubPackageFragments) { // in case of a copy updateReadOnlyPackageFragmentsForCopy((IContainer) source.parent.resource(), root, newFragName); } // workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=24505 if (isEmpty && isMove() && !(Util.isExcluded(source) || Util.isExcluded(newFrag))) { IJavaProject sourceProject = source.getJavaProject(); getDeltaFor(sourceProject).movedFrom(source, newFrag); IJavaProject destProject = newFrag.getJavaProject(); getDeltaFor(destProject).movedTo(newFrag, source); } } catch (JavaModelException e) { throw e; } catch (CoreException ce) { throw new JavaModelException(ce); } }
From source file:org.eclipse.jdt.internal.core.PackageFragment.java
License:Open Source License
/** * @see Openable/*from www .j a v a 2 s . c o m*/ */ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { // add compilation units/class files from resources HashSet vChildren = new HashSet(); int kind = getKind(); try { PackageFragmentRoot root = getPackageFragmentRoot(); char[][] inclusionPatterns = root.fullInclusionPatternChars(); char[][] exclusionPatterns = root.fullExclusionPatternChars(); IResource[] members = ((IContainer) underlyingResource).members(); int length = members.length; if (length > 0) { IJavaProject project = getJavaProject(); String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); for (int i = 0; i < length; i++) { IResource child = members[i]; if (child.getType() != IResource.FOLDER && !Util.isExcluded(child, inclusionPatterns, exclusionPatterns)) { IJavaElement childElement; if (kind == IPackageFragmentRoot.K_SOURCE && Util.isValidCompilationUnitName(child.getName(), sourceLevel, complianceLevel)) { // GROOVY start /* old { childElement = new CompilationUnit(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY); } new */ childElement = LanguageSupportFactory.newCompilationUnit(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY); // GROOVY end vChildren.add(childElement); } else if (kind == IPackageFragmentRoot.K_BINARY && Util.isValidClassFileName(child.getName(), sourceLevel, complianceLevel)) { childElement = getClassFile(child.getName()); vChildren.add(childElement); } } } } } catch (CoreException e) { throw new JavaModelException(e); } if (kind == IPackageFragmentRoot.K_SOURCE) { // add primary compilation units ICompilationUnit[] primaryCompilationUnits = getCompilationUnits(DefaultWorkingCopyOwner.PRIMARY); for (int i = 0, length = primaryCompilationUnits.length; i < length; i++) { ICompilationUnit primary = primaryCompilationUnits[i]; vChildren.add(primary); } } IJavaElement[] children = new IJavaElement[vChildren.size()]; vChildren.toArray(children); info.setChildren(children); return true; }
From source file:org.eclipse.jdt.internal.core.PackageFragmentRootInfo.java
License:Open Source License
/** * Compute the non-package resources of this package fragment root. *//*from ww w . j a v a2 s .c o m*/ private Object[] computeNonJavaResources(IResource underlyingResource, PackageFragmentRoot handle) { Object[] resources = NO_NON_JAVA_RESOURCES; try { // the underlying resource may be a folder or a project (in the case that the project folder // is actually the package fragment root) if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) { resources = computeFolderNonJavaResources(handle, (IContainer) underlyingResource, handle.fullInclusionPatternChars(), handle.fullExclusionPatternChars()); } } catch (JavaModelException e) { // ignore } return resources; }