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

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/IndexUpdatePolicy.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
3
 
 * All rights reserved. This program and the accompanying materials
4
 
 * are made available under the terms of the Eclipse Public License v1.0
5
 
 * which accompanies this distribution, and is available at
6
 
 * http://www.eclipse.org/legal/epl-v10.html
7
 
 *
8
 
 * Contributors:
9
 
 *    Markus Schorn - initial API and implementation
10
 
 *******************************************************************************/ 
11
 
package org.eclipse.cdt.internal.core.pdom;
12
 
 
13
 
import java.util.HashSet;
14
 
 
15
 
import org.eclipse.cdt.core.dom.IPDOMIndexer;
16
 
import org.eclipse.cdt.core.dom.IPDOMIndexerTask;
17
 
import org.eclipse.cdt.core.dom.IPDOMManager;
18
 
import org.eclipse.cdt.core.index.IIndexManager;
19
 
import org.eclipse.cdt.core.model.ICProject;
20
 
import org.eclipse.cdt.core.model.ITranslationUnit;
21
 
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
22
 
import org.eclipse.cdt.internal.core.pdom.indexer.PDOMUpdateTask;
23
 
 
24
 
public class IndexUpdatePolicy {
25
 
        public static final int POST_CHANGE= IndexerPreferences.UPDATE_POLICY_IMMEDIATE;
26
 
        public static final int POST_BUILD= IndexerPreferences.UPDATE_POLICY_LAZY;
27
 
        public static final int MANUAL= IndexerPreferences.UPDATE_POLICY_MANUAL;
28
 
        
29
 
        private final ICProject fCProject;
30
 
        private int fKind;
31
 
        
32
 
        private HashSet<ITranslationUnit> fForce= new HashSet<ITranslationUnit>();
33
 
        private HashSet<ITranslationUnit> fTimestamp= new HashSet<ITranslationUnit>();
34
 
        private HashSet<ITranslationUnit> fRemoved= new HashSet<ITranslationUnit>();
35
 
        private IPDOMIndexer fIndexer;
36
 
        private boolean fReindexRequested;
37
 
 
38
 
        public IndexUpdatePolicy(ICProject project, int kind) {
39
 
                fCProject= project;
40
 
                fKind= getLegalPolicy(kind);
41
 
        }
42
 
 
43
 
        private int getLegalPolicy(int kind) {
44
 
                switch(kind) {
45
 
                case POST_BUILD:
46
 
                case POST_CHANGE:
47
 
                case MANUAL:
48
 
                        return kind;
49
 
                }
50
 
                return POST_CHANGE;
51
 
        }
52
 
 
53
 
        public ICProject getProject() {
54
 
                return fCProject;
55
 
        }
56
 
 
57
 
        public void clearTUs() {
58
 
                fForce.clear();
59
 
                fTimestamp.clear();
60
 
                fRemoved.clear();
61
 
        }
62
 
 
63
 
        public boolean hasTUs() {
64
 
                return !(fForce.isEmpty() && fTimestamp.isEmpty() && fRemoved.isEmpty());
65
 
        }
66
 
 
67
 
        public void setIndexer(IPDOMIndexer indexer) {
68
 
                fIndexer= indexer;
69
 
        }
70
 
 
71
 
        public IPDOMIndexer getIndexer() {
72
 
                return fIndexer;
73
 
        }
74
 
 
75
 
        public IPDOMIndexerTask handleDelta(ITranslationUnit[] force, ITranslationUnit[] changed, ITranslationUnit[] removed) {
76
 
                if (isNullIndexer()) {
77
 
                        return null;
78
 
                }
79
 
 
80
 
                switch(fKind) {
81
 
                case IndexUpdatePolicy.MANUAL:
82
 
                        return null;
83
 
                case IndexUpdatePolicy.POST_CHANGE:
84
 
                        if (fIndexer != null) {
85
 
                                return fIndexer.createTask(force, changed, removed);
86
 
                        }
87
 
                        break;
88
 
                }
89
 
                
90
 
                for (int i = 0; i < removed.length; i++) {
91
 
                        ITranslationUnit tu = removed[i];
92
 
                        fForce.remove(tu);
93
 
                        fTimestamp.remove(tu);
94
 
                        fRemoved.add(tu);
95
 
                }
96
 
                for (int i = 0; i < force.length; i++) {
97
 
                        ITranslationUnit tu = force[i];
98
 
                        fForce.add(tu);
99
 
                        fTimestamp.remove(tu);
100
 
                        fRemoved.remove(tu);
101
 
                }
102
 
                for (int i = 0; i < changed.length; i++) {
103
 
                        ITranslationUnit tu = changed[i];
104
 
                        if (!fForce.contains(tu)) {
105
 
                                fTimestamp.add(tu);
106
 
                        }
107
 
                        fRemoved.remove(tu);
108
 
                }
109
 
                return null;
110
 
        }
111
 
        
112
 
        public IPDOMIndexerTask createTask() {
113
 
                IPDOMIndexerTask task= null;
114
 
                if (fIndexer != null && hasTUs()) {
115
 
                        if (fKind != IndexUpdatePolicy.MANUAL && !isNullIndexer()) {
116
 
                                task= fIndexer.createTask(toarray(fForce), toarray(fTimestamp), toarray(fRemoved));
117
 
                        }
118
 
                        clearTUs();
119
 
                }
120
 
                return task;
121
 
        }
122
 
 
123
 
        private ITranslationUnit[] toarray(HashSet<ITranslationUnit> set) {
124
 
                return set.toArray(new ITranslationUnit[set.size()]);
125
 
        }
126
 
 
127
 
        private boolean isNullIndexer() {
128
 
                return fIndexer != null && fIndexer.getID().equals(IPDOMManager.ID_NO_INDEXER);
129
 
        }
130
 
 
131
 
        public IPDOMIndexerTask changePolicy(int updatePolicy) {
132
 
                int oldPolicy= fKind;
133
 
                fKind= getLegalPolicy(updatePolicy);
134
 
                
135
 
                IPDOMIndexerTask task= null;
136
 
                if (fKind == MANUAL || isNullIndexer()) {
137
 
                        clearTUs();
138
 
                }
139
 
                else if (fIndexer != null) {
140
 
                        if (oldPolicy == MANUAL) {
141
 
                                task= new PDOMUpdateTask(fIndexer, IIndexManager.UPDATE_CHECK_TIMESTAMPS);
142
 
                                clearTUs();
143
 
                        }
144
 
                        else if (fKind == POST_CHANGE) {
145
 
                                task= createTask();
146
 
                        }
147
 
                }
148
 
                return task;
149
 
        }
150
 
 
151
 
        public void requestInitialReindex() {
152
 
                fReindexRequested= true;
153
 
        }
154
 
 
155
 
        public void clearInitialFlags() {
156
 
                fReindexRequested= false;
157
 
        }
158
 
 
159
 
        public boolean isInitialRebuildRequested() {
160
 
                return fReindexRequested;
161
 
        }
162
 
}