Example usage for org.eclipse.jdt.core.compiler CharOperation equals

List of usage examples for org.eclipse.jdt.core.compiler CharOperation equals

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.compiler CharOperation equals.

Prototype

public static final boolean equals(char[] first, char[] second) 

Source Link

Document

Answers true if the two arrays are identical character by character, otherwise false.

Usage

From source file:com.android.tools.lint.psi.EcjPsiBuilder.java

License:Apache License

@NonNull
EcjPsiJavaFile toFile(@NonNull CompilationUnitDeclaration node, EcjSourceFile source) {
    EcjPsiJavaFile unit = new EcjPsiJavaFile(mManager, source, node);

    if (node.currentPackage != null) {
        EcjPsiPackageStatement packageStatement = toPackageStatement(unit, node.currentPackage);
        unit.setPackageStatement(packageStatement);
    }/*  www.  j ava  2  s.c  o  m*/

    EcjPsiImportList importList = toImportList(unit, node.imports);
    unit.setImportList(importList);

    TypeDeclaration[] newTypes;
    if (node.types != null && node.types.length > 0 && CharOperation.equals(PACKAGE_INFO, node.types[0].name)) {
        newTypes = new TypeDeclaration[node.types.length - 1];
        System.arraycopy(node.types, 1, newTypes, 0, node.types.length - 1);
    } else {
        newTypes = node.types;
    }

    List<EcjPsiClass> classes = Lists.newArrayList();
    if (newTypes != null) {
        for (TypeDeclaration declaration : newTypes) {
            EcjPsiClass toClass = toClass(unit, declaration);
            classes.add(toClass);
        }
    }
    unit.setClasses(classes.toArray(new PsiClass[classes.size()]));

    return unit;
}

From source file:com.codenvy.ide.ext.java.emul.clasfmt.AnnotationInfo.java

License:Open Source License

private int readRetentionPolicy(int offset) {
    int currentOffset = offset;
    int tag = u1At(currentOffset);
    currentOffset++;/*from   ww w. j a  v  a 2 s. co m*/
    switch (tag) {
    case 'e':
        int utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset;
        char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
        currentOffset += 2;
        if (typeName.length == 38
                && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTIONPOLICY)) {
            utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset;
            char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
            this.standardAnnotationTagBits |= Annotation.getRetentionPolicy(constName);
        }
        currentOffset += 2;
        break;
    case 'B':
    case 'C':
    case 'D':
    case 'F':
    case 'I':
    case 'J':
    case 'S':
    case 'Z':
    case 's':
    case 'c':
        currentOffset += 2;
        break;
    case '@':
        // none of the supported standard annotation are in the nested
        // level.
        currentOffset = scanAnnotation(currentOffset, false, false);
        break;
    case '[':
        int numberOfValues = u2At(currentOffset);
        currentOffset += 2;
        for (int i = 0; i < numberOfValues; i++)
            currentOffset = scanElementValue(currentOffset);
        break;
    default:
        throw new IllegalStateException();
    }
    return currentOffset;
}

From source file:com.codenvy.ide.ext.java.emul.clasfmt.AnnotationInfo.java

License:Open Source License

private int readTargetValue(int offset) {
    int currentOffset = offset;
    int tag = u1At(currentOffset);
    currentOffset++;/*from  ww w .  j  a va  2s .co m*/
    switch (tag) {
    case 'e':
        int utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset;
        char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
        currentOffset += 2;
        if (typeName.length == 34
                && CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_ELEMENTTYPE)) {
            utf8Offset = this.constantPoolOffsets[u2At(currentOffset)] - this.structOffset;
            char[] constName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
            this.standardAnnotationTagBits |= Annotation.getTargetElementType(constName);
        }
        currentOffset += 2;
        break;
    case 'B':
    case 'C':
    case 'D':
    case 'F':
    case 'I':
    case 'J':
    case 'S':
    case 'Z':
    case 's':
    case 'c':
        currentOffset += 2;
        break;
    case '@':
        // none of the supported standard annotation are in the nested
        // level.
        currentOffset = scanAnnotation(currentOffset, false, false);
        break;
    case '[':
        int numberOfValues = u2At(currentOffset);
        currentOffset += 2;
        if (numberOfValues == 0) {
            this.standardAnnotationTagBits |= TagBits.AnnotationTarget;
        } else {
            for (int i = 0; i < numberOfValues; i++)
                currentOffset = readTargetValue(currentOffset);
        }
        break;
    default:
        throw new IllegalStateException();
    }
    return currentOffset;
}

