1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for [Bug 203092] Available tools only lists one flavor of a tool

This commit is contained in:
Mikhail Sennikovsky 2007-09-14 20:25:38 +00:00
parent 104ed95619
commit 6e9c019ae5
2 changed files with 98 additions and 18 deletions

View file

@ -12,6 +12,7 @@ package org.eclipse.cdt.managedbuilder.internal.core;
import java.util.AbstractSet; import java.util.AbstractSet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -452,30 +453,95 @@ class ToolChainModificationHelper {
iter.set(new ToolInfo(rcInfo, t, ToolInfo.REMOVED)); iter.set(new ToolInfo(rcInfo, t, ToolInfo.REMOVED));
} }
calculateConverterTools(rcInfo, removedList, addedList, null, null); ToolInfo[] added = listToArray(addedList);
ToolInfo[] removed = listToArray(removedList);
adjustAddedList(added, removed);
calculateConverterTools(rcInfo, removed, added, null, null);
return new ToolListModificationInfo(rcInfo, return new ToolListModificationInfo(rcInfo,
listToArray(resultingList), listToArray(resultingList),
listToArray(addedList), added,
listToArray(removedList), removed,
listToArray(remainedList)); listToArray(remainedList));
} }
private static ITool getCommonSuperClass(ITool tool1, ITool tool2){
for(int i = 0; tool2 != null; tool2 = tool2.getSuperClass(), i++){
if(getSuperClassLevel(tool1, tool2) != -1)
return tool2;
}
return null;
}
private static int getSuperClassLevel(ITool tool, ITool superClass){
for(int i = 0; tool != null; tool = tool.getSuperClass(), i++){
if(superClass == tool)
return i;
}
return -1;
}
private static int getLevel(ITool tool){
int i= 0;
for(; tool != null; tool = tool.getSuperClass(), i++);
return i;
}
private static ITool getBestMatchTool(ITool realTool, ToolInfo[] tools){
int num = -1;
ITool bestMatch = null;
ITool[] identicTools = ManagedBuildManager.findIdenticalTools(realTool);
for(int i = 0; i < tools.length; i++){
ITool extTool = ManagedBuildManager.getExtensionTool(tools[i].getInitialTool());
for(int k = 0; k < identicTools.length; k++){
ITool identic = identicTools[k];
ITool commonSuper = getCommonSuperClass(extTool, identic);
if(commonSuper != null){
int level = getLevel(commonSuper);
if(level > num){
bestMatch = identic;
num = level;
}
}
}
}
return bestMatch;
}
private static void adjustAddedList(ToolInfo[] adds, ToolInfo[] removes){
for(int i = 0; i < adds.length; i++){
ToolInfo add = adds[i];
ITool bestMatch = getBestMatchTool(add.getRealTool(), removes);
if(bestMatch != null){
add.updateInitialTool(bestMatch);
}
}
}
private static ToolInfo[] listToArray(List list){ private static ToolInfo[] listToArray(List list){
return (ToolInfo[])list.toArray(new ToolInfo[list.size()]); return (ToolInfo[])list.toArray(new ToolInfo[list.size()]);
} }
private static Map calculateConverterTools(IResourceInfo rcInfo, List removedList, List addedList, List remainingRemoved, List remainingAdded){ private static Map calculateConverterTools(IResourceInfo rcInfo, ToolInfo[] removed, ToolInfo[] added, List remainingRemoved, List remainingAdded){
if(remainingAdded == null) if(remainingAdded == null)
remainingAdded = new ArrayList(addedList.size()); remainingAdded = new ArrayList(added.length);
if(remainingRemoved == null) if(remainingRemoved == null)
remainingRemoved = new ArrayList(removedList.size()); remainingRemoved = new ArrayList(removed.length);
remainingAdded.clear(); remainingAdded.clear();
remainingRemoved.clear(); remainingRemoved.clear();
remainingAdded.addAll(addedList); remainingAdded.addAll(Arrays.asList(added));
remainingRemoved.addAll(removedList); remainingRemoved.addAll(Arrays.asList(removed));
Map resultMap = new HashMap(); Map resultMap = new HashMap();

View file

@ -35,9 +35,8 @@ class ToolInfo {
ToolInfo(IResourceInfo rcInfo, ITool tool, int flag){ ToolInfo(IResourceInfo rcInfo, ITool tool, int flag){
fRcInfo = rcInfo; fRcInfo = rcInfo;
fInitialTool = tool;
fBaseTool = calculateBaseTool(rcInfo, tool); updateInitialTool(tool);
fFlag = flag; fFlag = flag;
} }
@ -57,14 +56,15 @@ class ToolInfo {
if(realTool == null){ if(realTool == null){
baseTool = tool; baseTool = tool;
} else { } else {
ITool[] tcTools = baseTc.getTools(); // ITool[] tcTools = baseTc.getTools();
for(int i = 0; i < tcTools.length; i++){ // baseTool = getBestMatchTool(realTool, tcTools);
ITool extTool = ManagedBuildManager.getExtensionTool(tcTools[i]); //
if(extTool != null && realTool == ManagedBuildManager.getRealTool(extTool)){ // if(baseTool == null){
baseTool = extTool; // IToolChain extTc = ManagedBuildManager.getExtensionToolChain(baseTc);
break; // if(extTc != null){
} // baseTool = getBestMatchTool(realTool, extTc.getTools());
} // }
// }
if(baseTool == null){ if(baseTool == null){
baseTool = tool; baseTool = tool;
@ -91,6 +91,20 @@ class ToolInfo {
return fRealTool; return fRealTool;
} }
void updateInitialTool(ITool tool){
if(fInitialTool == tool)
return;
fResultingTool = null;
fRealTool = null;
fInitialTool = tool;
fModificationStatus = null;
fBaseTool = calculateBaseTool(fRcInfo, tool);
}
public ITool getBaseTool(){ public ITool getBaseTool(){
if(fBaseTool == null){ if(fBaseTool == null){
fBaseTool = ManagedBuildManager.getExtensionTool(fInitialTool); fBaseTool = ManagedBuildManager.getExtensionTool(fInitialTool);