Skip to content

Commit

Permalink
Change javac bundle to plugin and make use of compilationUnitResolver…
Browse files Browse the repository at this point in the history
… extension point

Signed-off-by: Rob Stryker <[email protected]>

Fix merge issue

Signed-off-by: Rob Stryker <[email protected]>
  • Loading branch information
Rob Stryker committed Jun 11, 2024
1 parent 183d681 commit 2fca795
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 250 deletions.
11 changes: 7 additions & 4 deletions org.eclipse.jdt.core.javac/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Javac
Bundle-SymbolicName: org.eclipse.jdt.core.javac
Bundle-SymbolicName: org.eclipse.jdt.core.javac;singleton:=true
Bundle-Version: 1.0.0.qualifier
Fragment-Host: org.eclipse.jdt.core
Automatic-Module-Name: org.eclipse.jdt.core.javac
Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=22))"
Import-Package: org.eclipse.jdt.core.dom
Export-Package: org.eclipse.jdt.internal.javac;x-friends:="org.eclipse.jdt.core.tests.javac",
org.eclipse.jdt.internal.javac.dom;x-friends:="org.eclipse.jdt.core.tests.javac"
Require-Bundle: org.eclipse.jdt.core;bundle-version="3.38.100",
org.eclipse.core.runtime;bundle-version="3.31.0",
org.eclipse.core.resources;bundle-version="3.20.200",
org.eclipse.jface.text;bundle-version="3.25.100"
Export-Package: org.eclipse.jdt.internal.javac;manipulation=split;mandatory:=manipulation;x-friends:="org.eclipse.jdt.core.tests.javac",
org.eclipse.jdt.internal.javac.dom;manipulation=split;mandatory:=manipulation;x-friends:="org.eclipse.jdt.core.tests.javac"
12 changes: 12 additions & 0 deletions org.eclipse.jdt.core.javac/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.jdt.core.compilationUnitResolver">
<resolver
class="org.eclipse.jdt.internal.javac.dom.JavacCompilationUnitResolver"
id="org.eclipse.jdt.core.dom.JavacCompilationUnitResolver">
</resolver>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.JavacBindingResolver;

import com.sun.tools.javac.code.Attribute.Compound;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.jdt.core.dom;
package org.eclipse.jdt.internal.javac.dom;

import java.io.IOException;
import java.util.Arrays;
Expand All @@ -21,14 +21,44 @@

import org.eclipse.core.runtime.ILog;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.javac.dom.JavacAnnotationBinding;
import org.eclipse.jdt.internal.javac.dom.JavacMemberValuePairBinding;
import org.eclipse.jdt.internal.javac.dom.JavacMethodBinding;
import org.eclipse.jdt.internal.javac.dom.JavacModuleBinding;
import org.eclipse.jdt.internal.javac.dom.JavacPackageBinding;
import org.eclipse.jdt.internal.javac.dom.JavacTypeBinding;
import org.eclipse.jdt.internal.javac.dom.JavacTypeVariableBinding;
import org.eclipse.jdt.internal.javac.dom.JavacVariableBinding;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
import org.eclipse.jdt.core.dom.BindingResolver;
import org.eclipse.jdt.core.dom.ClassInstanceCreation;
import org.eclipse.jdt.core.dom.ConstructorInvocation;
import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
import org.eclipse.jdt.core.dom.EnumDeclaration;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.FieldAccess;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.IBinding;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.IModuleBinding;
import org.eclipse.jdt.core.dom.IPackageBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.eclipse.jdt.core.dom.LambdaExpression;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.core.dom.MethodReference;
import org.eclipse.jdt.core.dom.ModuleDeclaration;
import org.eclipse.jdt.core.dom.Name;
import org.eclipse.jdt.core.dom.PackageDeclaration;
import org.eclipse.jdt.core.dom.ParameterizedType;
import org.eclipse.jdt.core.dom.PrimitiveType;
import org.eclipse.jdt.core.dom.RecordDeclaration;
import org.eclipse.jdt.core.dom.SimpleName;
import org.eclipse.jdt.core.dom.SimpleType;
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
import org.eclipse.jdt.core.dom.SuperFieldAccess;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.TypeParameter;
import org.eclipse.jdt.core.dom.VariableDeclaration;

