Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax highlight is broken after accessing filed in grails config #976

Closed
AntonPanikov opened this issue Oct 22, 2019 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@AntonPanikov
Copy link

I was unable to re-produce it with pure groovy, but with simple grails it is working:

  • create simple empty grails app (using sdkman)
  • inject GrailsApplication
  • access any field in config
  • syntax highlight will be broken in the current method after that till the end of this method

Sample:

package grails.sample

import grails.core.GrailsApplication

class SampleService {
    
    GrailsApplication grailsApplication
    
    def some() {
        if (true) {
            String var = 'qwe'
            println 'ok'
        }
        grailsApplication.config
        if (true) {
            String var = 'qwe'
            println 'still ok'
        }
        grailsApplication.config.some
        if (false) {
            String var = 'qwe'
            println 'fail'
        }
    }

}

groovy_syntax_highlight

Stack trace from error log:
eclipse.buildId=4.11.0.I20190307-0500
java.version=1.8.0_131
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments:  -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.jee.product

This is a continuation of log file /ptmp/workspace/.metadata/.bak_0.log
Created Time: 2019-10-21 18:10:00.441

org.eclipse.jdt.groovy.core
Error
Tue Oct 22 13:05:45 EDT 2019
Groovy-Eclipse Type Inferencing: Error visiting method some in class SampleService

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:653)
	at java.util.ArrayList.get(ArrayList.java:429)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.lookupExpressionType(TypeInferencingVisitorWithRequestor.java:2521)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.handleSimpleExpression(TypeInferencingVisitorWithRequestor.java:1869)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.handleSimpleExpression(TypeInferencingVisitorWithRequestor.java:1874)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitConstantExpression(TypeInferencingVisitorWithRequestor.java:967)
	at org.codehaus.groovy.ast.expr.ConstantExpression.visit(ConstantExpression.java:84)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitPropertyExpression(TypeInferencingVisitorWithRequestor.java:1538)
	at org.codehaus.groovy.ast.expr.PropertyExpression.visit(PropertyExpression.java:57)
	at org.codehaus.groovy.ast.CodeVisitorSupport.visitExpressionStatement(CodeVisitorSupport.java:120)
	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitExpressionStatement(ClassCodeVisitorSupport.java:266)
	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
	at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:86)
	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:236)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitBlockStatement(TypeInferencingVisitorWithRequestor.java:823)
	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71)
	at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:145)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitConstructorOrMethod(TypeInferencingVisitorWithRequestor.java:1068)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitMethodInternal(TypeInferencingVisitorWithRequestor.java:624)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitJDT(TypeInferencingVisitorWithRequestor.java:448)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitJDT(TypeInferencingVisitorWithRequestor.java:339)
	at org.eclipse.jdt.groovy.search.TypeInferencingVisitorWithRequestor.visitCompilationUnit(TypeInferencingVisitorWithRequestor.java:246)
	at org.codehaus.groovy.eclipse.codebrowsing.requestor.CodeSelectHelper.select(CodeSelectHelper.java:84)
	at org.codehaus.jdt.groovy.model.GroovyCompilationUnit.codeSelect(GroovyCompilationUnit.java:506)
	at org.codehaus.jdt.groovy.model.GroovyCompilationUnit.codeSelect(GroovyCompilationUnit.java:499)
	at org.codehaus.jdt.groovy.model.GroovyCompilationUnit.codeSelect(GroovyCompilationUnit.java:493)
	at org.eclipse.recommenders.internal.rcp.JavaElementSelections.resolveJavaElementFromTypeRootInEditor(JavaElementSelections.java:138)
	at org.eclipse.recommenders.internal.rcp.JavaElementSelections.resolveJavaElementFromEditor(JavaElementSelections.java:119)
	at org.eclipse.recommenders.internal.rcp.JavaElementSelections.resolveJavaElementFromEditor(JavaElementSelections.java:102)
	at org.eclipse.recommenders.internal.rcp.JavaElementSelectionService.handleSelectionInEditor(JavaElementSelectionService.java:108)
	at org.eclipse.recommenders.internal.rcp.JavaElementSelectionService.access$1(JavaElementSelectionService.java:105)
	at org.eclipse.recommenders.internal.rcp.JavaElementSelectionService$1.run(JavaElementSelectionService.java:82)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)

I am using Eclipse Version: 2019-03 (4.11.0)
Eclipse Groovy Development Tools: 3.6.0.v201910182213-e1903

@eric-milles
Copy link
Member

Thanks for reporting. Inference engine is trying to determine expression type using generics on java.util.Map's V put(K, V) method. Not sure why the method was not available, but I'll make sure the code is safer.

        if (result.confidence == TypeConfidence.UNKNOWN && result.declaringType != null &&
                GeneralUtils.isOrImplements(result.declaringType, VariableScope.MAP_CLASS_NODE)) {
            ClassNode inferredType = VariableScope.OBJECT_CLASS_NODE;
            if (node instanceof ConstantExpression && node.getType().equals(VariableScope.STRING_CLASS_NODE)) {
                List<MethodNode> putMethods = result.declaringType.getMethods("put"); // returns the value type
                GenericsMapper mapper = GenericsMapper.gatherGenerics(result.declaringType, result.declaringType.redirect());
                inferredType = VariableScope.resolveTypeParameterization(mapper, VariableScope.clone(putMethods.get(0).getReturnType()));

@eric-milles
Copy link
Member

@AntonPanikov ready to test

@AntonPanikov
Copy link
Author

Version: 3.6.0.v201910222146-e1903
Tested: Success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants