Skip to content

Commit

Permalink
Isolate access to CompletionEngine in InternalCompletionProposal
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
Rob Stryker authored and rgrunber committed Jan 22, 2025
1 parent 15f22d4 commit 8050026
Showing 1 changed file with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ protected char[][] findConstructorParameterNames(char[] declaringTypePackageName
int length = paramTypeNames.length;

char[] tName = CharOperation.concat(declaringTypePackageName,declaringTypeName,'.');
Object cachedType = this.completionEngine.typeCache.get(tName);
Object cachedType = getFromEngineTypeCache(tName);

IType type = null;
if(cachedType != null) {
Expand All @@ -226,7 +226,7 @@ protected char[][] findConstructorParameterNames(char[] declaringTypePackageName
null);
type = answer == null ? null : answer.type;
if(type instanceof BinaryType){
this.completionEngine.typeCache.put(tName, type);
addToCompletionEngineTypeCache(tName, type);
} else {
type = null;
}
Expand All @@ -242,14 +242,15 @@ protected char[][] findConstructorParameterNames(char[] declaringTypePackageName

IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot)type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
if (packageFragmentRoot.isArchive() ||
this.completionEngine.openedBinaryTypes < getOpenedBinaryTypesThreshold()) {
getOpenedBinaryTypesCount() < getOpenedBinaryTypesThreshold()) {
SourceMapper mapper = ((JavaElement)method).getSourceMapper();
if (mapper != null) {
char[][] paramNames = mapper.getMethodParameterNames(method);

// map source and try to find parameter names
if(paramNames == null) {
if (!packageFragmentRoot.isArchive()) this.completionEngine.openedBinaryTypes++;
if (!packageFragmentRoot.isArchive())
incrementOpenedBinaryTypesCount();
IBinaryType info = ((BinaryType) type).getElementInfo();
char[] source = mapper.findSource(type, info);
if (source != null){
Expand Down Expand Up @@ -290,14 +291,30 @@ this.completionEngine.openedBinaryTypes < getOpenedBinaryTypesThreshold()) {
return parameters;
}

protected void incrementOpenedBinaryTypesCount() {
this.completionEngine.openedBinaryTypes++;
}

protected int getOpenedBinaryTypesCount() {
return this.completionEngine.openedBinaryTypes;
}

protected void addToCompletionEngineTypeCache(char[] tName, IType type) {
this.completionEngine.typeCache.put(tName, type);
}

protected Object getFromEngineTypeCache(char[] tName) {
return this.completionEngine.typeCache.get(tName);
}

protected char[][] findMethodParameterNames(char[] declaringTypePackageName, char[] declaringTypeName, char[] selector, char[][] paramTypeNames){
if(paramTypeNames == null || declaringTypeName == null) return null;

char[][] parameters = null;
int length = paramTypeNames.length;

char[] tName = CharOperation.concat(declaringTypePackageName,declaringTypeName,'.');
Object cachedType = this.completionEngine.typeCache.get(tName);
Object cachedType = getFromEngineTypeCache(tName);

IType type = null;
if(cachedType != null) {
Expand All @@ -316,7 +333,7 @@ protected char[][] findMethodParameterNames(char[] declaringTypePackageName, cha
null);
type = answer == null ? null : answer.type;
if(type instanceof BinaryType){
this.completionEngine.typeCache.put(tName, type);
addToCompletionEngineTypeCache(tName, type);
} else {
type = null;
}
Expand Down

0 comments on commit 8050026

Please sign in to comment.