Search in sources :

Example 6 with IEObjectDescriptionWithError

use of org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError in project n4js by eclipse.

the class ComposedMemberDescriptionWithError method initSubMessages.

/**
 * Combines error messages to one message.
 */
protected boolean initSubMessages(IEObjectDescription[] descriptions, MapOfIndexes<String> indexesPerCode) {
    // all subScopes returned same code:
    if (indexesPerCode.size() == 1 && indexesPerCode.numberOf(indexesPerCode.firstKey()) == max) {
        code = indexesPerCode.firstKey();
        int index = indexesPerCode.firstIndex(code);
        message = ((IEObjectDescriptionWithError) descriptions[index]).getMessage();
        String scopeName = getNameForSubScope(index);
        message.replace(scopeName, "all types");
        return true;
    }
    if (indexesPerCode.size() > 0) {
        StringBuilder strb = new StringBuilder();
        for (String subCode : indexesPerCode.keySet()) {
            int index = indexesPerCode.firstIndex(subCode);
            IEObjectDescriptionWithError descrWithError = (IEObjectDescriptionWithError) descriptions[index];
            String submessage = descrWithError.getMessage();
            String scopeName = getNameForSubScope(index);
            String allScopeNames = indexesPerCode.getScopeNamesForKey(subCode);
            String completeSubMessage;
            if (submessage.contains(scopeName)) {
                completeSubMessage = submessage.replace(scopeName, allScopeNames);
            } else {
                if (submessage.endsWith(".")) {
                    submessage = submessage.substring(0, submessage.length() - 1);
                }
                completeSubMessage = IssueCodes.getMessageForCOMP_SUBMESSAGES(allScopeNames, submessage);
            }
            if (strb.length() > 0) {
                strb.append(" ");
            }
            strb.append(completeSubMessage);
        }
        message = strb.toString();
        code = IssueCodes.COMP_SUBMESSAGES;
        return true;
    }
    return false;
}
Also used : IEObjectDescriptionWithError(org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError)

Aggregations

IEObjectDescriptionWithError (org.eclipse.n4js.xtext.scoping.IEObjectDescriptionWithError)6 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)5 QualifiedName (org.eclipse.xtext.naming.QualifiedName)4 IScope (org.eclipse.xtext.scoping.IScope)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 EObject (org.eclipse.emf.ecore.EObject)1 UnresolvableObjectDescription (org.eclipse.n4js.scoping.utils.UnresolvableObjectDescription)1 TField (org.eclipse.n4js.ts.types.TField)1