Skip to content

Commit

Permalink
Stop assuming Java 1.3 source if project doesn't set explicitly
Browse files Browse the repository at this point in the history
ECJ supports 1.8 as min java version thus this would prevent the case of
UI generating/accepting code that the compiler may reject at compile
time.
  • Loading branch information
akurtakov committed Dec 22, 2024
1 parent b815dd4 commit fa3b37f
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 37 deletions.
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 @@ -42,7 +42,6 @@
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.SourceRange;
Expand Down Expand Up @@ -74,9 +73,9 @@
import org.eclipse.jdt.internal.corext.dom.ASTNodes;
import org.eclipse.jdt.internal.corext.dom.Bindings;
import org.eclipse.jdt.internal.corext.dom.ScopeAnalyzer;
import org.eclipse.jdt.internal.corext.util.StaticImportFavoritesCompletionInvoker;
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
import org.eclipse.jdt.internal.corext.util.JdtFlags;
import org.eclipse.jdt.internal.corext.util.StaticImportFavoritesCompletionInvoker;



Expand Down Expand Up @@ -233,7 +232,6 @@ public void addInfo(TypeNameMatch info) {
private IPackageFragment fCurrPackage;

private ScopeAnalyzer fAnalyzer;
private boolean fAllowDefaultPackageImports;

private Map<String, UnresolvedTypeData> fUnresolvedTypes;
private Set<String> fImportsAdded;
Expand All @@ -259,8 +257,6 @@ public TypeReferenceProcessor(Set<String> oldSingleImports, Set<String> oldDeman

fCurrPackage= (IPackageFragment) cu.getParent();

fAllowDefaultPackageImports= JavaCore.VERSION_1_3.equals(cu.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true));

fImportsAdded= new HashSet<>();
fUnresolvedTypes= new HashMap<>();
}
Expand Down Expand Up @@ -369,7 +365,7 @@ public boolean process(IProgressMonitor monitor) throws JavaModelException {
for (TypeNameMatch curr : typesFound) {
UnresolvedTypeData data= fUnresolvedTypes.get(curr.getSimpleTypeName());
if (data != null && isVisible(curr) && isOfKind(curr, data.typeKinds, is50OrHigher)) {
if (fAllowDefaultPackageImports || curr.getPackageName().length() > 0) {
if (curr.getPackageName().length() > 0) {
data.addInfo(curr);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2013 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 @@ -233,7 +233,7 @@ public int open() {
String text= ((ITextSelection)selection).getText();
if (text != null) {
text= text.trim();
if (text.length() > 0 && JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3, null).isOK()) {
if (text.length() > 0 && JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8, null).isOK()) {
fInitialFilter= text;
fSelectionMode= FULL_SELECTION;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 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,6 +32,7 @@
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;

import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;
import org.eclipse.jdt.internal.corext.refactoring.Checks;
import org.eclipse.jdt.internal.corext.refactoring.ParameterInfo;
import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
Expand All @@ -45,7 +46,6 @@
import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
import org.eclipse.jdt.internal.ui.refactoring.contentassist.ControlContentAssistHelper;
import org.eclipse.jdt.internal.ui.refactoring.contentassist.JavaTypeCompletionProcessor;
import org.eclipse.jdt.internal.core.manipulation.util.BasicElementLabels;

public class ParameterEditDialog extends StatusDialog {

Expand Down Expand Up @@ -193,7 +193,7 @@ private IStatus validateName() {
return createErrorStatus(RefactoringMessages.ParameterEditDialog_name_error);
IStatus status= fContext != null
? JavaConventionsUtil.validateFieldName(text, fContext.getCuHandle().getJavaProject())
: JavaConventions.validateFieldName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
: JavaConventions.validateFieldName(text, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);
if (status.matches(IStatus.ERROR))
return status;
if (! Checks.startsWithLowerCase(text))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2016 IBM Corporation and others.
* Copyright (c) 2009, 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 @@ -246,7 +246,7 @@ private void doValidation() {
if (newText.length() == 0) {
status.setError(""); //$NON-NLS-1$
} else {
IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3, null);
IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8, null);
if (val.matches(IStatus.ERROR)) {
if (fIsEditingMember)
status.setError(CallHierarchyMessages.CallHierarchyTypesOrMembersDialog_error_invalidMemberName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 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 @@ -431,7 +431,7 @@ public int open() {
String text= ((ITextSelection) selection).getText();
if (text != null) {
text= text.trim();
if (text.length() > 0 && JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3, null).isOK()) {
if (text.length() > 0 && JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8, null).isOK()) {
setInitialPattern(text, FULL_SELECTION);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2022 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 @@ -148,7 +148,7 @@ private void doValidation() {
status.setError(PreferencesMessages.TypeFilterInputDialog_error_enterName);
} else {
newText= newText.replace('*', 'X').replace('?', 'Y');
IStatus val= JavaConventions.validatePackageName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
IStatus val= JavaConventions.validatePackageName(newText, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);
if (val.matches(IStatus.ERROR)) {
status.setError(Messages.format(PreferencesMessages.TypeFilterInputDialog_error_invalidName, val.getMessage()));
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2013 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 @@ -594,7 +594,7 @@ protected void doValidation(JavadocTree javadocstatus) {
if (doclet.length() == 0) {
fDocletStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_nodocletname_error);

} else if (JavaConventions.validateJavaTypeName(doclet, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3, null).matches(IStatus.ERROR)) {
} else if (JavaConventions.validateJavaTypeName(doclet, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8, null).matches(IStatus.ERROR)) {
fDocletStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_invaliddocletname_error);
} else if ((docletPath.length() == 0) || !validDocletPath(docletPath)) {
fDocletStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_invaliddocletpath_error);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2016 IBM Corporation and others.
* Copyright (c) 2007, 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 @@ -208,7 +208,7 @@ private void doValidation() {
if (newText.length() == 0) {
status.setError(""); //$NON-NLS-1$
} else {
IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3, null);
IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8, null);
if (val.matches(IStatus.ERROR)) {
if (fIsEditingMember)
status.setError(PreferencesMessages.FavoriteStaticMemberInputDialog_error_invalidMemberName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 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 @@ -329,7 +329,7 @@ private List<ImportOrderEntry> loadFromProperties(Properties properties) {
String curr= properties.getProperty(String.valueOf(i));
if (curr != null) {
ImportOrderEntry entry= ImportOrderEntry.fromSerialized(curr);
if (entry.name.length() == 0 || !JavaConventions.validatePackageName(entry.name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_5).matches(IStatus.ERROR)) {
if (entry.name.length() == 0 || !JavaConventions.validatePackageName(entry.name, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8).matches(IStatus.ERROR)) {
res.add(entry);
} else {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2013 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 @@ -224,7 +224,7 @@ private void doValidation() {
status.setError(PreferencesMessages.ImportOrganizeInputDialog_error_entryExists);
}
} else {
IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3, null);
IStatus val= JavaConventions.validateJavaTypeName(newText, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8, null);
if (val.matches(IStatus.ERROR)) {
status.setError(PreferencesMessages.ImportOrganizeInputDialog_error_invalidName);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2016 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 @@ -192,7 +192,7 @@ private IStatus validateIdentifiers(String[] values, boolean prefix) {
}
}
String name= prefix ? val + "x" : "x" + val; //$NON-NLS-2$ //$NON-NLS-1$
IStatus status= JavaConventions.validateIdentifier(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
IStatus status= JavaConventions.validateIdentifier(name, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);
if (status.matches(IStatus.ERROR)) {
if (prefix) {
return new StatusInfo(IStatus.ERROR, Messages.format(PreferencesMessages.NameConventionConfigurationBlock_error_invalidprefix, val));
Expand Down Expand Up @@ -446,7 +446,7 @@ protected final void updateModel(DialogField field) {
setValue(PREF_EXCEPTION_NAME, name);

// validation
IStatus status = JavaConventions.validateIdentifier(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
IStatus status = JavaConventions.validateIdentifier(name, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);
if (!status.isOK()) {
fContext.statusChanged(status);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public ChangeToRequiredCompilerCompliance(String name, IJavaProject project, boo

private boolean isRequiredOrGreaterVMInstall(IVMInstall install) {
if (install instanceof IVMInstall2) {
String compliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) install, JavaCore.VERSION_1_3);
String compliance= JavaModelUtil.getCompilerCompliance((IVMInstall2) install, JavaCore.VERSION_1_8);
return !JavaModelUtil.isVersionLessThan(compliance, fRequiredVersion);
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018 IBM Corporation and others.
* Copyright (c) 2018, 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 @@ -74,8 +74,8 @@ public static IVMInstall findRequiredOrGreaterVMInstall(String requiredVersion,
}

public static String getVMInstallCompliance(IVMInstall install, boolean allowNullCompliance) {
String defCompliance1= JavaCore.VERSION_1_1;
String defCompliance2= JavaCore.VERSION_1_3;
String defCompliance1= JavaCore.VERSION_1_8;
String defCompliance2= JavaCore.VERSION_1_8;
if (allowNullCompliance) {
defCompliance1= null;
defCompliance2= null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 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 @@ -329,7 +329,7 @@ protected void handleFieldChanged(String fieldName) {
private IStatus validatePackageName(String text) {
IJavaProject project= getJavaProject();
if (project == null || !project.exists()) {
return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);
}
return JavaConventionsUtil.validatePackageName(text, project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -859,14 +859,14 @@ private IPackageFragment getPackage(IJavaProject javaProject) {

private static IStatus validateJavaTypeName(String text, IJavaProject project) {
if (project == null || !project.exists()) {
return JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3, null);
return JavaConventions.validateJavaTypeName(text, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8, null);
}
return JavaConventionsUtil.validateJavaTypeName(text, project);
}

private static IStatus validatePackageName(String text, IJavaProject project) {
if (project == null || !project.exists()) {
return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
return JavaConventions.validatePackageName(text, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8);
}
return JavaConventionsUtil.validatePackageName(text, project);
}
Expand Down

0 comments on commit fa3b37f

Please sign in to comment.