Skip to content

Commit

Permalink
retain bindings for synthetic property methods
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Aug 10, 2020
1 parent c3c06da commit fd3747c
Show file tree
Hide file tree
Showing 19 changed files with 238 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,12 +510,10 @@ final class SemanticHighlightingTests extends GroovyEclipseTestSuite {
|class Impl implements Face<Pogo> {
| Pogo item = new Pogo()
|}
|'''.stripMargin(), 'Impl'
addGroovySource '''\
|class Pogo {
| def prop
|}
|'''.stripMargin(), 'Pogo'
|'''.stripMargin(), 'Impl'

String contents = '''\
|@groovy.transform.TypeChecked
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2016 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,7 @@
* is determined to be a LazilyResolvedMethodBinding - we ask it for the parameter and return
* types which it determines from the field binding for the property. The key benefit here is that
* the parameter/return type bindings are not chased down unless required.
*
*
* @author Andy Clement
*/
public class LazilyResolvedMethodBinding extends MethodBinding {
Expand All @@ -35,36 +35,42 @@ public class LazilyResolvedMethodBinding extends MethodBinding {
private String propertyName;

public LazilyResolvedMethodBinding(boolean isGetter, String propertyName, int modifiers, char[] selector, ReferenceBinding[] thrownExceptions, ReferenceBinding declaringClass) {
super(modifiers| ExtraCompilerModifiers.AccUnresolved,selector,null,null,thrownExceptions,declaringClass);
super(modifiers | ExtraCompilerModifiers.AccUnresolved, selector, null, null, thrownExceptions, declaringClass);
this.propertyName = propertyName;
this.isGetter = isGetter;
}

/**
* Discover the type of the property and return that as the binding to use as the accessor method
* parameter/return type.
* Resolves the property type for use as the return type if this represents
* an accessor method or parameter type if this represents a mutator method.
*/
private TypeBinding getTypeBinding() {
FieldBinding fBinding = this.declaringClass.getField(this.propertyName.toCharArray(), false);
if (fBinding != null && !(fBinding.type instanceof MissingTypeBinding)) {
return fBinding.type;
private TypeBinding getPropertyTypeBinding() {
FieldBinding field = this.declaringClass.getField(this.propertyName.toCharArray(), false);
if (field != null && !(field.type instanceof MissingTypeBinding)) {
return field.type;
}
return null;
}

public TypeBinding getParameterTypeBinding() {
if (this.isGetter) {
return null;
} else {
return getTypeBinding();
TypeBinding getParameterTypeBinding() {
if (!this.isGetter) {
return getPropertyTypeBinding();
}
return null;
}

public TypeBinding getReturnTypeBinding() {
TypeBinding getReturnTypeBinding() {
if (this.isGetter) {
return getTypeBinding();
} else {
return TypeBinding.VOID;
return getPropertyTypeBinding();
}
return TypeBinding.VOID;
}

@Override
public int problemId() {
if (getPropertyTypeBinding() == null) {
return ProblemReasons.NotFound;
}
return super.problemId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,9 @@ public MethodBinding[] methods() {
}
}
}
// GROOVY add
if (method instanceof LazilyResolvedMethodBinding) continue;
// GROOVY end
if (method.returnType == null && resolvedMethods[i] != null) { // forget method with invalid return type... was kept to detect possible collisions
methodDecl = method.sourceMethod();
if (methodDecl != null)
Expand Down Expand Up @@ -1926,7 +1929,7 @@ private MethodBinding resolveTypesWithSuspendedTempErrorHandlingPolicy(MethodBin
// GROOVY edit
//if (methodDecl == null) return null; // method could not be resolved in previous iteration
if (methodDecl == null) {
if (method instanceof LazilyResolvedMethodBinding) {
if (method.problemId() == ProblemReasons.NoError && method instanceof LazilyResolvedMethodBinding) {
LazilyResolvedMethodBinding lrMethod = (LazilyResolvedMethodBinding) method;
// the rest is a copy of the code below but doesn't depend on the method declaration
// nothing to do for method type parameters (there are none)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2016 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,7 @@
* is determined to be a LazilyResolvedMethodBinding - we ask it for the parameter and return
* types which it determines from the field binding for the property. The key benefit here is that
* the parameter/return type bindings are not chased down unless required.
*
*
* @author Andy Clement
*/
public class LazilyResolvedMethodBinding extends MethodBinding {
Expand All @@ -35,36 +35,42 @@ public class LazilyResolvedMethodBinding extends MethodBinding {
private String propertyName;

public LazilyResolvedMethodBinding(boolean isGetter, String propertyName, int modifiers, char[] selector, ReferenceBinding[] thrownExceptions, ReferenceBinding declaringClass) {
super(modifiers| ExtraCompilerModifiers.AccUnresolved,selector,null,null,thrownExceptions,declaringClass);
super(modifiers | ExtraCompilerModifiers.AccUnresolved, selector, null, null, thrownExceptions, declaringClass);
this.propertyName = propertyName;
this.isGetter = isGetter;
}

/**
* Discover the type of the property and return that as the binding to use as the accessor method
* parameter/return type.
* Resolves the property type for use as the return type if this represents
* an accessor method or parameter type if this represents a mutator method.
*/
private TypeBinding getTypeBinding() {
FieldBinding fBinding = this.declaringClass.getField(this.propertyName.toCharArray(), false);
if (fBinding != null && !(fBinding.type instanceof MissingTypeBinding)) {
return fBinding.type;
private TypeBinding getPropertyTypeBinding() {
FieldBinding field = this.declaringClass.getField(this.propertyName.toCharArray(), false);
if (field != null && !(field.type instanceof MissingTypeBinding)) {
return field.type;
}
return null;
}

public TypeBinding getParameterTypeBinding() {
if (this.isGetter) {
return null;
} else {
return getTypeBinding();
TypeBinding getParameterTypeBinding() {
if (!this.isGetter) {
return getPropertyTypeBinding();
}
return null;
}

public TypeBinding getReturnTypeBinding() {
TypeBinding getReturnTypeBinding() {
if (this.isGetter) {
return getTypeBinding();
} else {
return TypeBinding.VOID;
return getPropertyTypeBinding();
}
return TypeBinding.VOID;
}

@Override
public int problemId() {
if (getPropertyTypeBinding() == null) {
return ProblemReasons.NotFound;
}
return super.problemId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,9 @@ public MethodBinding[] methods() {
}
}
}
// GROOVY add
if (method instanceof LazilyResolvedMethodBinding) continue;
// GROOVY end
if (method.returnType == null && resolvedMethods[i] != null) { // forget method with invalid return type... was kept to detect possible collisions
methodDecl = method.sourceMethod();
if (methodDecl != null)
Expand Down Expand Up @@ -1927,7 +1930,7 @@ private MethodBinding resolveTypesWithSuspendedTempErrorHandlingPolicy(MethodBin
// GROOVY edit
//if (methodDecl == null) return null; // method could not be resolved in previous iteration
if (methodDecl == null) {
if (method instanceof LazilyResolvedMethodBinding) {
if (method.problemId() == ProblemReasons.NoError && method instanceof LazilyResolvedMethodBinding) {
LazilyResolvedMethodBinding lrMethod = (LazilyResolvedMethodBinding) method;
// the rest is a copy of the code below but doesn't depend on the method declaration
// nothing to do for method type parameters (there are none)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2016 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,7 @@
* is determined to be a LazilyResolvedMethodBinding - we ask it for the parameter and return
* types which it determines from the field binding for the property. The key benefit here is that
* the parameter/return type bindings are not chased down unless required.
*
*
* @author Andy Clement
*/
public class LazilyResolvedMethodBinding extends MethodBinding {
Expand All @@ -35,36 +35,42 @@ public class LazilyResolvedMethodBinding extends MethodBinding {
private String propertyName;

public LazilyResolvedMethodBinding(boolean isGetter, String propertyName, int modifiers, char[] selector, ReferenceBinding[] thrownExceptions, ReferenceBinding declaringClass) {
super(modifiers| ExtraCompilerModifiers.AccUnresolved,selector,null,null,thrownExceptions,declaringClass);
super(modifiers | ExtraCompilerModifiers.AccUnresolved, selector, null, null, thrownExceptions, declaringClass);
this.propertyName = propertyName;
this.isGetter = isGetter;
}

/**
* Discover the type of the property and return that as the binding to use as the accessor method
* parameter/return type.
* Resolves the property type for use as the return type if this represents
* an accessor method or parameter type if this represents a mutator method.
*/
private TypeBinding getTypeBinding() {
FieldBinding fBinding = this.declaringClass.getField(this.propertyName.toCharArray(), false);
if (fBinding != null && !(fBinding.type instanceof MissingTypeBinding)) {
return fBinding.type;
private TypeBinding getPropertyTypeBinding() {
FieldBinding field = this.declaringClass.getField(this.propertyName.toCharArray(), false);
if (field != null && !(field.type instanceof MissingTypeBinding)) {
return field.type;
}
return null;
}

public TypeBinding getParameterTypeBinding() {
if (this.isGetter) {
return null;
} else {
return getTypeBinding();
TypeBinding getParameterTypeBinding() {
if (!this.isGetter) {
return getPropertyTypeBinding();
}
return null;
}

public TypeBinding getReturnTypeBinding() {
TypeBinding getReturnTypeBinding() {
if (this.isGetter) {
return getTypeBinding();
} else {
return TypeBinding.VOID;
return getPropertyTypeBinding();
}
return TypeBinding.VOID;
}

@Override
public int problemId() {
if (getPropertyTypeBinding() == null) {
return ProblemReasons.NotFound;
}
return super.problemId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,9 @@ public MethodBinding[] methods() {
}
}
}
// GROOVY add
if (method instanceof LazilyResolvedMethodBinding) continue;
// GROOVY end
if (method.returnType == null && resolvedMethods[i] != null) { // forget method with invalid return type... was kept to detect possible collisions
methodDecl = method.sourceMethod();
if (methodDecl != null)
Expand Down Expand Up @@ -1927,7 +1930,7 @@ private MethodBinding resolveTypesWithSuspendedTempErrorHandlingPolicy(MethodBin
// GROOVY edit
//if (methodDecl == null) return null; // method could not be resolved in previous iteration
if (methodDecl == null) {
if (method instanceof LazilyResolvedMethodBinding) {
if (method.problemId() == ProblemReasons.NoError && method instanceof LazilyResolvedMethodBinding) {
LazilyResolvedMethodBinding lrMethod = (LazilyResolvedMethodBinding) method;
// the rest is a copy of the code below but doesn't depend on the method declaration
// nothing to do for method type parameters (there are none)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2016 the original author or authors.
* Copyright 2009-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,7 @@
* is determined to be a LazilyResolvedMethodBinding - we ask it for the parameter and return
* types which it determines from the field binding for the property. The key benefit here is that
* the parameter/return type bindings are not chased down unless required.
*
*
* @author Andy Clement
*/
public class LazilyResolvedMethodBinding extends MethodBinding {
Expand All @@ -35,41 +35,42 @@ public class LazilyResolvedMethodBinding extends MethodBinding {
private String propertyName;

public LazilyResolvedMethodBinding(boolean isGetter, String propertyName, int modifiers, char[] selector, ReferenceBinding[] thrownExceptions, ReferenceBinding declaringClass) {
super(modifiers| ExtraCompilerModifiers.AccUnresolved,selector,null,null,thrownExceptions,declaringClass);
super(modifiers | ExtraCompilerModifiers.AccUnresolved, selector, null, null, thrownExceptions, declaringClass);
this.propertyName = propertyName;
this.isGetter = isGetter;
}

/**
* Discover the type of the property and return that as the binding to use as the accessor method
* parameter/return type.
* Resolves the property type for use as the return type if this represents
* an accessor method or parameter type if this represents a mutator method.
*/
private TypeBinding getTypeBinding() {
FieldBinding fBinding = this.declaringClass.getField(this.propertyName.toCharArray(), false);
if (fBinding != null && !(fBinding.type instanceof MissingTypeBinding)) {
return fBinding.type;
private TypeBinding getPropertyTypeBinding() {
FieldBinding field = this.declaringClass.getField(this.propertyName.toCharArray(), false);
if (field != null && !(field.type instanceof MissingTypeBinding)) {
return field.type;
}
return null;
}

public TypeBinding getParameterTypeBinding() {
if (this.isGetter) {
return null;
} else {
return getTypeBinding();
TypeBinding getParameterTypeBinding() {
if (!this.isGetter) {
return getPropertyTypeBinding();
}
return null;
}

public TypeBinding getReturnTypeBinding() {
TypeBinding getReturnTypeBinding() {
if (this.isGetter) {
return getTypeBinding();
} else {
return TypeBinding.VOID;
return getPropertyTypeBinding();
}
return TypeBinding.VOID;
}

@Override
public char[] computeUniqueKey() {
return super.computeUniqueKey();
public int problemId() {
if (getPropertyTypeBinding() == null) {
return ProblemReasons.NotFound;
}
return super.problemId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,9 @@ public MethodBinding[] methods() {
}
}
}
// GROOVY add
if (method instanceof LazilyResolvedMethodBinding) continue;
// GROOVY end
if (method.returnType == null && resolvedMethods[i] != null) { // forget method with invalid return type... was kept to detect possible collisions
methodDecl = method.sourceMethod();
if (methodDecl != null)
Expand Down Expand Up @@ -1957,7 +1960,7 @@ private MethodBinding resolveTypesWithSuspendedTempErrorHandlingPolicy(MethodBin
// GROOVY edit
//if (methodDecl == null) return null; // method could not be resolved in previous iteration
if (methodDecl == null) {
if (method instanceof LazilyResolvedMethodBinding) {
if (method.problemId() == ProblemReasons.NoError && method instanceof LazilyResolvedMethodBinding) {
LazilyResolvedMethodBinding lrMethod = (LazilyResolvedMethodBinding) method;
// the rest is a copy of the code below but doesn't depend on the method declaration
// nothing to do for method type parameters (there are none)
Expand Down
Loading

0 comments on commit fd3747c

Please sign in to comment.