1 11 package org.eclipse.core.internal.resources; 12 13 import java.util.*; 14 import org.eclipse.core.resources.ResourcesPlugin; 15 import org.eclipse.core.runtime.*; 16 17 public class MarkerTypeDefinitionCache { 18 static class MarkerTypeDefinition { 19 boolean isPersistent = false; 20 Set superTypes; 21 22 MarkerTypeDefinition(IExtension ext) { 23 IConfigurationElement[] elements = ext.getConfigurationElements(); 24 for (int i = 0; i < elements.length; i++) { 25 IConfigurationElement element = elements[i]; 26 final String elementName = element.getName(); 28 if (elementName.equalsIgnoreCase("super")) { String aType = element.getAttribute("type"); if (aType != null) { 31 if (superTypes == null) 32 superTypes = new HashSet(8); 33 superTypes.add(aType.intern()); 37 } 38 } 39 if (elementName.equalsIgnoreCase("persistent")) { String bool = element.getAttribute("value"); if (bool != null) 43 this.isPersistent = Boolean.valueOf(bool).booleanValue(); 44 } 45 if (elementName.equalsIgnoreCase("transient")) { String bool = element.getAttribute("value"); if (bool != null) 49 this.isPersistent = !Boolean.valueOf(bool).booleanValue(); 50 } 51 } 52 } 53 } 54 55 58 protected HashMap definitions; 59 60 62 public MarkerTypeDefinitionCache() { 63 loadDefinitions(); 64 HashSet toCompute = new HashSet(definitions.keySet()); 65 for (Iterator i = definitions.keySet().iterator(); i.hasNext();) { 66 String markerId = (String ) i.next(); 67 if (toCompute.contains(markerId)) 68 computeSuperTypes(markerId, toCompute); 69 } 70 } 71 72 80 private Set computeSuperTypes(String markerId, Set toCompute) { 81 MarkerTypeDefinition def = (MarkerTypeDefinition) definitions.get(markerId); 82 if (def == null || def.superTypes == null) { 83 toCompute.remove(markerId); 85 return null; 86 } 87 Set transitiveSuperTypes = new HashSet(def.superTypes); 88 for (Iterator it = def.superTypes.iterator(); it.hasNext();) { 89 String superId = (String ) it.next(); 90 Set toAdd = null; 91 if (toCompute.contains(superId)) { 92 toAdd = computeSuperTypes(superId, toCompute); 94 } else { 95 MarkerTypeDefinition parentDef = (MarkerTypeDefinition) definitions.get(superId); 97 if (parentDef != null) 98 toAdd = parentDef.superTypes; 99 } 100 if (toAdd != null) 101 transitiveSuperTypes.addAll(toAdd); 102 } 103 def.superTypes = transitiveSuperTypes; 104 toCompute.remove(markerId); 105 return transitiveSuperTypes; 106 } 107 108 111 public boolean isPersistent(String type) { 112 MarkerTypeDefinition def = (MarkerTypeDefinition) definitions.get(type); 113 return def != null && def.isPersistent; 114 } 115 116 119 public boolean isSubtype(String type, String superType) { 120 if (type.equals(superType)) 122 return true; 123 MarkerTypeDefinition def = (MarkerTypeDefinition) definitions.get(type); 124 return def != null && def.superTypes != null && def.superTypes.contains(superType); 125 } 126 127 private void loadDefinitions() { 128 IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PT_MARKERS); 129 IExtension[] types = point.getExtensions(); 130 definitions = new HashMap(types.length); 131 for (int i = 0; i < types.length; i++) 132 definitions.put(types[i].getUniqueIdentifier().intern(), new MarkerTypeDefinition(types[i])); 133 } 134 } 135 | Popular Tags |