Example usage for org.eclipse.jdt.internal.core CompilationUnit hasResourceChanged

List of usage examples for org.eclipse.jdt.internal.core CompilationUnit hasResourceChanged

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core CompilationUnit hasResourceChanged.

Prototype

@Override
    public boolean hasResourceChanged() 

Source Link

Usage

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

License:Open Source License

private ICompilationUnit[] getWorkingCopies() {
    ICompilationUnit[] copies;//  www .  j av  a 2  s .c o m
    if (this.workingCopies != null) {
        if (this.workingCopyOwner == null) {
            copies = JavaModelManager.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY,
                    false/*don't add primary WCs a second time*/);
            if (copies == null) {
                copies = this.workingCopies;
            } else {
                HashMap pathToCUs = new HashMap();
                for (int i = 0, length = copies.length; i < length; i++) {
                    ICompilationUnit unit = copies[i];
                    pathToCUs.put(unit.getPath(), unit);
                }
                for (int i = 0, length = this.workingCopies.length; i < length; i++) {
                    ICompilationUnit unit = this.workingCopies[i];
                    pathToCUs.put(unit.getPath(), unit);
                }
                int length = pathToCUs.size();
                copies = new ICompilationUnit[length];
                pathToCUs.values().toArray(copies);
            }
        } else {
            copies = this.workingCopies;
        }
    } else if (this.workingCopyOwner != null) {
        copies = JavaModelManager.getJavaModelManager().getWorkingCopies(this.workingCopyOwner,
                true/*add primary WCs*/);
    } else {
        copies = JavaModelManager.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY,
                false/*don't add primary WCs a second time*/);
    }
    if (copies == null)
        return null;

    // filter out primary working copies that are saved
    ICompilationUnit[] result = null;
    int length = copies.length;
    int index = 0;
    for (int i = 0; i < length; i++) {
        CompilationUnit copy = (CompilationUnit) copies[i];
        try {
            if (!copy.isPrimary() || copy.hasUnsavedChanges() || copy.hasResourceChanged()) {
                if (result == null) {
                    result = new ICompilationUnit[length];
                }
                result[index++] = copy;
            }
        } catch (JavaModelException e) {
            // copy doesn't exist: ignore
        }
    }
    if (index != length && result != null) {
        System.arraycopy(result, 0, result = new ICompilationUnit[index], 0, index);
    }
    return result;
}

From source file:org.eclipse.che.jdt.internal.core.search.BasicSearchEngine.java

License:Open Source License

private ICompilationUnit[] getWorkingCopies() {
    ICompilationUnit[] copies;// w  w  w.ja va2  s  . com
    if (this.workingCopies != null) {
        if (this.workingCopyOwner == null) {
            copies = javaProject.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY,
                    false/*don't add primary WCs
                         a second time*/);
            if (copies == null) {
                copies = this.workingCopies;
            } else {
                HashMap pathToCUs = new HashMap();
                for (int i = 0, length = copies.length; i < length; i++) {
                    ICompilationUnit unit = copies[i];
                    pathToCUs.put(unit.getPath(), unit);
                }
                for (int i = 0, length = this.workingCopies.length; i < length; i++) {
                    ICompilationUnit unit = this.workingCopies[i];
                    pathToCUs.put(unit.getPath(), unit);
                }
                int length = pathToCUs.size();
                copies = new ICompilationUnit[length];
                pathToCUs.values().toArray(copies);
            }
        } else {
            copies = this.workingCopies;
        }
    } else if (this.workingCopyOwner != null) {
        copies = javaProject.getJavaModelManager().getWorkingCopies(this.workingCopyOwner,
                true/*add primary WCs*/);
    } else {
        copies = javaProject.getJavaModelManager().getWorkingCopies(DefaultWorkingCopyOwner.PRIMARY,
                false/*don't add primary WCs a second time*/);
    }
    if (copies == null)
        return null;

    // filter out primary working copies that are saved
    ICompilationUnit[] result = null;
    int length = copies.length;
    int index = 0;
    for (int i = 0; i < length; i++) {
        CompilationUnit copy = (CompilationUnit) copies[i];
        try {
            if (!copy.isPrimary() || copy.hasUnsavedChanges() || copy.hasResourceChanged()) {
                if (result == null) {
                    result = new ICompilationUnit[length];
                }
                result[index++] = copy;
            }
        } catch (JavaModelException e) {
            // copy doesn't exist: ignore
        }
    }
    if (index != length && result != null) {
        System.arraycopy(result, 0, result = new ICompilationUnit[index], 0, index);
    }
    return result;
}