Skip to content

Commit

Permalink
Initial work to separate out the interfaces at play in completion eng…
Browse files Browse the repository at this point in the history
…ine and parser
  • Loading branch information
Rob Stryker committed Jan 30, 2024
1 parent 69a3085 commit 86921b2
Show file tree
Hide file tree
Showing 19 changed files with 15,139 additions and 14,741 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnQualifiedTypeReference;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleTypeReference;
import org.eclipse.jdt.internal.codeassist.complete.ICompletionParserFacade;
import org.eclipse.jdt.internal.codeassist.impl.AssistAnnotation;
import org.eclipse.jdt.internal.codeassist.impl.AssistImportContainer;
import org.eclipse.jdt.internal.codeassist.impl.AssistImportDeclaration;
Expand All @@ -45,7 +46,6 @@
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.env.IElementInfo;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.parser.Parser;
import org.eclipse.jdt.internal.core.AnnotatableInfo;
import org.eclipse.jdt.internal.core.Annotation;
import org.eclipse.jdt.internal.core.CompilationUnit;
Expand All @@ -72,7 +72,7 @@ public class CompletionUnitStructureRequestor extends CompilationUnitStructureRe
public CompletionUnitStructureRequestor(
ICompilationUnit unit,
CompilationUnitElementInfo unitInfo,
Parser parser,
ICompletionParserFacade parser,
ASTNode assistNode,
Map<JavaElement, Binding> bindingCache,
Map<Binding, JavaElement> elementCache,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.codeassist;

import org.eclipse.jdt.internal.compiler.util.HashtableOfObject;

public interface ICompletionEngine {
public HashtableOfObject getTypeCache();
public int getOpenedBinaryTypes();
public void incrementOpenedBinaryTypes();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright (c) 2004, 2006 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.codeassist;

import org.eclipse.jdt.internal.codeassist.MissingTypesGuesser.GuessedTypeRequestor;
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.lookup.Scope;

public interface IMissingTypesGuesser {
public void guess(TypeReference typeRef, Scope scope, GuessedTypeRequestor requestor);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.eclipse.jdt.internal.codeassist;

import org.eclipse.jdt.internal.codeassist.UnresolvedReferenceNameFinder.UnresolvedReferenceNameRequestor;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Initializer;
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
import org.eclipse.jdt.internal.compiler.lookup.Scope;

public interface IUnresolvedReferenceNameFinder {

public void find(char[] startWith, Initializer initializer, ClassScope scope, int from, char[][] discouragedNames,
UnresolvedReferenceNameRequestor nameRequestor);

public void find(char[] startWith, AbstractMethodDeclaration methodDeclaration, int from, char[][] discouragedNames,
UnresolvedReferenceNameRequestor nameRequestor);

public void findAfter(char[] startWith, Scope scope, ClassScope classScope, int from, int to,
char[][] discouragedNames, UnresolvedReferenceNameRequestor nameRequestor);

public void findBefore(char[] startWith, Scope scope, ClassScope classScope, int from, int recordTo, int parseTo,
char[][] discouragedNames, UnresolvedReferenceNameRequestor nameRequestor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.eclipse.jdt.core.ITypeRoot;
import org.eclipse.jdt.core.WorkingCopyOwner;
import org.eclipse.jdt.internal.codeassist.complete.CompletionOnJavadoc;
import org.eclipse.jdt.internal.codeassist.complete.CompletionParser;
import org.eclipse.jdt.internal.codeassist.complete.ICompletionParserFacade;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.lookup.FieldBinding;
Expand Down Expand Up @@ -68,7 +68,7 @@ protected void setExtendedData(
ASTNode astNode,
ASTNode astNodeParent,
WorkingCopyOwner owner,
CompletionParser parser) {
ICompletionParserFacade parser) {
this.isExtended = true;
this.extendedContext =
new InternalExtendedCompletionContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
public class InternalCompletionProposal extends CompletionProposal {
private static Object NO_ATTACHED_SOURCE = new Object();

protected CompletionEngine completionEngine;
protected ICompletionEngine completionEngine;
protected NameLookup nameLookup;

protected char[] declarationPackageName;
Expand Down Expand Up @@ -217,7 +217,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 = this.completionEngine.getTypeCache().get(tName);

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

IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot)type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
if (packageFragmentRoot.isArchive() ||
this.completionEngine.openedBinaryTypes < getOpenedBinaryTypesThreshold()) {
this.completionEngine.getOpenedBinaryTypes() < 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()) {
this.completionEngine.incrementOpenedBinaryTypes();
}
IBinaryType info = ((BinaryType) type).getElementInfo();
char[] source = mapper.findSource(type, info);
if (source != null){
Expand Down Expand Up @@ -307,7 +309,7 @@ protected char[][] findMethodParameterNames(char[] declaringTypePackageName, cha
int length = paramTypeNames.length;

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

IType type = null;
if(cachedType != null) {
Expand All @@ -326,7 +328,7 @@ protected char[][] findMethodParameterNames(char[] declaringTypePackageName, cha
null);
type = answer == null ? null : answer.type;
if(type instanceof BinaryType){
this.completionEngine.typeCache.put(tName, type);
this.completionEngine.getTypeCache().put(tName, type);
} else {
type = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.eclipse.jdt.core.WorkingCopyOwner;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.internal.codeassist.complete.CompletionNodeDetector;
import org.eclipse.jdt.internal.codeassist.complete.CompletionParser;
import org.eclipse.jdt.internal.codeassist.complete.ICompletionParserFacade;
import org.eclipse.jdt.internal.codeassist.impl.AssistCompilationUnit;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
Expand Down Expand Up @@ -90,7 +90,7 @@ public ASTNode get(Binding binding) {
private final ASTNode assistNodeParent;
private final WorkingCopyOwner owner;

private final CompletionParser parser;
private final ICompletionParserFacade parser;

// computed data
private boolean hasComputedVisibleElementBindings;
Expand All @@ -112,7 +112,7 @@ public InternalExtendedCompletionContext(
ASTNode assistNode,
ASTNode assistNodeParent,
WorkingCopyOwner owner,
CompletionParser parser) {
ICompletionParserFacade parser) {
this.completionContext = completionContext;
this.typeRoot = typeRoot;
this.compilationUnitDeclaration = compilationUnitDeclaration;
Expand Down Expand Up @@ -164,7 +164,7 @@ private void computeEnclosingJavaElements() {
this.compilationUnitDeclaration.sourceStart,
this.compilationUnitDeclaration.sourceEnd,
false,
this.parser.sourceEnds,
this.parser.getSourceEnds(),
new HashMap<>());

this.bindingsToHandles = bindingToHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.eclipse.jdt.internal.core.SearchableEnvironment;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class MissingTypesGuesser extends ASTVisitor {
public class MissingTypesGuesser extends ASTVisitor implements IMissingTypesGuesser {
public static interface GuessedTypeRequestor {
public void accept(
TypeBinding guessedType,
Expand Down Expand Up @@ -535,6 +535,7 @@ private char[][][] getSubstitution(TypeReference typeRef) {
return (char[][][])this.substituedTypes.get(typeRef);
}

@Override
public void guess(TypeReference typeRef, Scope scope, GuessedTypeRequestor requestor) {
this.substituedTypes = new HashMap();
this.originalTypes = new HashMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
import org.eclipse.jdt.internal.codeassist.impl.Engine;
import org.eclipse.jdt.internal.codeassist.select.SelectionJavadocParser;
import org.eclipse.jdt.internal.codeassist.select.SelectionNodeFound;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnPackageVisibilityReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnImportReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnLambdaExpression;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnLocalName;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnMessageSend;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnPackageReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnPackageVisibilityReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnQualifiedTypeReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionOnSingleTypeReference;
import org.eclipse.jdt.internal.codeassist.select.SelectionParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.eclipse.jdt.internal.compiler.util.SimpleSetOfCharArray;
import org.eclipse.jdt.internal.compiler.util.Util;

public class UnresolvedReferenceNameFinder extends ASTVisitor {
public class UnresolvedReferenceNameFinder extends ASTVisitor implements IUnresolvedReferenceNameFinder {
private static final int MAX_LINE_COUNT = 100;
private static final int FAKE_BLOCKS_COUNT = 20;

Expand All @@ -58,10 +58,10 @@ public static interface UnresolvedReferenceNameRequestor {

private final SimpleSetOfCharArray acceptedNames = new SimpleSetOfCharArray();

public UnresolvedReferenceNameFinder(CompletionEngine completionEngine) {
public UnresolvedReferenceNameFinder(CompletionEngine completionEngine, CompletionParser completionParser) {
this.completionEngine = completionEngine;
this.parser = completionEngine.parser;
this.completionScanner = (CompletionScanner) this.parser.scanner;
this.parser = completionParser;
this.completionScanner = (CompletionScanner) this.parser.getScanner();
}

private void acceptName(char[] name) {
Expand All @@ -79,6 +79,7 @@ private void acceptName(char[] name) {
this.requestor.acceptName(name);
}

@Override
public void find(
char[] startWith,
Initializer initializer,
Expand All @@ -91,6 +92,7 @@ public void find(
if (fakeMethod != null) fakeMethod.traverse(this, scope);
}

@Override
public void find(
char[] startWith,
AbstractMethodDeclaration methodDeclaration,
Expand All @@ -102,6 +104,7 @@ public void find(
if (fakeMethod != null) fakeMethod.traverse(this, methodDeclaration.scope.classScope());
}

@Override
public void findAfter(
char[] startWith,
Scope scope,
Expand Down Expand Up @@ -169,6 +172,7 @@ private MethodDeclaration findAfter(
return fakeMethod;
}

@Override
public void findBefore(
char[] startWith,
Scope scope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt;
import org.eclipse.jdt.internal.compiler.util.Util;

public class CompletionParser extends AssistParser {
public class CompletionParser extends AssistParser implements ICompletionParserFacade {
// OWNER
protected static final int COMPLETION_PARSER = 1024;
protected static final int COMPLETION_OR_ASSIST_PARSER = ASSIST_PARSER + COMPLETION_PARSER;
Expand Down Expand Up @@ -6453,4 +6453,34 @@ protected boolean isInModuleStatements() {
isInProvidesStatement() ||
isInUsesStatement();
}
@Override
public HashtableOfObjectToInt getSourceEnds() {
// TODO Auto-generated method stub
return null;
}
@Override
public Scanner getScanner() {
return this.scanner;
}
@Override
public CompilationUnitDeclaration parseCompilationUnitDeclaration(ICompilationUnit sourceUnit, CompilationResult result,
int actualCompletionPosition2) {
return this.dietParse(sourceUnit, result, actualCompletionPosition2);
}
@Override
public ASTNode getEnclosingNode() {
return this.enclosingNode;
}
@Override
public ASTNode getAssistNodeParent() {
return this.assistNodeParent;
}
@Override
public ASTNode getAssistNode() {
return this.assistNode;
}
@Override
public void setEnclosingNode(ASTNode enclosing) {
this.enclosingNode = enclosing;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.codeassist.complete;

import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.util.HashtableOfObjectToInt;

/**
* The purpose of this interface is to isolate how various internal classes
* are using the parser, and to allow for drop-in replacements of different parser
* implementations while conforming to the same interface.
*/
public interface ICompletionParserFacade extends IScannerProvider {

HashtableOfObjectToInt getSourceEnds();

CompilationUnitDeclaration parseCompilationUnitDeclaration(ICompilationUnit sourceUnit,
CompilationResult result, int actualCompletionPosition2);

ASTNode getEnclosingNode();
ASTNode getAssistNodeParent();
ASTNode getAssistNode();
void setEnclosingNode(ASTNode providesStmt);
}
Loading

0 comments on commit 86921b2

Please sign in to comment.