1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

1. Bug-fixes

2. Basis for the pattern paths support
This commit is contained in:
Mikhail Sennikovsky 2007-03-16 14:35:43 +00:00
parent 4a6e26be9c
commit 4ba1f45c11
5 changed files with 332 additions and 40 deletions

View file

@ -12,19 +12,19 @@ package org.eclipse.cdt.core.settings.model.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
public class PathSettingsContainer { public class PathSettingsContainer {
private static final Object INEXISTENT_VALUE = new Object(); private static final Object INEXISTENT_VALUE = new Object();
private static final int INIT_CHILDREN_MAP_CAPACITY = 2; // private static final int INIT_CHILDREN_MAP_CAPACITY = 2;
private Map fChildrenMap; // private Map fChildrenMap;
// private Map fPatternMap;
private PatternNameMap fPatternChildrenMap;
private Object fValue; private Object fValue;
private IPath fPath; private IPath fPath;
private String fName; private String fName;
@ -32,6 +32,8 @@ public class PathSettingsContainer {
private PathSettingsContainer fDirectParentContainer; private PathSettingsContainer fDirectParentContainer;
private List fListeners; private List fListeners;
private boolean fIsPatternMode;
private static final int ADDED = 1; private static final int ADDED = 1;
private static final int REMOVED = 2; private static final int REMOVED = 2;
private static final int VALUE_CHANGED = 3; private static final int VALUE_CHANGED = 3;
@ -39,17 +41,22 @@ public class PathSettingsContainer {
public static PathSettingsContainer createRootContainer(){ public static PathSettingsContainer createRootContainer(){
return new PathSettingsContainer(); return createRootContainer(false);
} }
private PathSettingsContainer(){ public static PathSettingsContainer createRootContainer(boolean patternMode){
this(null, null, new String()); return new PathSettingsContainer(patternMode);
} }
private PathSettingsContainer(PathSettingsContainer root, PathSettingsContainer parent, String name){ private PathSettingsContainer(boolean pattternMode){
this(null, null, "", pattternMode); //$NON-NLS-1$
}
private PathSettingsContainer(PathSettingsContainer root, PathSettingsContainer parent, String name, boolean patternMode){
fRootContainer = root; fRootContainer = root;
fDirectParentContainer = parent; fDirectParentContainer = parent;
fName = name; fName = name;
fIsPatternMode = patternMode;
if(fRootContainer == null){ if(fRootContainer == null){
fRootContainer = this; fRootContainer = this;
// fPath = new Path(name); // fPath = new Path(name);
@ -58,18 +65,18 @@ public class PathSettingsContainer {
} }
} }
private Map getChildrenMap(boolean create){ private PatternNameMap getPatternChildrenMap(boolean create){
if(fChildrenMap == null && create) if(fPatternChildrenMap == null && create)
fChildrenMap = new HashMap(INIT_CHILDREN_MAP_CAPACITY); fPatternChildrenMap = new PatternNameMap();
return fChildrenMap; return fPatternChildrenMap;
} }
private PathSettingsContainer getChild(String name, boolean create){ private PathSettingsContainer getExacChild(String name, boolean create){
Map map = getChildrenMap(create); PatternNameMap pMap = getPatternChildrenMap(create);
if(map != null){ if(pMap != null){
PathSettingsContainer child = (PathSettingsContainer)map.get(name); PathSettingsContainer child = (PathSettingsContainer)pMap.get(name);
if(child == null && create){ if(child == null && create){
child = new PathSettingsContainer(fRootContainer, this, name); child = new PathSettingsContainer(fRootContainer, this, name, fIsPatternMode);
connectChild(child); connectChild(child);
} }
return child; return child;
@ -77,6 +84,15 @@ public class PathSettingsContainer {
return null; return null;
} }
private List getChildren(String name){
PatternNameMap pMap = getPatternChildrenMap(false);
if(pMap != null){
return pMap.getValues(name);
}
return null;
}
private void notifyChange(PathSettingsContainer container, int type, Object oldValue, boolean childrenAffected){ private void notifyChange(PathSettingsContainer container, int type, Object oldValue, boolean childrenAffected){
List list = getListenersList(false); List list = getListenersList(false);
if(list != null && list.size() > 0){ if(list != null && list.size() > 0){
@ -110,8 +126,8 @@ public class PathSettingsContainer {
} }
public boolean hasChildren(){ public boolean hasChildren(){
Map map = getChildrenMap(false); PatternNameMap pMap = getPatternChildrenMap(false);
return map != null && map.size() != 0; return pMap != null && pMap.size() != 0;
} }
public PathSettingsContainer getChildContainer(IPath path, boolean create, boolean exactPath){ public PathSettingsContainer getChildContainer(IPath path, boolean create, boolean exactPath){
@ -168,11 +184,11 @@ public class PathSettingsContainer {
} }
private List doGetDirectChildren(List list){ private List doGetDirectChildren(List list){
Map map = getChildrenMap(false); PatternNameMap pMap = getPatternChildrenMap(false);
if(map != null){ if(pMap != null){
if(list == null) if(list == null)
list = new ArrayList(); list = new ArrayList();
for(Iterator iter = map.values().iterator(); iter.hasNext(); ){ for(Iterator iter = pMap.values().iterator(); iter.hasNext(); ){
PathSettingsContainer cr = (PathSettingsContainer)iter.next(); PathSettingsContainer cr = (PathSettingsContainer)iter.next();
if(cr.fValue == INEXISTENT_VALUE){ if(cr.fValue == INEXISTENT_VALUE){
cr.doGetDirectChildren(list); cr.doGetDirectChildren(list);
@ -242,11 +258,11 @@ public class PathSettingsContainer {
} }
private void disconnectChild(PathSettingsContainer child){ private void disconnectChild(PathSettingsContainer child){
getChildrenMap(true).remove(child.getName()); getPatternChildrenMap(true).remove(child.getName());
} }
private void connectChild(PathSettingsContainer child){ private void connectChild(PathSettingsContainer child){
getChildrenMap(true).put(child.getName(), child); getPatternChildrenMap(true).put(child.getName(), child);
} }
public boolean isValid(){ public boolean isValid(){
@ -254,12 +270,12 @@ public class PathSettingsContainer {
} }
public void removeChildren(){ public void removeChildren(){
Map map = getChildrenMap(false); PatternNameMap pMap = getPatternChildrenMap(false);
if(map == null || map.size() == 0) if(pMap == null || pMap.size() == 0)
return; return;
Collection c = map.values(); Collection c = pMap.values();
PathSettingsContainer childContainers[] = (PathSettingsContainer[])c.toArray(new PathSettingsContainer[c.size()]); PathSettingsContainer childContainers[] = (PathSettingsContainer[])c.toArray(new PathSettingsContainer[c.size()]);
for(int i = 0; i < childContainers.length; i++){ for(int i = 0; i < childContainers.length; i++){
@ -269,7 +285,7 @@ public class PathSettingsContainer {
} }
private void deleteChild(PathSettingsContainer child){ private void deleteChild(PathSettingsContainer child){
getChildrenMap(false).remove(child.getName()); getPatternChildrenMap(false).remove(child.getName());
} }
private String getName(){ private String getName(){
@ -280,12 +296,31 @@ public class PathSettingsContainer {
PathSettingsContainer container = null; PathSettingsContainer container = null;
if(path.segmentCount() == 0) if(path.segmentCount() == 0)
container = this; container = this;
else { else if (create || exactPath || !fIsPatternMode) {
PathSettingsContainer child = getChild(path.segment(0), create); PathSettingsContainer child = getExacChild(path.segment(0), create);
if(child != null) if(child != null)
container = child.findContainer(path.removeFirstSegments(1), create, exactPath); container = child.findContainer(path.removeFirstSegments(1), create, exactPath);
else if(!exactPath) else if(!exactPath)
container = this; container = this;
} else {
//looking for container using patterns in read mode (i.e. not creating new container)
List list = getChildren(path.segment(0));
if(list != null){
int size = list.size();
PathSettingsContainer child, childFound;
for(int i = 0; i < size; i++){
child = (PathSettingsContainer)list.get(i);
childFound = child.findContainer(path.removeFirstSegments(1), false, false);
if(container == null)
container = childFound;
else if(container.getPath().segmentCount() < childFound.getPath().segmentCount()){
container = childFound;
}
}
}
if(container == null)
container = this;
} }
return container; return container;
} }
@ -298,9 +333,9 @@ public class PathSettingsContainer {
if(fValue != INEXISTENT_VALUE && !visitor.visit(this)) if(fValue != INEXISTENT_VALUE && !visitor.visit(this))
return false; return false;
Map map = getChildrenMap(false); PatternNameMap pMap = getPatternChildrenMap(false);
if(map != null){ if(pMap != null){
for(Iterator iter = map.values().iterator(); iter.hasNext();){ for(Iterator iter = pMap.values().iterator(); iter.hasNext();){
PathSettingsContainer child = (PathSettingsContainer)iter.next(); PathSettingsContainer child = (PathSettingsContainer)iter.next();
if(!child.doAccept(visitor)) if(!child.doAccept(visitor))
return false; return false;
@ -330,8 +365,8 @@ public class PathSettingsContainer {
if(!moveChildren){ if(!moveChildren){
if(hasChildren()){ if(hasChildren()){
PathSettingsContainer cr = new PathSettingsContainer(fRootContainer, fDirectParentContainer, fName); PathSettingsContainer cr = new PathSettingsContainer(fRootContainer, fDirectParentContainer, fName, fIsPatternMode);
for(Iterator iter = fChildrenMap.values().iterator(); iter.hasNext();){ for(Iterator iter = fPatternChildrenMap.values().iterator(); iter.hasNext();){
PathSettingsContainer child = (PathSettingsContainer)iter.next(); PathSettingsContainer child = (PathSettingsContainer)iter.next();
iter.remove(); iter.remove();
child.setParent(cr); child.setParent(cr);

View file

@ -0,0 +1,241 @@
/*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.settings.model.util;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import org.eclipse.cdt.core.model.CoreModelUtil;
public class PatternNameMap {
private static final char[] SPEC_CHARS = new char[]{'*', '?'};
private Map fChildrenMap;
private Map fPatternMap;
private Collection fValues;
private static class StringCharArray {
private String fString;
private char[] fCharArray;
StringCharArray(String string){
fString = string;
}
char[] getCharArray(){
if(fCharArray == null){
fCharArray = fString.toCharArray();
}
return fCharArray;
}
public boolean equals(Object obj) {
if(obj == this)
return true;
if(!(obj instanceof StringCharArray))
return false;
return fString.equals(((StringCharArray)obj).fString);
}
public int hashCode() {
return fString.hashCode();
}
public String toString() {
return fString;
}
}
private class EmptyIterator implements Iterator{
public boolean hasNext() {
return false;
}
public Object next() {
throw new NoSuchElementException();
}
public void remove() {
throw new IllegalStateException();
}
}
private class ValuesCollection extends AbstractCollection {
private class Iter implements Iterator {
private Iterator fEntrySetIter;
private Map.Entry fCur;
Iter (Iterator entryIter){
this.fEntrySetIter = entryIter;
}
public boolean hasNext() {
return fEntrySetIter.hasNext();
}
public Object next() {
fCur = (Map.Entry)fEntrySetIter.next();
return fCur.getValue();
}
public void remove() {
fEntrySetIter.remove();
removePattern((String)fCur.getKey());
}
}
public Iterator iterator() {
return fChildrenMap != null ? (Iterator)new Iter(fChildrenMap.entrySet().iterator()) : (Iterator)new EmptyIterator();
}
public int size() {
return PatternNameMap.this.size();
}
public void clear(){
PatternNameMap.this.clear();
}
public boolean contains(Object o){
return fChildrenMap != null ? fChildrenMap.containsValue(o) : false;
}
}
public Object get(String name){
return fChildrenMap != null ? fChildrenMap.get(name) : null;
}
public int size(){
return fChildrenMap != null ? fChildrenMap.size() : 0;
}
public boolean hasPatterns(){
return fPatternMap != null && fPatternMap.size() != 0;
}
public List getValues(String name){
if(fChildrenMap == null)
return null;
Object val = fChildrenMap.get(name);
if(hasPatterns()){
List list;
if(val != null){
list = new ArrayList(3);
list.add(val);
} else {
list = null;;
}
Map.Entry entry;
StringCharArray strCA;
char[] nameCharArray = name.toCharArray();
for(Iterator iter = fPatternMap.entrySet().iterator(); iter.hasNext();){
entry = (Map.Entry)iter.next();
strCA = (StringCharArray)entry.getKey();
if(CoreModelUtil.match(strCA.getCharArray(), nameCharArray, true)){
if(list == null)
list = new ArrayList(2);
list.add(entry.getValue());
}
}
return list;
} else if (val != null){
List list = new ArrayList(1);
list.add(val);
return list;
}
return null;
}
public Object put(String name, Object value){
if(value == null)
return remove(name);
Object oldValue;
if(fChildrenMap == null){
fChildrenMap = new HashMap();
oldValue = null;
} else {
oldValue = fChildrenMap.get(name);
}
fChildrenMap.put(name, value);
if(isPatternName(name)){
StringCharArray strCA = new StringCharArray(name);
if(fPatternMap == null)
fPatternMap = new HashMap();
fPatternMap.put(strCA, value);
}
return oldValue;
}
public Object remove(String name){
if(fChildrenMap != null){
Object oldVal = fChildrenMap.remove(name);
if(fChildrenMap.size() == 0){
fChildrenMap = null;
fPatternMap = null;
} else {
removePattern(name);
}
return oldVal;
}
return null;
}
private void removePattern(String name){
if (fPatternMap != null){
fPatternMap.remove(new StringCharArray(name));
if(fPatternMap.size() == 0)
fPatternMap = null;
}
}
private static boolean hasSpecChars(String str){
for(int i = 0; i < SPEC_CHARS.length; i++){
if(str.indexOf(SPEC_CHARS[i]) != -1)
return true;
}
return false;
}
public static boolean isPatternName(String str){
//TODO: check escape chars
return hasSpecChars(str);
}
public void clear(){
fChildrenMap = null;
fPatternMap = null;
}
public Collection values(){
if(fValues == null)
fValues = new ValuesCollection();
return fValues;
}
}

View file

@ -90,7 +90,7 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData
((CBuildSettingCache)fBuildData).initEnvironmentCache(); ((CBuildSettingCache)fBuildData).initEnvironmentCache();
ICdtVariable vars[] = CdtVariableManager.getDefault().getVariables(this); ICdtVariable vars[] = CdtVariableManager.getDefault().getVariables(this);
fMacros = new StorableCdtVariables(vars, true); fMacros = new StorableCdtVariables(vars, true);
fInitializing = false; // fInitializing = false;
} }
CConfigurationDescriptionCache(ICConfigurationDescription baseDescription, CConfigurationData base, CConfigurationSpecSettings settingsBase, CProjectDescription parent, ICStorageElement rootEl) throws CoreException { CConfigurationDescriptionCache(ICConfigurationDescription baseDescription, CConfigurationData base, CConfigurationSpecSettings settingsBase, CProjectDescription parent, ICStorageElement rootEl) throws CoreException {
@ -138,7 +138,7 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData
fSpecSettings.serialize(); fSpecSettings.serialize();
fBaseDescription = null; fBaseDescription = null;
fInitializing = false; // fInitializing = false;
} }
public StorableCdtVariables getCachedVariables(){ public StorableCdtVariables getCachedVariables(){
@ -420,4 +420,8 @@ public class CConfigurationDescriptionCache extends CDefaultConfigurationData
public boolean isPreferenceConfiguration() { public boolean isPreferenceConfiguration() {
return getProjectDescription() == null; return getProjectDescription() == null;
} }
void doneInitialization(){
fInitializing = false;
}
} }

View file

@ -82,6 +82,7 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
} }
} }
doneInitializing();
fIsLoadding = false; fIsLoadding = false;
} }
@ -99,9 +100,18 @@ public class CProjectDescription implements ICProjectDescription, ICDataProxyCon
} }
} }
doneInitializing();
fIsApplying = false; fIsApplying = false;
} }
private void doneInitializing(){
for(Iterator iter = fCfgMap.values().iterator(); iter.hasNext();){
CConfigurationDescriptionCache cache = (CConfigurationDescriptionCache)iter.next();
cache.doneInitialization();
}
}
public boolean isLoadding(){ public boolean isLoadding(){
return fIsLoadding; return fIsLoadding;
} }

View file

@ -2657,6 +2657,7 @@ public class CProjectDescriptionManager {
rootEl = rootParent.importChild(baseRootEl); rootEl = rootParent.importChild(baseRootEl);
CConfigurationDescriptionCache cache = new CConfigurationDescriptionCache(des, baseData, cfgDes.getSpecSettings(), null, rootEl); CConfigurationDescriptionCache cache = new CConfigurationDescriptionCache(des, baseData, cfgDes.getSpecSettings(), null, rootEl);
cache.applyData(); cache.applyData();
cache.doneInitialization();
return cache; return cache;
} }
@ -2734,6 +2735,7 @@ public class CProjectDescriptionManager {
} }
CConfigurationDescriptionCache cache = new CConfigurationDescriptionCache(cfgEl, null); CConfigurationDescriptionCache cache = new CConfigurationDescriptionCache(cfgEl, null);
cache.loadData(); cache.loadData();
cache.doneInitialization();
return cache; return cache;
} }