* @return
*/
public static Map<String, IMethod> getImportedMethods(IType type) {
Map<String, IMethod> ret = new HashMap<String, IMethod>();
UseTrait parsed = TraitUtils.parse(type);
IDLTKSearchScope scope = TraitUtils.createSearchScope(type);
Map<String, IType> traits = new HashMap<String, IType>();
Set<String> usedMethods = new HashSet<String>();
for (String traitName : parsed.getTraits()) {
if (findType(type.getSourceModule(), traitName) != null) {
traits.put(traitName, findType(type.getSourceModule(), traitName)); // out of index
continue;
}
IType[] traitTypes = PhpModelAccess.getDefault().findTraits(traitName, MatchRule.EXACT, 0, 0, scope, new NullProgressMonitor());
if (traitTypes.length != 1) {
continue; //more than one ignore it
}
traits.put(traitName, traitTypes[0]);
}
if (traits.size() == 0) {
return ret;
}
//load aliases
for (TraitAliasObject alias : parsed.getTraitAliases()) {
IType trait = traits.get(alias.traitName);
if (trait == null) {
continue;
}
IMethod[] methods;
try {
methods = PHPModelUtils.getTypeMethod(trait, alias.traitMethodName, true);
if (methods.length != 1) {
continue;
}
usedMethods.add(alias.traitName + "::" + alias.traitMethodName);
ret.put(alias.newMethodName, methods[0]);
} catch (ModelException e) {
Logger.logException(e);
}
}
//load precedences
for (Entry<String, TraitPrecedenceObject> entry : parsed.getPrecedenceMap().entrySet()) {
IType trait = traits.get(entry.getValue().traitName);
if (trait == null) {
continue;
}