Skip to content

Commit

Permalink
Remove pre 1.8 support
Browse files Browse the repository at this point in the history
ECJ supports min 1.8 and JDT UI provides no way to set BREE lower than
that thus all this code is non reachable.
  • Loading branch information
akurtakov committed Dec 30, 2024
1 parent f5e22a7 commit 21b6bc4
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1095,9 +1095,6 @@ public static ASTNode getNodeToInsertBefore(ListRewrite listRewrite, IJavaElemen
public static void addOverrideAnnotation(CodeGenerationSettings settings, IJavaProject project, ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration methodDecl,
boolean isDeclaringTypeInterface, TextEditGroup group) {
if (isDeclaringTypeInterface) {
String version= project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_6))
return; // not allowed in 1.5
if (JavaCore.DISABLED.equals(project.getOption(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, true)))
return; // user doesn't want to use 1.6 style
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1230,8 +1230,6 @@ public final void acceptBinding(final String key, final IBinding binding) {
subMonitor.beginTask("", keySet.size() * 100); //$NON-NLS-1$
subMonitor.setTaskName(RefactoringCoreMessages.SuperTypeRefactoringProcessor_creating);
for (IJavaProject project : keySet) {
if (level == 3 && !JavaModelUtil.is50OrHigher(project))
level= 2;
Collection<ICompilationUnit> cuCollection= secondPass.get(project);
if (cuCollection != null) {
parser.setWorkingCopyOwner(fOwner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,6 @@ public static boolean is50OrHigher(String compliance) {
return !isVersionLessThan(compliance, JavaCore.VERSION_1_5);
}

public static boolean is1d6OrHigher(String compliance) {
return !isVersionLessThan(compliance, JavaCore.VERSION_1_6);
}

public static boolean is1d7OrHigher(String compliance) {
return !isVersionLessThan(compliance, JavaCore.VERSION_1_7);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ private void validateComplianceStatus() {
args[1]= getVersionLabel(version);
}
if (JavaModelUtil.is9OrHigher(compilerCompliance)) {
if (!JavaModelUtil.is1d6OrHigher(compliance) || !fCompilerReleaseCheck.getSelection()) {
if (!fCompilerReleaseCheck.getSelection()) {
if (fProject == null) {
fJRE50InfoText.setText(Messages.format(PreferencesMessages.ComplianceConfigurationBlock_jrecompliance_info, args));
} else {
Expand Down Expand Up @@ -748,7 +748,6 @@ private void updateReleaseOptionStatus() {
if (!compilerCompliance.equals(compliance)) { // Discourage using compiler with version other than compliance
if (JavaModelUtil.is9OrHigher(compilerCompliance)) {
if (!JavaModelUtil.isVersionLessThan(compliance, compilerCompliance)
|| !JavaModelUtil.is1d6OrHigher(compliance)
|| ( JavaModelUtil.is12OrHigher(compilerCompliance))
&& !JavaModelUtil.is1d7OrHigher(compliance)) {
fCompilerReleaseCheck.setEnabled(false);
Expand All @@ -773,7 +772,7 @@ private void updateReleaseOptionStatus() {
setValue(PREF_RELEASE, JavaCore.DISABLED);
} else {
if (fProject == null
|| (isJREUnsupportedAndGreater && JavaModelUtil.is1d6OrHigher(compliance))
|| isJREUnsupportedAndGreater
|| JavaModelUtil.is9OrHigher(compliance)) {
fCompilerReleaseCheck.setEnabled(true);
}
Expand Down Expand Up @@ -921,7 +920,7 @@ private void updateComplianceEnableSourceTargetState() {
String complianceFollowsEE= getValue(INTR_COMPLIANCE_FOLLOWS_EE);
enableComplianceControls= hasProjectSpecificOptions && !DEFAULT_CONF.equals(complianceFollowsEE); // is disabled or user
}
boolean enableBasedOnRelease= !fCompilerReleaseCheck.getSelection() || !JavaModelUtil.is1d6OrHigher(getValue(PREF_COMPLIANCE));
boolean enableBasedOnRelease= !fCompilerReleaseCheck.getSelection();
boolean enableComplianceChildren= enableComplianceControls && checkValue(INTR_DEFAULT_COMPLIANCE, USER_CONF) && enableBasedOnRelease;
for (int i= fComplianceChildControls.size() - 1; i >= 0; i--) {
Control curr= fComplianceChildControls.get(i);
Expand Down Expand Up @@ -1055,7 +1054,7 @@ private void updateComplianceDefaultSettings(boolean rememberOld, String oldComp
boolean isDefault= checkValue(INTR_DEFAULT_COMPLIANCE, DEFAULT_CONF);
boolean isFollowEE= checkValue(INTR_COMPLIANCE_FOLLOWS_EE, DEFAULT_CONF);
String complianceLevel= getValue(PREF_COMPLIANCE);
boolean isRelease= checkValue(PREF_RELEASE, JavaCore.ENABLED) && JavaModelUtil.is1d6OrHigher(complianceLevel) && !isDefault;
boolean isRelease= checkValue(PREF_RELEASE, JavaCore.ENABLED) && !isDefault;

if (isDefault || isFollowEE || isRelease) {
if (rememberOld) {
Expand Down Expand Up @@ -1139,7 +1138,7 @@ private void updateComplianceDefaultSettings(boolean rememberOld, String oldComp

private void updateComplianceReleaseSettings() {
String compliance= getValue(PREF_COMPLIANCE);
boolean isRelease= checkValue(PREF_RELEASE, JavaCore.ENABLED) && JavaModelUtil.is1d6OrHigher(compliance);
boolean isRelease= checkValue(PREF_RELEASE, JavaCore.ENABLED);
if (isRelease) {
setValue(PREF_SOURCE_COMPATIBILITY, compliance);
setValue(PREF_CODEGEN_TARGET_PLATFORM, compliance);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corporation and others.
* Copyright (c) 2000, 2024 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 @@ -72,7 +72,6 @@ private final static class CorePrefs {
final boolean prefIndentBracesForMethods;
final boolean prefIndentBracesForTypes;
final int prefContinuationIndent;
final boolean prefHasGenerics;
final String prefTabChar;

private final IJavaProject fProject;
Expand Down Expand Up @@ -129,7 +128,6 @@ private String getCoreFormatterOption(String key) {
prefIndentBracesForArrays= false;
prefIndentBracesForMethods= false;
prefIndentBracesForTypes= false;
prefHasGenerics= false;
prefTabChar= JavaCore.TAB;
} else {
prefUseTabs= prefUseTabs();
Expand Down Expand Up @@ -158,7 +156,6 @@ private String getCoreFormatterOption(String key) {
prefIndentBracesForArrays= prefIndentBracesForArrays();
prefIndentBracesForMethods= prefIndentBracesForMethods();
prefIndentBracesForTypes= prefIndentBracesForTypes();
prefHasGenerics= hasGenerics();
prefTabChar= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR);
}
}
Expand Down Expand Up @@ -363,9 +360,6 @@ private int prefContinuationIndentForArrayInitializer() {

return 2; // sensible default
}
private boolean hasGenerics() {
return JavaCore.compareJavaVersions(JavaCore.VERSION_1_5, getCoreFormatterOption(JavaCore.COMPILER_SOURCE)) <= 0;
}
}

/** The document being scanned. */
Expand Down Expand Up @@ -1593,8 +1587,6 @@ private boolean skipScope() {
case Symbols.TokenRBRACE:
return skipScope(Symbols.TokenLBRACE, Symbols.TokenRBRACE);
case Symbols.TokenGREATERTHAN:
if (!fPrefs.prefHasGenerics)
return false;
int storedPosition= fPosition;
int storedToken= fToken;
nextToken();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2023 IBM Corporation and others.
* Copyright (c) 2000, 2024 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 @@ -32,7 +32,6 @@
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Annotation;
Expand All @@ -52,7 +51,6 @@

import org.eclipse.jdt.internal.core.manipulation.dom.ASTResolving;
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;

import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
Expand Down Expand Up @@ -86,10 +84,6 @@ private void addOverrideAnnotation(IDocument document) throws CoreException {
MethodDeclaration oldMethodDeclaration= (MethodDeclaration) ASTNodes.findDeclaration(fMethod, getInvocationNode());
CompilationUnit findParentCompilationUnit= ASTResolving.findParentCompilationUnit(oldMethodDeclaration);
IJavaProject javaProject= findParentCompilationUnit.getJavaElement().getJavaProject();
String version= javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
if (JavaModelUtil.isVersionLessThan(version, JavaCore.VERSION_1_5)) {
return;
}
IType type= javaProject.findType(fMethod.getDeclaringClass().getQualifiedName());
ICompilationUnit compilationUnit= type.getCompilationUnit();
ImportRewrite importRewrite= CodeStyleConfiguration.createImportRewrite(compilationUnit, true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2022 IBM Corporation and others.
* Copyright (c) 2005, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -26,9 +26,7 @@
import org.eclipse.jdt.core.CompletionContext;
import org.eclipse.jdt.core.CompletionProposal;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;

Expand Down Expand Up @@ -124,35 +122,9 @@ private IJavaCompletionProposal createTypeProposal(int relevance, String fullyQu
proposal.setReplaceRange(context.getInvocationOffset(), context.getInvocationOffset());
proposal.setSignature(Signature.createTypeSignature(fullyQualifiedType, true).toCharArray());

if (shouldProposeGenerics(context.getProject())) {
LazyGenericTypeProposal p= new LazyGenericTypeProposal(proposal, context);
p.setRelevance(relevance);
return p;
} else {
LazyJavaTypeCompletionProposal p= new LazyJavaTypeCompletionProposal(proposal, context);
p.setRelevance(relevance);
return p;
}
}

/**
* Returns <code>true</code> if generic proposals should be allowed,
* <code>false</code> if not. Note that even though code (in a library)
* may be referenced that uses generics, it is still possible that the
* current source does not allow generics.
*
* @param project the Java project
* @return <code>true</code> if the generic proposals should be allowed,
* <code>false</code> if not
*/
protected final boolean shouldProposeGenerics(IJavaProject project) {
String sourceVersion;
if (project != null)
sourceVersion= project.getOption(JavaCore.COMPILER_SOURCE, true);
else
sourceVersion= JavaCore.getOption(JavaCore.COMPILER_SOURCE);

return sourceVersion != null && JavaCore.compareJavaVersions(JavaCore.VERSION_1_5, sourceVersion) <= 0;
LazyGenericTypeProposal p= new LazyGenericTypeProposal(proposal, context);
p.setRelevance(relevance);
return p;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*******************************************************************************/
package org.eclipse.jdt.ui.wizards;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;

Expand All @@ -44,12 +40,9 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;

import org.eclipse.jface.dialogs.Dialog;
Expand All @@ -70,20 +63,15 @@
import org.eclipse.jdt.core.JavaModelException;

import org.eclipse.jdt.internal.core.manipulation.StubUtility;
import org.eclipse.jdt.internal.corext.javadoc.JavaDocCommentReader;
import org.eclipse.jdt.internal.corext.util.InfoFilesUtil;
import org.eclipse.jdt.internal.corext.util.JavaConventionsUtil;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.corext.util.Messages;

import org.eclipse.jdt.ui.JavaUI;

import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
import org.eclipse.jdt.internal.ui.javaeditor.DocumentAdapter;
import org.eclipse.jdt.internal.ui.text.javadoc.JavaDoc2HTMLTextReader;
import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
Expand Down Expand Up @@ -465,11 +453,7 @@ public IResource getModifiedResource() {
IPackageFragment pack= root.getPackageFragment(getPackageText());
IResource packRes= pack.getResource();
if (isCreatePackageDocumentation()) {
if (JavaModelUtil.is50OrHigher(getJavaProject())) {
return pack.getCompilationUnit(PACKAGE_INFO_JAVA_FILENAME).getResource();
} else if (packRes instanceof IFolder){
return ((IFolder) packRes).getFile(PACKAGE_HTML_FILENAME);
}
return pack.getCompilationUnit(PACKAGE_INFO_JAVA_FILENAME).getResource();
}

return packRes;
Expand Down Expand Up @@ -531,11 +515,7 @@ public void createPackage(IProgressMonitor monitor) throws CoreException, Interr
}

if (isCreatePackageDocumentation()) {
if (JavaModelUtil.is50OrHigher(getJavaProject())) {
createPackageInfoJava(monitor);
} else {
createPackageHtml(root, monitor);
}
createPackageInfoJava(monitor);
}

// save whether package documentation should be created
Expand All @@ -561,89 +541,4 @@ private void createPackageInfoJava(IProgressMonitor monitor) throws CoreExceptio

InfoFilesUtil.createInfoJavaFile(PACKAGE_INFO_JAVA_FILENAME, fileContent.toString(), fCreatedPackageFragment,this.isAddComments(), monitor);
}

private void createPackageHtml(IPackageFragmentRoot root, IProgressMonitor monitor) throws CoreException {
IWorkspace workspace= ResourcesPlugin.getWorkspace();
IFolder createdPackage= workspace.getRoot().getFolder(fCreatedPackageFragment.getPath());
IFile packageHtml= createdPackage.getFile(PACKAGE_HTML_FILENAME);
String charset= packageHtml.getCharset();
String content= buildPackageHtmlContent(root, charset);
try {
packageHtml.create(new ByteArrayInputStream(content.getBytes(charset)), false, monitor);
} catch (UnsupportedEncodingException e) {
String message= "charset " + charset + " not supported by platform"; //$NON-NLS-1$ //$NON-NLS-2$
throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, message, e));
}
}

private String buildPackageHtmlContent(IPackageFragmentRoot root, String charset) throws CoreException {
String lineDelimiter= StubUtility.getLineDelimiterUsed(root.getJavaProject());
StringBuilder content = new StringBuilder();
String fileComment= InfoFilesUtil.getFileComment(PACKAGE_INFO_JAVA_FILENAME, fCreatedPackageFragment, lineDelimiter);
String typeComment= InfoFilesUtil.getTypeComment(PACKAGE_INFO_JAVA_FILENAME, fCreatedPackageFragment, lineDelimiter);

content.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">"); //$NON-NLS-1$
content.append(lineDelimiter);
if (fileComment != null) {
content.append("<!--"); //$NON-NLS-1$
content.append(lineDelimiter);
content.append(stripJavaComments(fileComment));
content.append(lineDelimiter);
content.append("-->"); //$NON-NLS-1$
content.append(lineDelimiter);
}
content.append("<html>"); //$NON-NLS-1$
content.append(lineDelimiter);
content.append("<head>"); //$NON-NLS-1$
content.append(lineDelimiter);
content.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset="); //$NON-NLS-1$
content.append(charset);
content.append("\">"); //$NON-NLS-1$
content.append(lineDelimiter);
content.append("<title>"); //$NON-NLS-1$
content.append(fCreatedPackageFragment.getElementName());
content.append("</title>"); //$NON-NLS-1$
content.append(lineDelimiter);
content.append("</head>"); //$NON-NLS-1$
content.append(lineDelimiter);
content.append("<body>"); //$NON-NLS-1$
content.append(lineDelimiter);

if (typeComment != null) {
content.append(stripJavaComments(typeComment));
content.append(lineDelimiter);
}

content.append("</body>"); //$NON-NLS-1$
content.append(lineDelimiter);
content.append("</html>"); //$NON-NLS-1$

return content.toString();
}

private String stripJavaComments(String comment) {
DocumentAdapter documentAdapter= new DocumentAdapter(null, fCreatedPackageFragment.getPath());
documentAdapter.setContents(comment);
try (JavaDoc2HTMLTextReader reader= new JavaDoc2HTMLTextReader(new JavaDocCommentReader(documentAdapter, 0, comment.length()))) {
return getString(reader);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
documentAdapter.close();
}
}

private static String getString(Reader reader) {
StringBuilder buf= new StringBuilder();
char[] buffer= new char[1024];
int count;
try {
while ((count= reader.read(buffer)) != -1)
buf.append(buffer, 0, count);
} catch (IOException e) {
return null;
}
return buf.toString();
}

}

0 comments on commit 21b6bc4

Please sign in to comment.