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
9
* Markus Schorn - initial API and implementation
10
*******************************************************************************/
11
package org.eclipse.cdt.internal.core.pdom;
13
import java.util.HashSet;
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;
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;
29
private final ICProject fCProject;
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;
38
public IndexUpdatePolicy(ICProject project, int kind) {
40
fKind= getLegalPolicy(kind);
43
private int getLegalPolicy(int kind) {
53
public ICProject getProject() {
57
public void clearTUs() {
63
public boolean hasTUs() {
64
return !(fForce.isEmpty() && fTimestamp.isEmpty() && fRemoved.isEmpty());
67
public void setIndexer(IPDOMIndexer indexer) {
71
public IPDOMIndexer getIndexer() {
75
public IPDOMIndexerTask handleDelta(ITranslationUnit[] force, ITranslationUnit[] changed, ITranslationUnit[] removed) {
76
if (isNullIndexer()) {
81
case IndexUpdatePolicy.MANUAL:
83
case IndexUpdatePolicy.POST_CHANGE:
84
if (fIndexer != null) {
85
return fIndexer.createTask(force, changed, removed);
90
for (int i = 0; i < removed.length; i++) {
91
ITranslationUnit tu = removed[i];
93
fTimestamp.remove(tu);
96
for (int i = 0; i < force.length; i++) {
97
ITranslationUnit tu = force[i];
99
fTimestamp.remove(tu);
102
for (int i = 0; i < changed.length; i++) {
103
ITranslationUnit tu = changed[i];
104
if (!fForce.contains(tu)) {
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));
123
private ITranslationUnit[] toarray(HashSet<ITranslationUnit> set) {
124
return set.toArray(new ITranslationUnit[set.size()]);
127
private boolean isNullIndexer() {
128
return fIndexer != null && fIndexer.getID().equals(IPDOMManager.ID_NO_INDEXER);
131
public IPDOMIndexerTask changePolicy(int updatePolicy) {
132
int oldPolicy= fKind;
133
fKind= getLegalPolicy(updatePolicy);
135
IPDOMIndexerTask task= null;
136
if (fKind == MANUAL || isNullIndexer()) {
139
else if (fIndexer != null) {
140
if (oldPolicy == MANUAL) {
141
task= new PDOMUpdateTask(fIndexer, IIndexManager.UPDATE_CHECK_TIMESTAMPS);
144
else if (fKind == POST_CHANGE) {
151
public void requestInitialReindex() {
152
fReindexRequested= true;
155
public void clearInitialFlags() {
156
fReindexRequested= false;
159
public boolean isInitialRebuildRequested() {
160
return fReindexRequested;