public List<BindingValueKey> getBindingValueMutatorKeys(IJavaProject javaProject, String name) throws JavaModelException { synchronized (_bindingValueMutatorKeys) { List<BindingValueKey> bindingValueMutatorKeys = _bindingValueMutatorKeys.get(name); if (bindingValueMutatorKeys == null) { // System.out.println("TypeCache.getBindingValueMutatorKeys: MISS " + // type.getElementName() + ": " + name); bindingValueMutatorKeys = BindingReflectionUtils.getBindingKeys( javaProject, _type, name, true, BindingReflectionUtils.MUTATORS_ONLY, false, TypeCache.this); // MS: Don't cache this for now -- I don't know how many end up in here and how long they // hang around, but I think the answer is "a lot" and "for a long time". However, it's a // huge performance win. // Q: Don't cache results from types with generic type parameters if (_type.getTypeParameters().length == 0 || bindingValueMutatorKeys.size() == 0) { _bindingValueMutatorKeys.put(name, bindingValueMutatorKeys); } else { // System.out.println("TypeCacheEntry.getBindingValueMutatorKeys: not caching " + // _type.getElementName() + ": " + name); } } else { // System.out.println("TypeCache.getBindingValueMutatorKeys: HIT " + // _type.getElementName() + ": " + name); } return bindingValueMutatorKeys; } }
public IType getTypeForName(String typeName) throws JavaModelException { // long a = System.currentTimeMillis(); IType type; if ("void".equals(typeName) || (typeName != null && typeName.length() == 1)) { // ignore primitives type = null; } else { synchronized (_nextTypeCache) { type = _nextTypeCache.get(typeName); } if (type == null) { // long t = System.currentTimeMillis(); // MS: This call right here is the DEVIL. This is BY FAR where the // majority of time is spent during component validation. It's also // unfortunately completely necessary, but caching should focus on // this in the future. // String resolvedNextTypeName = JavaModelUtil.getResolvedTypeName(typeName, _type); type = resolveType(typeName, _type); if (type == null) { // We are going to hit KVCProtectedAccessor a LOT, and in most cases, it's just not // going to exist, so let's save us all some trouble and skip it ... if (!"QKeyValueCodingProtectedAccessor;".equals(typeName)) { System.out.println( "TypeCacheEntry.getTypeForName: Failed to resolve type name " + typeName + " in component " + _type.getElementName()); } else if (BindingReflectionUtils.isPrimitive(typeName)) { // ignore primitives if we get this far } } else { synchronized (_nextTypeCache) { _nextTypeCache.put(typeName, type); } } } // System.out.println("TypeCacheEntry.getTypeForName: " + typeName + " => " + // (System.currentTimeMillis() - t) + " => " + type); } // if (System.currentTimeMillis() -a > 0) { // System.out.println("TypeCache.TypeCacheEntry.getTypeForName: " + type.getElementName() + " // " + (System.currentTimeMillis() - a)); // } return type; }
protected String chooseSuperclass() { Set<String> superclasses = new HashSet<String>(); try { IProject actualProject = ResourcesPlugin.getWorkspace().getRoot().getProject(getContainerFullPath().segment(0)); IJavaProject javaProject = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProject(actualProject); TypeNameCollector typeNameCollector = new TypeNameCollector(javaProject, false); BindingReflectionUtils.findMatchingElementClassNames( "", SearchPattern.R_PREFIX_MATCH, typeNameCollector, new NullProgressMonitor()); for (String typeName : typeNameCollector.getTypeNames()) { // int dotIndex = typeName.lastIndexOf('.'); // if (dotIndex != -1) { // typeName = typeName.substring(dotIndex + 1); // } // validValues.add("\"" + typeName + "\""); superclasses.add(typeName); } } catch (JavaModelException e) { // JTourBusPlugin.log(e); e.printStackTrace(); } ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new StringLabelProvider()); dialog.setIgnoreCase(true); dialog.setTitle(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_title); dialog.setMessage(NewWizardMessages.NewTypeWizardPage_SuperClassDialog_message); // dialog.setEmptyListMessage(NewWizardMessages.NewTypeWiz); dialog.setFilter(_superclassDialogField.getText()); dialog.setElements(superclasses.toArray()); if (dialog.open() == Window.OK) { return (String) dialog.getFirstResult(); } return null; }