uqbar-project / wollok

Wollok Programming Language
GNU General Public License v3.0
60 stars 16 forks source link

Weird warnings on rename #712

Open flbulgarelli opened 8 years ago

flbulgarelli commented 8 years ago

If I try to rename the following baz2 method to baz:

object foo {

    method baz2() {
        var x = 9
        return x * 3 + 7
    }
}

program abc {
    console.println(null + "hello")
}   

I get the following bad warnings:

wollokrename

But there are no such syntax errors!

PS: it also shows a missconfigured language message, related to #674

fdodino commented 7 years ago

Related to #697

It happens because RefactoringCrossReferenceSerializer is checking whether new name has correct syntax.

    public String getCrossRefText(EObject owner, CrossReference crossref, EObject target,
            RefTextEvaluator refTextEvaluator, ITextRegion linkTextRegion, StatusWrapper status) {
        try {
            final EReference ref = GrammarUtil.getReference(crossref, owner.eClass());
            final IScope scope = scopeProvider.getScope(owner, ref);
            if (scope == null) {
                throw new IllegalStateException("Could not create scope for the given cross reference.");
            }
            String ruleName = linkingHelper.getRuleNameFrom(crossref);

            Iterable<IEObjectDescription> descriptionsForCrossRef = scope.getElements(target);
            String bestRefText = null;
            for (IEObjectDescription desc : descriptionsForCrossRef) {
                try {
                    String unconvertedRefText = qualifiedNameConverter.toString(desc.getName());
                    String convertedRefText = valueConverter.toString(unconvertedRefText, ruleName);
                    if (refTextEvaluator.isValid(desc) && (bestRefText == null || refTextEvaluator.isBetterThan(convertedRefText, bestRefText)))
                        bestRefText = convertedRefText;
                } catch (ValueConverterException e) {
                    status.add(RefactoringStatus.WARNING,
                            "Missconfigured language: New reference text has invalid syntax.", owner, linkTextRegion);
                }
            }
            return bestRefText;

        } catch (Exception exc) {
            log.error(exc.getMessage(), exc);
            status.add(ERROR, exc.getMessage(), owner, linkTextRegion);
            return null;
        }
    }

The problem is here: scope.getElements(target); you probably get in this case a list: [x, foo.x] (or something similar). It works in the first case (that's why rename occurs), but afterwards you get several warnings, one for each indirection in the list (character "." makes it fail, because it doesn't conform a valid ID rule). @tesonep I don't know if we can override scope for WollokGlobalScopeProvider.

fdodino commented 7 years ago

Hi @tesonep , tried to talk to you, maybe tomorrow, I was able to fix this warning by commenting parent elements from Wollok import scope:

    override getElements(EObject object) {
        synchronized (this) {
            val localElementsFound = if(localElements === null) #[] else localElements.getExportedObjectsByObject(object)
            localElementsFound //+ parent.getElements(object)
        }
    }

See parent.getElements(object). I imported current TP and it seems to work, but it scares me to put such major change before deploy.