import com.sun.source.util.JavacTask;
import com.sun.tools.javac.code.Attribute;
Expand Down Expand Up @@ -79,7 +109,7 @@ public class JavacBindingResolver extends BindingResolver {
private Map<Symbol, ASTNode> symbolToDom;
public final IJavaProject javaProject;
private JavacConverter converter;
boolean isRecoveringBindings = false;
public boolean isRecoveringBindings = false;

public class Bindings {
private Map<String, JavacAnnotationBinding> annotationBindings = new HashMap<>();
Expand Down Expand Up @@ -233,7 +263,7 @@ private Optional<Symbol> symbol(JCTree value) {
}

@Override
ITypeBinding resolveType(Type type) {
public ITypeBinding resolveType(Type type) {
resolve();
JCTree jcTree = this.converter.domToJavac.get(type);
if (jcTree instanceof JCIdent ident && ident.type != null) {
Expand Down Expand Up @@ -280,7 +310,7 @@ ITypeBinding resolveType(Type type) {
}

@Override
ITypeBinding resolveType(AnnotationTypeDeclaration type) {
public ITypeBinding resolveType(AnnotationTypeDeclaration type) {
resolve();
JCTree javacNode = this.converter.domToJavac.get(type);
if (javacNode instanceof JCClassDecl jcClassDecl && jcClassDecl.type != null) {
Expand All @@ -290,7 +320,7 @@ ITypeBinding resolveType(AnnotationTypeDeclaration type) {
}

@Override
ITypeBinding resolveType(RecordDeclaration type) {
public ITypeBinding resolveType(RecordDeclaration type) {
resolve();
JCTree javacNode = this.converter.domToJavac.get(type);
if (javacNode instanceof JCClassDecl jcClassDecl && jcClassDecl.type != null) {
Expand All @@ -301,7 +331,7 @@ ITypeBinding resolveType(RecordDeclaration type) {


@Override
ITypeBinding resolveType(TypeDeclaration type) {
public ITypeBinding resolveType(TypeDeclaration type) {
resolve();
JCTree javacNode = this.converter.domToJavac.get(type);
if (javacNode instanceof JCClassDecl jcClassDecl && jcClassDecl.type != null) {
Expand All @@ -311,7 +341,7 @@ ITypeBinding resolveType(TypeDeclaration type) {
}

@Override
ITypeBinding resolveType(EnumDeclaration enumDecl) {
public ITypeBinding resolveType(EnumDeclaration enumDecl) {
resolve();
JCTree javacNode = this.converter.domToJavac.get(enumDecl);
if (javacNode instanceof JCClassDecl jcClassDecl && jcClassDecl.type != null) {
Expand All @@ -321,15 +351,15 @@ ITypeBinding resolveType(EnumDeclaration enumDecl) {
}

@Override
ITypeBinding resolveType(AnonymousClassDeclaration anonymousClassDecl) {
public ITypeBinding resolveType(AnonymousClassDeclaration anonymousClassDecl) {
resolve();
JCTree javacNode = this.converter.domToJavac.get(anonymousClassDecl);
if (javacNode instanceof JCClassDecl jcClassDecl && jcClassDecl.type != null) {
return this.bindings.getTypeBinding(jcClassDecl.type);
}
return null;
}
ITypeBinding resolveTypeParameter(TypeParameter typeParameter) {
public ITypeBinding resolveTypeParameter(TypeParameter typeParameter) {
resolve();
JCTree javacNode = this.converter.domToJavac.get(typeParameter);
if (javacNode instanceof JCTypeParameter jcClassDecl) {
Expand All @@ -339,7 +369,7 @@ ITypeBinding resolveTypeParameter(TypeParameter typeParameter) {
}

@Override
IVariableBinding resolveField(FieldAccess fieldAccess) {
public IVariableBinding resolveField(FieldAccess fieldAccess) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(fieldAccess);
if (javacElement instanceof JCFieldAccess javacFieldAccess && javacFieldAccess.sym instanceof VarSymbol varSymbol) {
Expand All @@ -349,7 +379,7 @@ IVariableBinding resolveField(FieldAccess fieldAccess) {
}

@Override
IVariableBinding resolveField(SuperFieldAccess fieldAccess) {
public IVariableBinding resolveField(SuperFieldAccess fieldAccess) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(fieldAccess);
if (javacElement instanceof JCFieldAccess javacFieldAccess && javacFieldAccess.sym instanceof VarSymbol varSymbol) {
Expand All @@ -359,7 +389,7 @@ IVariableBinding resolveField(SuperFieldAccess fieldAccess) {
}

@Override
IMethodBinding resolveMethod(MethodInvocation method) {
public IMethodBinding resolveMethod(MethodInvocation method) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(method);
if (javacElement instanceof JCMethodInvocation javacMethodInvocation) {
Expand All @@ -376,7 +406,7 @@ IMethodBinding resolveMethod(MethodInvocation method) {
}

@Override
IMethodBinding resolveMethod(MethodDeclaration method) {
public IMethodBinding resolveMethod(MethodDeclaration method) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(method);
if (javacElement instanceof JCMethodDecl methodDecl) {
Expand All @@ -386,7 +416,7 @@ IMethodBinding resolveMethod(MethodDeclaration method) {
}

@Override
IMethodBinding resolveMethod(LambdaExpression lambda) {
public IMethodBinding resolveMethod(LambdaExpression lambda) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(lambda);
if (javacElement instanceof JCLambda jcLambda) {
Expand All @@ -399,7 +429,7 @@ IMethodBinding resolveMethod(LambdaExpression lambda) {
}

@Override
IMethodBinding resolveMethod(MethodReference methodReference) {
public IMethodBinding resolveMethod(MethodReference methodReference) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(methodReference);
if (javacElement instanceof JCMemberReference memberRef && memberRef.sym instanceof MethodSymbol methodSymbol) {
Expand All @@ -409,7 +439,7 @@ IMethodBinding resolveMethod(MethodReference methodReference) {
}

@Override
IMethodBinding resolveMember(AnnotationTypeMemberDeclaration member) {
public IMethodBinding resolveMember(AnnotationTypeMemberDeclaration member) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(member);
if (javacElement instanceof JCMethodDecl methodDecl) {
Expand All @@ -419,7 +449,7 @@ IMethodBinding resolveMember(AnnotationTypeMemberDeclaration member) {
}

@Override
IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) {
public IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaration) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(enumConstantDeclaration);
if( javacElement instanceof JCVariableDecl jcvd ) {
Expand All @@ -432,7 +462,7 @@ IMethodBinding resolveConstructor(EnumConstantDeclaration enumConstantDeclaratio
}

@Override
IMethodBinding resolveConstructor(SuperConstructorInvocation expression) {
public IMethodBinding resolveConstructor(SuperConstructorInvocation expression) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(expression);
if (javacElement instanceof JCMethodInvocation javacMethodInvocation) {
Expand All @@ -448,7 +478,7 @@ IMethodBinding resolveConstructor(SuperConstructorInvocation expression) {
}

@Override
IBinding resolveName(Name name) {
public IBinding resolveName(Name name) {
resolve();
JCTree tree = this.converter.domToJavac.get(name);
if( tree != null ) {
Expand Down Expand Up @@ -495,7 +525,7 @@ IBinding resolveNameToJavac(Name name, JCTree tree) {
}

@Override
IVariableBinding resolveVariable(EnumConstantDeclaration enumConstant) {
public IVariableBinding resolveVariable(EnumConstantDeclaration enumConstant) {
resolve();
if (this.converter.domToJavac.get(enumConstant) instanceof JCVariableDecl decl) {
// the decl.type can be null when there are syntax errors
Expand All @@ -507,7 +537,7 @@ IVariableBinding resolveVariable(EnumConstantDeclaration enumConstant) {
}

@Override
IVariableBinding resolveVariable(VariableDeclaration variable) {
public IVariableBinding resolveVariable(VariableDeclaration variable) {
resolve();
if (this.converter.domToJavac.get(variable) instanceof JCVariableDecl decl) {
// the decl.type can be null when there are syntax errors
Expand Down Expand Up @@ -563,7 +593,7 @@ public ITypeBinding resolveExpressionType(Expression expr) {
}

@Override
IMethodBinding resolveConstructor(ClassInstanceCreation expression) {
public IMethodBinding resolveConstructor(ClassInstanceCreation expression) {
resolve();
return this.converter.domToJavac.get(expression) instanceof JCNewClass jcExpr
&& !jcExpr.constructor.type.isErroneous()?
Expand All @@ -572,7 +602,7 @@ IMethodBinding resolveConstructor(ClassInstanceCreation expression) {
}

@Override
IMethodBinding resolveConstructor(ConstructorInvocation invocation) {
public IMethodBinding resolveConstructor(ConstructorInvocation invocation) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(invocation);
if (javacElement instanceof JCMethodInvocation javacMethodInvocation) {
Expand Down Expand Up @@ -651,8 +681,7 @@ private java.util.List<TypeSymbol> getTypeArguments(final MethodInvocation metho
}) //
.collect(Collectors.toList());
}

IModuleBinding resolveModule(ModuleDeclaration module) {
public IModuleBinding resolveModule(ModuleDeclaration module) {
resolve();
JCTree javacElement = this.converter.domToJavac.get(module);
if( javacElement instanceof JCModuleDecl jcmd) {
Expand Down Expand Up @@ -700,7 +729,7 @@ public Object getValueFromAttribute(Attribute attribute) {
}

@Override
IBinding resolveImport(ImportDeclaration importDeclaration) {
public IBinding resolveImport(ImportDeclaration importDeclaration) {
var javac = this.converter.domToJavac.get(importDeclaration.getName());
if (javac instanceof JCFieldAccess fieldAccess) {
if (fieldAccess.sym != null) {
Expand All @@ -720,7 +749,7 @@ IBinding resolveImport(ImportDeclaration importDeclaration) {
}

@Override
ITypeBinding resolveWellKnownType(String typeName) {
public ITypeBinding resolveWellKnownType(String typeName) {
com.sun.tools.javac.code.Symtab symtab = com.sun.tools.javac.code.Symtab.instance(this.context);
com.sun.tools.javac.code.Type type = switch (typeName) {
case "byte", "java.lang.Byte" -> symtab.byteType;
Expand Down Expand Up @@ -751,7 +780,7 @@ ITypeBinding resolveWellKnownType(String typeName) {
}

@Override
IAnnotationBinding resolveAnnotation(Annotation annotation) {
public IAnnotationBinding resolveAnnotation(Annotation annotation) {
resolve();
var javac = this.converter.domToJavac.get(annotation);
if (javac instanceof JCAnnotation jcAnnotation) {
Expand Down
Loading

0 comments on commit 2fca795

Please sign in to comment.