-
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.
Adds a compiler AST UnnamedClass type and grammar rules to parse unnamed classes. Sets up validation and (in)visibility rules. Codegen. With some tests.
- Loading branch information
1 parent
398ba0b
commit 0b2891f
Showing
37 changed files
with
2,229 additions
and
1,777 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
63 changes: 63 additions & 0 deletions
63
...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,63 @@ | ||
/******************************************************************************* | ||
* 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 java.util.Arrays; | ||
|
||
import org.eclipse.jdt.internal.compiler.CompilationResult; | ||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; | ||
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; | ||
|
||
/** | ||
* 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) { | ||
super.analyseCode(unitScope); | ||
if (this.ignoreFurtherInvestigation) | ||
return; | ||
if (Arrays.stream(this.methods) | ||
.filter(MethodDeclaration.class::isInstance) | ||
.map(MethodDeclaration.class::cast) | ||
.noneMatch(MethodDeclaration::isMainMethodCandidate)) { | ||
unitScope.problemReporter().unnamedClassMustHaveMainMethod(); | ||
this.ignoreFurtherInvestigation = true; | ||
} | ||
} | ||
|
||
// @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
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.