Skip to content

Commit

Permalink
Eclipse 4.19 (RC1) JDT Patch for Groovy-Eclipse: JDT commit 37880e2
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 28, 2021
1 parent cf4c88a commit cbe4bad
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</license>

<requires>
<import feature="org.eclipse.jdt" version="3.18.700.v20210217-1800" patch="true"/>
<import feature="org.eclipse.jdt" version="3.18.700.v20210224-1800" patch="true"/>
</requires>

<plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -76,6 +76,7 @@
import org.eclipse.jdt.internal.compiler.env.AccessRestriction;
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.eclipse.jdt.internal.compiler.env.ISourceType;
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
Expand Down Expand Up @@ -365,6 +366,12 @@ public void acceptConstructor(
AccessRestriction access) {
// constructors aren't searched
}
@Override
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
CompilationUnitDeclaration unit = this.lookupEnvironment.unitBeingCompleted;
super.accept(sourceTypes, packageBinding, accessRestriction);
this.lookupEnvironment.unitBeingCompleted = unit;
}

@Override
public void acceptType(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, int modifiers, AccessRestriction accessRestriction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation;
import org.eclipse.jdt.internal.compiler.env.IBinaryType;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo;
Expand Down Expand Up @@ -1083,6 +1084,7 @@ public JavadocContents getJavadocContents(IProgressMonitor monitor) throws JavaM
typeQualifiedName = getElementName();
}

appendModulePath(pack, pathBuffer);
pathBuffer.append(pack.getElementName().replace('.', '/')).append('/').append(typeQualifiedName).append(JavadocConstants.HTML_EXTENSION);
if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException();
final String contents = getURLContents(baseLocation, String.valueOf(pathBuffer));
Expand All @@ -1096,4 +1098,49 @@ public JavadocContents getJavadocContents(IProgressMonitor monitor) throws JavaM
public boolean isLambda() {
return false;
}

private static void appendModulePath(IPackageFragment pack, StringBuffer buf) {
IModuleDescription moduleDescription= getModuleDescription(pack);
if (moduleDescription != null) {
String moduleName= moduleDescription.getElementName();
if (moduleName != null && moduleName.length() > 0) {
buf.append(moduleName);
buf.append('/');
}
}
}

private static IModuleDescription getModuleDescription(IPackageFragment pack) {
if (pack == null) {
return null;
}
IModuleDescription moduleDescription= null;
/*
* The Javadoc tool for Java SE 11 uses module name in the created URL.
* We can't know what format is required, so we just guess by the project's compiler compliance.
*/
IJavaProject javaProject= pack.getJavaProject();
if (javaProject != null && isComplianceJava11OrHigher(javaProject)) {
if (pack.isReadOnly()) {
IPackageFragmentRoot root= (IPackageFragmentRoot) pack.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
if (root != null) {
moduleDescription= root.getModuleDescription();
}
} else {
try {
moduleDescription= javaProject.getModuleDescription();
} catch (JavaModelException e) {
// do nothing
}
}
}
return moduleDescription;
}

private static boolean isComplianceJava11OrHigher(IJavaProject javaProject) {
if (javaProject == null) {
return false;
}
return CompilerOptions.versionToJdkLevel(javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true)) >= ClassFileConstants.JDK11;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GROOVY PATCHED
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -133,7 +133,9 @@ public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, Acc

