-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JEP-445: allow parsing unnamed classes
Adds a compiler AST UnnamedClass type and grammar rules to parse unnamed classes. Adds some tests. Still missing: * codegen for UnnamedClass * checks for Java version compatibility * More analyseCode to ensure we don't allow more than specified (after parsing) * Proper check of existence of a main() method * ...
- Loading branch information
1 parent
398ba0b
commit d56b9af
Showing
37 changed files
with
2,153 additions
and
1,775 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...lipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/UnnamedClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 Red Hat, Inc. 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 | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.internal.compiler.ast; | ||
|
||
import org.eclipse.jdt.internal.compiler.CompilationResult; | ||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; | ||
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; | ||
import org.eclipse.jdt.internal.compiler.problem.AbortType; | ||
|
||
/** | ||
* Represents an unnamed class as defined in JEP 445 | ||
*/ | ||
public class UnnamedClass extends TypeDeclaration { | ||
|
||
public UnnamedClass(CompilationResult result) { | ||
super(result); | ||
this.modifiers = ClassFileConstants.AccDefault | ClassFileConstants.AccFinal; | ||
this.name = "<unnamed class>".toCharArray(); //$NON-NLS-1$ | ||
} | ||
|
||
@Override | ||
public void analyseCode(CompilationUnitScope unitScope) { | ||
if (this.ignoreFurtherInvestigation) | ||
return; | ||
try { | ||
boolean foundMain = false; | ||
for (AbstractMethodDeclaration method : this.methods) { | ||
if (method instanceof MethodDeclaration methodDeclaration) { | ||
foundMain |= methodDeclaration.isMainMethodCandidate(); | ||
} else { | ||
//unitScope.problemReporter().specialMethodsNotAllowedInUnnamedClass(method); | ||
} | ||
} | ||
if (!foundMain) { | ||
unitScope.problemReporter().unnamedClassMustHaveMainMethod(); | ||
} | ||
// TODO flowAnalyseCode(null, FlowInfo.initial(Integer.MAX_VALUE)); | ||
} catch (AbortType e) { | ||
this.ignoreFurtherInvestigation = true; | ||
} | ||
super.analyseCode(unitScope); | ||
} | ||
|
||
// @Override | ||
// public void generateCode(CompilationUnitScope unitScope) { | ||
// SourceTypeBinding unnamedBinding = this.binding; | ||
// this.binding = toNamedBinding(unitScope); | ||
// super.generateCode(unitScope); | ||
// this.binding = unnamedBinding; | ||
// } | ||
// | ||
// private SourceTypeBinding toNamedBinding(CompilationUnitScope scope) { | ||
// SourceTypeBinding res = new SourceTypeBinding(this.binding) { | ||
// @Override | ||
// public boolean isPrototype() { | ||
// return true; | ||
// } | ||
// }; | ||
// res.compoundName = new char[][] { scope.referenceContext.getMainTypeName() }; | ||
// return res; | ||
// } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.