From source file:com.codenvy.ide.ext.java.emul.clasfmt.AnnotationInfo.java

License:Open Source License

/**
 * Read through this annotation in order to figure out the necessary tag
 * bits and the length of this annotation. The data structure will not be
 * flushed out.//from   w w  w  .j  a  v  a2 s. co m
 * <p/>
 * The tag bits are derived from the following (supported) standard
 * annotation. java.lang.annotation.Documented,
 * java.lang.annotation.Retention, java.lang.annotation.Target, and
 * java.lang.Deprecated
 *
 * @param expectRuntimeVisibleAnno
 *         <code>true</cod> to indicate that this is a runtime-visible annotation
 * @param toplevel
 *         <code>false</code> to indicate that an nested annotation is read.
 *         <code>true</code> otherwise
 * @return the next offset to read.
 */
private int scanAnnotation(int offset, boolean expectRuntimeVisibleAnno, boolean toplevel) {
    int currentOffset = offset;
    int utf8Offset = this.constantPoolOffsets[u2At(offset)] - this.structOffset;
    char[] typeName = utf8At(utf8Offset + 3, u2At(utf8Offset + 1));
    if (toplevel)
        this.typename = typeName;
    int numberOfPairs = u2At(offset + 2);
    // u2 type_index + u2 number_member_value_pair
    currentOffset += 4;
    if (expectRuntimeVisibleAnno && toplevel) {
        switch (typeName.length) {
        case 22:
            if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_DEPRECATED)) {
                this.standardAnnotationTagBits |= TagBits.AnnotationDeprecated;
                return currentOffset;
            }
            break;
        case 23:
            if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_SAFEVARARGS)) {
                this.standardAnnotationTagBits |= TagBits.AnnotationSafeVarargs;
                return currentOffset;
            }
            break;
        case 29:
            if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_TARGET)) {
                currentOffset += 2;
                return readTargetValue(currentOffset);
            }
            break;
        case 32:
            if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_RETENTION)) {
                currentOffset += 2;
                return readRetentionPolicy(currentOffset);
            }
            if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_INHERITED)) {
                this.standardAnnotationTagBits |= TagBits.AnnotationInherited;
                return currentOffset;
            }
            break;
        case 33:
            if (CharOperation.equals(typeName, ConstantPool.JAVA_LANG_ANNOTATION_DOCUMENTED)) {
                this.standardAnnotationTagBits |= TagBits.AnnotationDocumented;
                return currentOffset;
            }
            break;
        case 52:
            if (CharOperation.equals(typeName,
                    ConstantPool.JAVA_LANG_INVOKE_METHODHANDLE_POLYMORPHICSIGNATURE)) {
                this.standardAnnotationTagBits |= TagBits.AnnotationPolymorphicSignature;
                return currentOffset;
            }
            break;
        }
    }
    for (int i = 0; i < numberOfPairs; i++) {
        // u2 member_name_index
        currentOffset += 2;
        currentOffset = scanElementValue(currentOffset);
    }
    return currentOffset;
}

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java

License:Open Source License

