Example usage for org.eclipse.jdt.internal.core.util Util equalArraysOrNull

List of usage examples for org.eclipse.jdt.internal.core.util Util equalArraysOrNull

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core.util Util equalArraysOrNull.

Prototype

public static boolean equalArraysOrNull(Object[] a, Object[] b) 

Source Link

Document

Compares two arrays using equals() on the elements.

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.MemberValuePair.java

License:Open Source License

public boolean equals(Object obj) {
    if (!(obj instanceof MemberValuePair)) {
        return false;
    }//from w  w w .j  a va 2 s  .  c  om
    MemberValuePair other = (MemberValuePair) obj;
    return this.valueKind == other.valueKind && this.memberName.equals(other.memberName)
            && (this.value == other.value || (this.value != null && this.value.equals(other.value))
                    || (this.value instanceof Object[] && other.value instanceof Object[]
                            && Util.equalArraysOrNull((Object[]) this.value, (Object[]) other.value)));
}

From source file:com.codenvy.ide.ext.java.server.internal.core.SourceMethod.java

License:Open Source License

public boolean equals(Object o) {
    if (!(o instanceof SourceMethod))
        return false;
    return super.equals(o) && Util.equalArraysOrNull(this.parameterTypes, ((SourceMethod) o).parameterTypes);
}

From source file:org.eclipse.ajdt.core.javaelements.AspectJMemberElement.java

License:Open Source License

public boolean equals(Object o) {
    if (!(o instanceof AspectJMemberElement))
        return false;
    return super.equals(o)
            && Util.equalArraysOrNull(fParameterTypes, ((AspectJMemberElement) o).fParameterTypes);
}

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 . j  a  v  a2s  .  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.CopyResourceElementsOperation.java

License:Open Source License

/**
 * Updates the content of <code>cu</code>, modifying the type name and/or package
 * declaration as necessary./*from ww  w  .  ja v  a2 s  .com*/
 *
 * @return an AST rewrite or null if no rewrite needed
 */
private TextEdit updateContent(ICompilationUnit cu, PackageFragment dest, String newName)
        throws JavaModelException {
    String[] currPackageName = ((PackageFragment) cu.getParent()).names;
    String[] destPackageName = dest.names;
    if (Util.equalArraysOrNull(currPackageName, destPackageName) && newName == null) {
        return null; //nothing to change
    } else {
        // ensure cu is consistent (noop if already consistent)
        cu.makeConsistent(this.progressMonitor);

        // GROOVY start
        // don't use the ASTParser if not a Java compilation unit
        if (LanguageSupportFactory.isInterestingSourceFile(cu.getElementName())) {
            return updateNonJavaContent(cu, destPackageName, currPackageName, newName);
        }
        // GROOVY end

        this.parser.setSource(cu);
        CompilationUnit astCU = (CompilationUnit) this.parser.createAST(this.progressMonitor);
        AST ast = astCU.getAST();
        ASTRewrite rewrite = ASTRewrite.create(ast);
        updateTypeName(cu, astCU, cu.getElementName(), newName, rewrite);
        updatePackageStatement(astCU, destPackageName, rewrite, cu);
        return rewrite.rewriteAST();
    }
}

From source file:org.eclipse.jdt.internal.core.CopyResourceElementsOperation.java

License:Open Source License

