~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/resources/FileRelevance.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2013-10-03 20:30:16 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20131003203016-d4ug6l0xgosasumq
Tags: 8.2.1-1
* New upstream release.
* Updated autotools documentation sources.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 *******************************************************************************/
12
12
package org.eclipse.cdt.internal.core.resources;
13
13
 
 
14
import java.net.URI;
 
15
 
14
16
import org.eclipse.cdt.core.model.CoreModel;
15
17
import org.eclipse.cdt.core.model.ICProject;
16
18
import org.eclipse.cdt.internal.core.model.CModelManager;
17
19
import org.eclipse.core.resources.IFile;
18
20
import org.eclipse.core.resources.IProject;
19
21
import org.eclipse.core.resources.ResourceAttributes;
 
22
import org.eclipse.core.runtime.IPath;
20
23
 
21
24
/**
22
25
 * This class computes a relevance for files in case we have to select
43
46
         * @return integer representing file relevance. Larger numbers are more relevant
44
47
         */
45
48
        public static int getRelevance(IFile f, IProject preferredProject) {
 
49
                return getRelevance(f, preferredProject, true, null);
 
50
        }
 
51
 
 
52
        /**
 
53
         * Compute a relevance for the given file. The higher the score the more relevant the
 
54
         * file. It is determined by the following criteria: <br>
 
55
         * - file belongs to preferred project <br>
 
56
         * - file belongs to a cdt-project <br>
 
57
         * - file belongs to a source folder of a cdt-project <br>
 
58
         * - file is accessible
 
59
         * - file is not a link
 
60
         * - file matches the original location
 
61
         * @param f the file to compute the relevance for
 
62
         * @return integer representing file relevance. Larger numbers are more relevant
 
63
         */
 
64
        public static int getRelevance(IFile f, IProject preferredProject, boolean degradeSymLinks, Object originalLocation) {
46
65
                int result= 0;
47
66
                IProject p= f.getProject();
48
67
                if (p.equals(preferredProject))
55
74
                                result+= ON_SOURCE_ROOT;
56
75
                }
57
76
 
58
 
                if (!f.isAccessible())
 
77
                if (!f.isAccessible()) {
59
78
                        result >>= INACCESSIBLE_SHIFT;
60
 
                else {
 
79
                } else if (f.isLinked()) {
 
80
                        result -= LINK_PENALTY;
 
81
                } else if (degradeSymLinks) {
61
82
                        ResourceAttributes ra = f.getResourceAttributes();
62
 
                        if (f.isLinked() || (ra != null && ra.isSymbolicLink()))
 
83
                        if (ra != null && ra.isSymbolicLink())
63
84
                                result -= LINK_PENALTY;
 
85
                } else {
 
86
                        // Symbolic links are not degraded, prefer the original location
 
87
                        if (originalLocation instanceof URI) {
 
88
                                if (originalLocation.equals(f.getLocationURI()))
 
89
                                        result += LINK_PENALTY;
 
90
                        } else if (originalLocation instanceof IPath) {
 
91
                                if (originalLocation.equals(f.getLocation()))
 
92
                                        result+= LINK_PENALTY;
 
93
                        }
64
94
                }
65
 
 
66
95
                return result;
67
96
        }
68
97
}