/** * Resolves a reference from within this module to a symbol in the same module, an imported module * or in the whole mib * * @param idToken Token of the identifier that has to be resolved. * @param reporter If not null, the reporter will be used to reporter the not found error message. * @return The symbol that was found, or null. */ public SmiSymbol resolveReference(IdToken idToken, XRefProblemReporter reporter) { // doesn't work anymore with hardcoded missing symbols // if (!idToken.getLocation().getSource().equals(getIdToken().getLocation().getSource())) // { // // note this check is not entirely fool-proof in case multiple modules are located // in one file // throw new IllegalArgumentException("Resolving references is only allowed from // inside the same module"); // } SmiSymbol result = findSymbol(idToken.getId()); if (result == null) { result = findImportedSymbol(idToken.getId()); } if (result == null) { List<SmiSymbol> symbols = getMib().getSymbols().findAll(idToken.getId()); if (symbols.size() == 1) { result = symbols.get(0); } else if (symbols.size() > 0) { result = determineBestMatch(idToken, symbols); } } if (result == null && reporter != null) { reporter.reportCannotFindSymbol(idToken); } return result; }
public <T extends SmiSymbol> T resolveReference( IdToken idToken, Class<T> expectedClass, XRefProblemReporter reporter) { SmiSymbol result = resolveReference(idToken, reporter); if (result != null) { if (expectedClass.isInstance(result)) { return expectedClass.cast(result); } else { reporter.reportFoundSymbolButWrongType(idToken, expectedClass, result.getClass()); } } return null; }