protected boolean mustQualifyType(char[] packageName, char[] typeName, char[] enclosingTypeNames,
        int modifiers) {

    // If there are no types defined into the current CU yet.
    if (this.unitScope == null)
        return true;

    if (!this.importCachesInitialized) {
        initializeImportCaches();//  w  ww . j ava 2 s .  co m
    }

    for (int i = 0; i < this.importCacheCount; i++) {
        char[][] importName = this.importsCache[i];
        if (CharOperation.equals(typeName, importName[0])) {
            char[] fullyQualifiedTypeName = enclosingTypeNames == null || enclosingTypeNames.length == 0
                    ? CharOperation.concat(packageName, typeName, '.')
                    : CharOperation.concat(CharOperation.concat(packageName, enclosingTypeNames, '.'), typeName,
                            '.');
            return !CharOperation.equals(fullyQualifiedTypeName, importName[1]);
        }
    }

    if ((enclosingTypeNames == null || enclosingTypeNames.length == 0)
            && CharOperation.equals(this.currentPackageName, packageName))
        return false;

    char[] fullyQualifiedEnclosingTypeName = null;

    for (int i = 0; i < this.onDemandImportCacheCount; i++) {
        ImportBinding importBinding = this.onDemandImportsCache[i];
        Binding resolvedImport = importBinding.resolvedImport;

        char[][] importName = importBinding.compoundName;
        char[] importFlatName = CharOperation.concatWith(importName, '.');

        boolean isFound = false;
        // resolvedImport is a ReferenceBindng or a PackageBinding
        if (resolvedImport instanceof ReferenceBinding) {
            if (enclosingTypeNames != null && enclosingTypeNames.length != 0) {
                if (fullyQualifiedEnclosingTypeName == null) {
                    fullyQualifiedEnclosingTypeName = CharOperation.concat(packageName, enclosingTypeNames,
                            '.');
                }
                if (CharOperation.equals(fullyQualifiedEnclosingTypeName, importFlatName)) {
                    if (importBinding.isStatic()) {
                        isFound = (modifiers & ClassFileConstants.AccStatic) != 0;
                    } else {
                        isFound = true;
                    }
                }
            }
        } else {
            if (enclosingTypeNames == null || enclosingTypeNames.length == 0) {
                if (CharOperation.equals(packageName, importFlatName)) {
                    if (importBinding.isStatic()) {
                        isFound = (modifiers & ClassFileConstants.AccStatic) != 0;
                    } else {
                        isFound = true;
                    }
                }
            }
        }

        // find potential conflict with another import
        if (isFound) {
            for (int j = 0; j < this.onDemandImportCacheCount; j++) {
                if (i != j) {
                    ImportBinding conflictingImportBinding = this.onDemandImportsCache[j];
                    if (conflictingImportBinding.resolvedImport instanceof ReferenceBinding) {
                        ReferenceBinding refBinding = (ReferenceBinding) conflictingImportBinding.resolvedImport;
                        if (refBinding.getMemberType(typeName) != null) {
                            return true;
                        }
                    } else {
                        char[] conflictingImportName = CharOperation
                                .concatWith(conflictingImportBinding.compoundName, '.');

                        if (this.nameEnvironment.nameLookup.findType(String.valueOf(typeName),
                                String.valueOf(conflictingImportName), false, NameLookup.ACCEPT_ALL,
                                false/*don't check restrictions*/) != null) {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    }
    return true;
}

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java

License:Open Source License

public void acceptType(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, int modifiers,
        AccessRestriction accessRestriction) {
    char[] typeName = enclosingTypeNames == null ? simpleTypeName
            : CharOperation.concat(CharOperation.concatWith(enclosingTypeNames, '.'), simpleTypeName, '.');

    if (CharOperation.equals(simpleTypeName, this.selectedIdentifier)) {
        char[] flatEnclosingTypeNames = enclosingTypeNames == null || enclosingTypeNames.length == 0 ? null
                : CharOperation.concatWith(enclosingTypeNames, '.');
        if (mustQualifyType(packageName, simpleTypeName, flatEnclosingTypeNames, modifiers)) {
            int length = 0;
            int kind = modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccEnum
                    | ClassFileConstants.AccAnnotation);
            switch (kind) {
            case ClassFileConstants.AccAnnotation:
            case ClassFileConstants.AccAnnotation | ClassFileConstants.AccInterface:
                char[][] acceptedAnnotation = new char[2][];
                acceptedAnnotation[0] = packageName;
                acceptedAnnotation[1] = typeName;

                if (this.acceptedAnnotations == null) {
                    this.acceptedAnnotations = new char[10][][];
                    this.acceptedAnnotationsModifiers = new int[10];
                    this.acceptedAnnotationsCount = 0;
                }/*from w  ww  .ja v a2 s .c om*/
                length = this.acceptedAnnotations.length;
                if (length == this.acceptedAnnotationsCount) {
                    int newLength = (length + 1) * 2;
                    System.arraycopy(this.acceptedAnnotations, 0,
                            this.acceptedAnnotations = new char[newLength][][], 0, length);
                    System.arraycopy(this.acceptedAnnotationsModifiers, 0,
                            this.acceptedAnnotationsModifiers = new int[newLength], 0, length);
                }
                this.acceptedAnnotationsModifiers[this.acceptedAnnotationsCount] = modifiers;
                this.acceptedAnnotations[this.acceptedAnnotationsCount++] = acceptedAnnotation;
                break;
            case ClassFileConstants.AccEnum:
                char[][] acceptedEnum = new char[2][];
                acceptedEnum[0] = packageName;
                acceptedEnum[1] = typeName;

                if (this.acceptedEnums == null) {
                    this.acceptedEnums = new char[10][][];
                    this.acceptedEnumsModifiers = new int[10];
                    this.acceptedEnumsCount = 0;
                }
                length = this.acceptedEnums.length;
                if (length == this.acceptedEnumsCount) {
                    int newLength = (length + 1) * 2;
                    System.arraycopy(this.acceptedEnums, 0, this.acceptedEnums = new char[newLength][][], 0,
                            length);
                    System.arraycopy(this.acceptedEnumsModifiers, 0,
                            this.acceptedEnumsModifiers = new int[newLength], 0, length);
                }
                this.acceptedEnumsModifiers[this.acceptedEnumsCount] = modifiers;
                this.acceptedEnums[this.acceptedEnumsCount++] = acceptedEnum;
                break;
            case ClassFileConstants.AccInterface:
                char[][] acceptedInterface = new char[2][];
                acceptedInterface[0] = packageName;
                acceptedInterface[1] = typeName;

                if (this.acceptedInterfaces == null) {
                    this.acceptedInterfaces = new char[10][][];
                    this.acceptedInterfacesModifiers = new int[10];
                    this.acceptedInterfacesCount = 0;
                }
                length = this.acceptedInterfaces.length;
                if (length == this.acceptedInterfacesCount) {
                    int newLength = (length + 1) * 2;
                    System.arraycopy(this.acceptedInterfaces, 0,
                            this.acceptedInterfaces = new char[newLength][][], 0, length);
                    System.arraycopy(this.acceptedInterfacesModifiers, 0,
                            this.acceptedInterfacesModifiers = new int[newLength], 0, length);
                }
                this.acceptedInterfacesModifiers[this.acceptedInterfacesCount] = modifiers;
                this.acceptedInterfaces[this.acceptedInterfacesCount++] = acceptedInterface;
                break;
            default:
                char[][] acceptedClass = new char[2][];
                acceptedClass[0] = packageName;
                acceptedClass[1] = typeName;

                if (this.acceptedClasses == null) {
                    this.acceptedClasses = new char[10][][];
                    this.acceptedClassesModifiers = new int[10];
                    this.acceptedClassesCount = 0;
                }
                length = this.acceptedClasses.length;
                if (length == this.acceptedClassesCount) {
                    int newLength = (length + 1) * 2;
                    System.arraycopy(this.acceptedClasses, 0, this.acceptedClasses = new char[newLength][][], 0,
                            length);
                    System.arraycopy(this.acceptedClassesModifiers, 0,
                            this.acceptedClassesModifiers = new int[newLength], 0, length);
                }
                this.acceptedClassesModifiers[this.acceptedClassesCount] = modifiers;
                this.acceptedClasses[this.acceptedClassesCount++] = acceptedClass;
                break;
            }
        } else {
            this.noProposal = false;
            this.requestor.acceptType(packageName, typeName, modifiers, false, null, this.actualSelectionStart,
                    this.actualSelectionEnd);
            this.acceptedAnswer = true;
        }
    }
}

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

License:Open Source License

private boolean equals(char[][][] first, char[][][] second) {
    if (first == second)
        return true;
    if (first == null || second == null)
        return false;
    if (first.length != second.length)
        return false;

    for (int i = first.length; --i >= 0;)
        if (!CharOperation.equals(first[i], second[i]))
            return false;
    return true;/*from w  w w  .ja v a 2 s .com*/
}

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

License:Open Source License

/**
 * The elements are equivalent, but might have content changes.
 *///from w  ww.j a  v a2 s. co  m
private void findContentChange(JavaElementInfo oldInfo, JavaElementInfo newInfo, IJavaElement newElement) {
    if (oldInfo instanceof MemberElementInfo && newInfo instanceof MemberElementInfo) {
        if (((MemberElementInfo) oldInfo).getModifiers() != ((MemberElementInfo) newInfo).getModifiers()) {
            this.delta.changed(newElement, IJavaElementDelta.F_MODIFIERS);
        }
        if (oldInfo instanceof AnnotatableInfo && newInfo instanceof AnnotatableInfo) {
            findAnnotationChanges(((AnnotatableInfo) oldInfo).annotations,
                    ((AnnotatableInfo) newInfo).annotations, newElement);
        }
        if (oldInfo instanceof SourceMethodElementInfo && newInfo instanceof SourceMethodElementInfo) {
            SourceMethodElementInfo oldSourceMethodInfo = (SourceMethodElementInfo) oldInfo;
            SourceMethodElementInfo newSourceMethodInfo = (SourceMethodElementInfo) newInfo;
            if (!CharOperation.equals(oldSourceMethodInfo.getReturnTypeName(),
                    newSourceMethodInfo.getReturnTypeName())
                    || !CharOperation.equals(oldSourceMethodInfo.getTypeParameterNames(),
                            newSourceMethodInfo.getTypeParameterNames())
                    || !equals(oldSourceMethodInfo.getTypeParameterBounds(),
                            newSourceMethodInfo.getTypeParameterBounds())) {
                this.delta.changed(newElement, IJavaElementDelta.F_CONTENT);
            }
        } else if (oldInfo instanceof SourceFieldElementInfo && newInfo instanceof SourceFieldElementInfo) {
            if (!CharOperation.equals(((SourceFieldElementInfo) oldInfo).getTypeName(),
                    ((SourceFieldElementInfo) newInfo).getTypeName())) {
                this.delta.changed(newElement, IJavaElementDelta.F_CONTENT);
            }
        } else if (oldInfo instanceof SourceTypeElementInfo && newInfo instanceof SourceTypeElementInfo) {
            SourceTypeElementInfo oldSourceTypeInfo = (SourceTypeElementInfo) oldInfo;
            SourceTypeElementInfo newSourceTypeInfo = (SourceTypeElementInfo) newInfo;
            if (!CharOperation.equals(oldSourceTypeInfo.getSuperclassName(),
                    newSourceTypeInfo.getSuperclassName())
                    || !CharOperation.equals(oldSourceTypeInfo.getInterfaceNames(),
                            newSourceTypeInfo.getInterfaceNames())) {
                this.delta.changed(newElement, IJavaElementDelta.F_SUPER_TYPES);
            }
            if (!CharOperation.equals(oldSourceTypeInfo.getTypeParameterNames(),
                    newSourceTypeInfo.getTypeParameterNames())
                    || !equals(oldSourceTypeInfo.getTypeParameterBounds(),
                            newSourceTypeInfo.getTypeParameterBounds())) {
                this.delta.changed(newElement, IJavaElementDelta.F_CONTENT);
            }
            HashMap oldTypeCategories = oldSourceTypeInfo.categories;
            HashMap newTypeCategories = newSourceTypeInfo.categories;
            if (oldTypeCategories != null) {
                // take the union of old and new categories elements (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=125675)
                Set elements;
                if (newTypeCategories != null) {
                    elements = new HashSet(oldTypeCategories.keySet());
                    elements.addAll(newTypeCategories.keySet());
                } else
                    elements = oldTypeCategories.keySet();
                Iterator iterator = elements.iterator();
                while (iterator.hasNext()) {
                    IJavaElement element = (IJavaElement) iterator.next();
                    String[] oldCategories = (String[]) oldTypeCategories.get(element);
                    String[] newCategories = newTypeCategories == null ? null
                            : (String[]) newTypeCategories.get(element);
                    if (!Util.equalArraysOrNull(oldCategories, newCategories)) {
                        this.delta.changed(element, IJavaElementDelta.F_CATEGORIES);
                    }
                }
            } else if (newTypeCategories != null) {
                Iterator elements = newTypeCategories.keySet().iterator();
                while (elements.hasNext()) {
                    IJavaElement element = (IJavaElement) elements.next();
                    this.delta.changed(element, IJavaElementDelta.F_CATEGORIES); // all categories for this element were removed
                }
            }
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.BinaryIndexer.java

License:Open Source License

/**
 * Extract all type, method, field and interface method references from the constant pool
 *///from  w w  w. j  a v  a2 s  .  co  m
private void extractReferenceFromConstantPool(byte[] contents, ClassFileReader reader)
        throws ClassFormatException {
    int[] constantPoolOffsets = reader.getConstantPoolOffsets();
    int constantPoolCount = constantPoolOffsets.length;
    for (int i = 1; i < constantPoolCount; i++) {
        int tag = reader.u1At(constantPoolOffsets[i]);
        /**
         * u1 tag
         * u2 class_index
         * u2 name_and_type_index
         */
        char[] name = null;
        char[] type = null;
        switch (tag) {
        case ClassFileConstants.FieldRefTag:
            // add reference to the class/interface and field name and type
            name = extractName(constantPoolOffsets, reader, i);
            addFieldReference(name);
            break;
        case ClassFileConstants.MethodRefTag:
            // add reference to the class and method name and type
        case ClassFileConstants.InterfaceMethodRefTag:
            // add reference to the interface and method name and type
            name = extractName(constantPoolOffsets, reader, i);
            type = extractType(constantPoolOffsets, reader, i);
            if (CharOperation.equals(INIT, name)) {
                // get class name and see if it's a local type or not
                char[] className = extractClassName(constantPoolOffsets, reader, i);
                boolean localType = false;
                if (className != null) {
                    for (int c = 0, max = className.length; c < max; c++) {
                        switch (className[c]) {
                        case '/':
                            className[c] = '.';
                            break;
                        case '$':
                            localType = true;
                            break;
                        }
                    }
                }
                // add a constructor reference, use class name to extract arg count if it's a local type to remove synthetic parameter
                addConstructorReference(className, extractArgCount(type, localType ? className : null));
            } else {
                // add a method reference
                addMethodReference(name, extractArgCount(type, null));
            }
            break;
        case ClassFileConstants.ClassTag:
            // add a type reference
            name = extractClassReference(constantPoolOffsets, reader, i);
            if (name.length > 0 && name[0] == '[')
                break; // skip over array references
            name = replace('/', '.', name); // so that it looks like java.lang.String
            addTypeReference(name);

            // also add a simple reference on each segment of the qualification (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=24741)
            char[][] qualification = CharOperation.splitOn('.', name);
            for (int j = 0, length = qualification.length; j < length; j++) {
                addNameReference(qualification[j]);
            }
            break;
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java

License:Open Source License

private boolean hasJavaLikeNamesChanged() {
    char[][] currentNames = com.codenvy.ide.ext.java.server.internal.core.search.Util.getJavaLikeExtensions();
    int current = currentNames.length;
    char[][] prevNames = readJavaLikeNamesFile();
    if (prevNames == null) {
        if (VERBOSE && current != 1)
            Util.verbose("No Java like names found and there is atleast one non-default javaLikeName", //$NON-NLS-1$
                    System.err);/*  w ww  .j av a  2s  . com*/
        return (current != 1); //Ignore if only java
    }
    int prev = prevNames.length;
    if (current != prev) {
        if (VERBOSE)
            Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$
        return true;
    }
    if (current > 1) {
        // Sort the current java like names.
        // Copy the array to avoid modifying the Util static variable
        System.arraycopy(currentNames, 0, currentNames = new char[current][], 0, current);
        Util.sort(currentNames);
    }

    // The JavaLikeNames would have been sorted before getting stored in the file,
    // hence just do a direct compare.
    for (int i = 0; i < current; i++) {
        if (!CharOperation.equals(currentNames[i], prevNames[i])) {
            if (VERBOSE)
                Util.verbose("Java like names have changed", System.err); //$NON-NLS-1$
            return true;
        }
    }
    return false;
}