if (unit != null) {
environment.buildTypeBindings(unit, accessRestriction);
CompilationUnitDeclaration previousUnitBeingCompleted = this.lookupEnvironment.unitBeingCompleted;
environment.completeTypeBindings(unit);
this.lookupEnvironment.unitBeingCompleted = previousUnitBeingCompleted;
}
} finally {
this.options.complianceLevel = savedComplianceLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public ModuleUpdater(JavaProject javaProject) {
* Detects any ADD_EXPORTS or ADD_READS classpath attributes, parses the value,
* and collects the resulting module updates.
* @param entry a classpath entry of the current project.
* @throws JavaModelException
* @throws JavaModelException
*/
public void computeModuleUpdates(IClasspathEntry entry) throws JavaModelException {
for (IClasspathAttribute attribute : entry.getExtraAttributes()) {
Expand Down Expand Up @@ -128,7 +128,7 @@ private static boolean containsNonModularDependency(IClasspathEntry[] entries) {
public void addReadUnnamedForNonEmptyClasspath(JavaProject project, IClasspathEntry[] expandedClasspath)
throws JavaModelException {
for (String moduleName : determineModulesOfProjectsWithNonEmptyClasspath(project, expandedClasspath)) {
addModuleUpdate(moduleName, m -> m.addReads(ModuleBinding.ALL_UNNAMED), UpdateKind.MODULE);
addModuleUpdate(moduleName, new IUpdatableModule.AddReads(ModuleBinding.ALL_UNNAMED), UpdateKind.MODULE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,19 +790,17 @@ private void writeBinaryLocations(DataOutputStream out, ClasspathLocation[] loca
if (c.updates != null) {
List<Consumer<IUpdatableModule>> pu = c.updates.getList(UpdateKind.PACKAGE, false);
if (pu != null) {
Map<String, List<Consumer<IUpdatableModule>>> map = pu.stream().
collect(Collectors.groupingBy(
update -> CharOperation.charToString(((IUpdatableModule.AddExports)update).getName())));
Map<String, List<AddExports>> map = pu.stream().filter(AddExports.class::isInstance)
.map(AddExports.class::cast)
.collect(Collectors.groupingBy(addExport -> CharOperation.charToString(addExport.getName())));
out.writeInt(map.size());
map.entrySet().stream().forEach(entry -> {
String pkgName = entry.getKey();
try {
writeName(pkgName.toCharArray(), out);
char[][] targetModules = entry.getValue().stream()
.map(consumer -> ((IUpdatableModule.AddExports) consumer).getTargetModules())
.filter(targets -> targets != null)
.reduce((f,s) -> CharOperation.arrayConcat(f,s))
.orElse(null);
.map(addExport -> addExport.getTargetModules()).filter(targets -> targets != null)
.reduce((f, s) -> CharOperation.arrayConcat(f, s)).orElse(null);
writeNames(targetModules, out);
} catch (IOException e) {
// ignore
Expand All @@ -814,9 +812,10 @@ private void writeBinaryLocations(DataOutputStream out, ClasspathLocation[] loca
}
List<Consumer<IUpdatableModule>> mu = c.updates.getList(UpdateKind.MODULE, false);
if (mu != null) {
out.writeInt(mu.size());
for (Consumer<IUpdatableModule> cons : mu) {
AddReads m = (AddReads) cons;
// TODO, here we cannot handle MODULE_MAIN_CLASS nor MODULE_PACKAGES (ModuleUpdater stores a lambda), should we?
List<AddReads> allReads = mu.stream().filter(AddReads.class::isInstance).map(AddReads.class::cast).collect(Collectors.toList());
out.writeInt(allReads.size());
for (AddReads m : allReads) {
writeName(m.getTarget(), out);
}
} else {
Expand Down
1 change: 1 addition & 0 deletions jdt-patch/e419/org.eclipse.jdt.core/readme.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2021-01-08: d5c188d (2021-03 M1)
2021-02-08: babeca4 (2021-03 M2)
2021-02-22: 96e9f52 (2021-03 M3)
2021-02-28: 37880e2 (2021-03 RC1)
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<repository>
<id>eclipse</id>
<layout>p2</layout>
<url>https://download.eclipse.org/eclipse/updates/4.19-I-builds/I20210217-1800</url>
<url>https://download.eclipse.org/eclipse/updates/4.19-I-builds/I20210224-1800</url>
</repository>
</repositories>
<modules>
Expand Down

0 comments on commit cbe4bad

Please sign in to comment.