private TextEdit updateNonJavaContent(ICompilationUnit cu, String[] destPackageName, String[] currPackageName,
        String newName) throws JavaModelException {
    // package statement
    IPackageDeclaration[] packageDecls = cu.getPackageDeclarations();
    boolean doPackage = !Util.equalArraysOrNull(currPackageName, destPackageName);
    boolean doName = newName != null;
    MultiTextEdit multiEdit = new MultiTextEdit();
    if (doPackage) {
        if (packageDecls.length == 1) {
            ISourceRange packageRange = packageDecls[0].getSourceRange();
            if (destPackageName == null || destPackageName.length == 0) {
                // move to default package
                multiEdit.addChild(new DeleteEdit(packageRange.getOffset(), packageRange.getLength()));
            } else {
                multiEdit.addChild(new ReplaceEdit(packageRange.getOffset(), packageRange.getLength(),
                        "package " + Util.concatWith(destPackageName, '.'))); //$NON-NLS-1$
            }/*from w  ww .ja va  2 s  . c  o  m*/
        } else {
            // move from default package
            // we don't keep track of comments, so we don't know where they start.  Just add the package declaration at location 0
            multiEdit.addChild(new InsertEdit(0, "package " + Util.concatWith(destPackageName, '.') + "\n")); //$NON-NLS-1$//$NON-NLS-2$
        }
    }

    if (doName) {
        int dotIndex = cu.getElementName().indexOf('.');
        dotIndex = dotIndex == -1 ? cu.getElementName().length() : dotIndex;
        String oldTypeName = cu.getElementName().substring(0, dotIndex);
        dotIndex = newName.indexOf('.');
        dotIndex = dotIndex == -1 ? newName.length() : dotIndex;
        String newTypeName = newName.substring(0, dotIndex);
        IType type = cu.getType(oldTypeName);
        if (type.exists()) {
            ISourceRange nameRange = type.getNameRange();
            // main type can be implicitly defined, so check offsets
            if (nameRange.getOffset() > 0 && nameRange.getLength() > 0
                    && oldTypeName.length() == nameRange.getLength()) {
                multiEdit.addChild(new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), newTypeName));
            }
            IJavaElement[] children = type.getChildren();
            for (int i = 0; i < children.length; i++) {
                if (children[i].getElementType() == IJavaElement.METHOD) {
                    IMethod method = (IMethod) children[i];
                    if (method.isConstructor()) {
                        nameRange = method.getNameRange();
                        // main type can be implicitly defined, so check offsets
                        if (nameRange.getOffset() > 0 && nameRange.getLength() > 0) {
                            multiEdit.addChild(
                                    new ReplaceEdit(nameRange.getOffset(), nameRange.getLength(), newTypeName));
                        }
                    }
                }
            }
        }
    }
    return multiEdit;
}

From source file:org.eclipse.jdt.internal.core.PackageFragment.java

License:Open Source License

public boolean equals(Object o) {
    if (this == o)
        return true;
    if (!(o instanceof PackageFragment))
        return false;

    PackageFragment other = (PackageFragment) o;
    return Util.equalArraysOrNull(this.names, other.names) && this.parent.equals(other.parent);
}

From source file:org.eclipse.objectteams.otdt.internal.core.MethodMapping.java

License:Open Source License

private boolean isEqualMethod(IMethodSpec baseMethodHandle, IMethod foundMethodOrCallout,
        String foundSelector) {// ww  w.  j a  v a 2 s .  c om
    if (!foundSelector.equals(baseMethodHandle.getSelector()))
        return false;
    if (!baseMethodHandle.hasSignature())
        return true;
    return Util.equalArraysOrNull(foundMethodOrCallout.getParameterTypes(),
            baseMethodHandle.getArgumentTypes());
}

From source file:org.eclipse.objectteams.otdt.internal.core.SourceMethodMappingInfo.java

License:Open Source License

public boolean signaturesEqual(SourceMethodMappingInfo other) {
    if (!Util.equalArraysOrNull(this.roleParameterNames, other.roleParameterNames))
        return false;
    if (this.nBaseMethods != other.nBaseMethods)
        return false;
    for (int i = 0; i < this.nBaseMethods; i++) {
        if (!Util.equalArraysOrNull(this.baseParameterNames[i], other.baseParameterNames[i]))
            return false;
        if (!Util.equalArraysOrNull(this.baseParameterTypes[i], other.baseParameterTypes[i]))
            return false;
        if (!this.baseReturnTypes[i].equals(other.baseReturnTypes[i]))
            return false;
    }//from  w ww . j a v a2s.  c om
    return true;
}