j3.27.0.0 working
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# Applied automatic formatting to the entire project
|
||||
# See https://github.com/javaparser/javaparser/issues/4408 for details
|
||||
5106428130cd3ff052a57d37a3d192f040da5edf
|
||||
1
Assignment-2/javaparser-javaparser-parent-3.27.0/.gitattributes
vendored
Normal file
1
Assignment-2/javaparser-javaparser-parent-3.27.0/.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.java text eol=lf
|
||||
10
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/dependabot.yml
vendored
Normal file
10
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "maven"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
17
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/renovate.json
vendored
Normal file
17
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/renovate.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"packageRules": [
|
||||
{
|
||||
"updateTypes": ["minor", "patch", "pin", "digest"],
|
||||
"automerge": true
|
||||
}
|
||||
],
|
||||
"automergeType": "pr",
|
||||
"prHourlyLimit": 0,
|
||||
"semanticCommits": true,
|
||||
"dependencyDashboard": true,
|
||||
"configWarningReuseIssue": false,
|
||||
"labels": ["dependencies"]
|
||||
}
|
||||
36
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/workflows/create_github_release.yml
vendored
Normal file
36
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/workflows/create_github_release.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
on:
|
||||
push:
|
||||
# Sequence of patterns matched against refs/tags
|
||||
tags:
|
||||
# - 'v[0-9]+.[0-9]+.[0-9]+' # Push events to matching pattern -- updated to use regex for a semantic versioning version number
|
||||
- 'javaparser-parent-[0-9].*' # Push events to matching pattern -- loosened pattern to be v followed by at least one number, then anything else after (this allows for e.g. "-DRAFT" and "-SNAPSHOT" as a suffix, and shorter version numbers such as "v2")
|
||||
|
||||
name: Create Release from semantic versioning tag push
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Create Release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4.2.2
|
||||
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1.1.4
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: Release ${{ github.ref }}
|
||||
## Body content doesn't yet seem to appear in the Github UI
|
||||
# body: |
|
||||
# Bug Fixes:
|
||||
# - TODO: Describe any bug fixes
|
||||
#
|
||||
# Enhancements:
|
||||
# - TODO: Describe any new features or enhancements
|
||||
## Option -- trigger as a draft release, followed by the addition of any key release notes and manual approval?
|
||||
## Alternative -- replace the above body with a link to the changelog? We can always edit release after the fact to add in e.g. notes about breaking changes.
|
||||
draft: true
|
||||
prerelease: false
|
||||
63
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/workflows/formatting_check.yml
vendored
Normal file
63
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/workflows/formatting_check.yml
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
name: Check codegen and formatting
|
||||
|
||||
#on: [push, pull_request]
|
||||
#on: [pull_request]
|
||||
on:
|
||||
# Trigger the workflow on push to master (ignoring .md only changes)
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
|
||||
# Trigger the workflow on any pull_request (ignoring .md only changes)
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
|
||||
# Enable manual triggering (important for contributors to enable a check on their fork)
|
||||
workflow_dispatch:
|
||||
|
||||
# If a build is running in the current branch, and the branch is updated, we cancel the previous build and start
|
||||
# a new one with the updated changes.
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
# Run checkstyle validations for pipeline
|
||||
checkstyle_check:
|
||||
name: Validate checkstyle
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout latest code
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
fetch-depth: "0"
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'zulu'
|
||||
- name: Validate Project Checkstyle
|
||||
run: ./mvnw -B checkstyle:check
|
||||
|
||||
spotless_check:
|
||||
name: Spotless check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout latest code
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
fetch-depth: "0"
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'zulu'
|
||||
- name: Generate code and format
|
||||
run: |
|
||||
./run_core_metamodel_generator.sh
|
||||
# ./run_core_generators.sh automatically runs ./mvnw spotless:apply
|
||||
./run_core_generators.sh
|
||||
git diff --exit-code
|
||||
116
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/workflows/maven_tests.yml
vendored
Normal file
116
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/workflows/maven_tests.yml
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
name: Build and test (using maven)
|
||||
|
||||
#on: [push, pull_request]
|
||||
#on: [pull_request]
|
||||
on:
|
||||
# Trigger the workflow on push to master (ignoring .md only changes)
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
|
||||
# Trigger the workflow on any pull_request (ignoring .md only changes)
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
|
||||
# Enable manual triggering (important for contributors to enable a check on their fork)
|
||||
workflow_dispatch:
|
||||
|
||||
# If a build is running in the current branch, and the branch is updated, we cancel the previous build and start
|
||||
# a new one with the updated changes.
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
maven_test:
|
||||
strategy:
|
||||
## Optionally cancel all other combinations if one fails
|
||||
fail-fast: false
|
||||
matrix:
|
||||
## Different OSs have different default line-endings -- test on all combinations.
|
||||
os: [ ubuntu-latest, macos-latest, windows-latest ]
|
||||
## Different JDK versions have different implementations etc. -- test on all combinations (ideally 8 to latest).
|
||||
### exclude pre-8 (min development version jdk8)
|
||||
jdk: [ 8,9,10,11,12,13,14,15,16,17,18 ]
|
||||
# The below configurations are no longer available on github runners and is not supported by the
|
||||
# setup-java action, nor are they available from the supported distributions.
|
||||
# See https://github.com/actions/setup-java for details
|
||||
exclude:
|
||||
- os: macos-latest
|
||||
jdk: 9
|
||||
- os: macos-latest
|
||||
jdk: 10
|
||||
- os: macos-latest
|
||||
jdk: 12
|
||||
- os: macos-latest
|
||||
jdk: 14
|
||||
|
||||
env:
|
||||
OS: ${{ matrix.os }}
|
||||
JDK: ${{ matrix.jdk }}
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
## Checkout the current version of the code from the repo.
|
||||
- name: Checkout latest code
|
||||
uses: actions/checkout@v4.2.2
|
||||
with:
|
||||
fetch-depth: "0"
|
||||
|
||||
## Setup the specified version of Java (includes maven/gradle).
|
||||
- name: Set up JDK ${{ matrix.jdk }}
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'zulu' # v2 requires explicitly stating the distribution - `zulu` and `adopt` supported at time of writing
|
||||
java-version: ${{ matrix.jdk }} # Use matrix to select which JDK level to use
|
||||
java-package: jdk # optional (jdk or jre) - defaults to jdk
|
||||
|
||||
## Given that the build matrix only specifies the major version (configurable), output the precise version used.
|
||||
- name: Echo exact java version being used
|
||||
run: java -version
|
||||
|
||||
## Use a cache to reduce the build/test times (avoids having to download dependencies on EVERY run).
|
||||
### https://help.github.com/en/actions/language-and-framework-guides/building-and-testing-java-with-maven#caching-dependencies
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ~/.m2
|
||||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: ${{ runner.os }}-m2
|
||||
|
||||
|
||||
## Actually perform the tests. Unsuccessful tests will indicate a failed build.
|
||||
### -e, --errors : show traces where any errors occur
|
||||
### -B,--batch-mode : Run in non-interactive (batch) mode (disables output color)
|
||||
### clean : run the maven lifecycle stage `clean`
|
||||
### test : run the maven lifecycle stage `test`
|
||||
### -P,--activate-profiles : Comma-delimited list of profiles to activate
|
||||
### AlsoSlowTests : by default, only quick tests are run - the profile `AlsoSlowTests` runs the full test suite
|
||||
- name: Test with Maven (incl. slow tests)
|
||||
shell: bash
|
||||
run: ./mvnw -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B --errors clean test --activate-profiles AlsoSlowTests
|
||||
|
||||
|
||||
- name: CodeCov - JavaParser Core
|
||||
uses: codecov/codecov-action@v5.4.3
|
||||
timeout-minutes: 10
|
||||
with:
|
||||
files: javaparser-core-testing/target/site/jacoco/jacoco.xml,javaparser-core-testing-bdd/target/site/jacoco/jacoco.xml
|
||||
fail_ci_if_error: false # optional (default = false) -- fail the build if upload to codecov.io fails
|
||||
verbose: false # optional (default = false):
|
||||
flags: javaparser-core,AlsoSlowTests,${{ matrix.os }},jdk-${{ matrix.jdk }}
|
||||
env_vars: OS,JDK
|
||||
|
||||
- name: CodeCov - JavaParser Symbol Solver
|
||||
uses: codecov/codecov-action@v5.4.3
|
||||
timeout-minutes: 10
|
||||
with:
|
||||
file: javaparser-symbol-solver-testing/target/site/jacoco/jacoco.xml
|
||||
fail_ci_if_error: false # optional (default = false) -- fail the build if upload to codecov.io fails
|
||||
verbose: false # optional (default = false):
|
||||
flags: javaparser-symbol-solver,AlsoSlowTests,${{ matrix.os }},jdk-${{ matrix.jdk }}
|
||||
env_vars: OS,JDK
|
||||
81
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/workflows/prepare_release_changelog.yml
vendored
Normal file
81
Assignment-2/javaparser-javaparser-parent-3.27.0/.github/workflows/prepare_release_changelog.yml
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
name: Build Snapshot
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
## (testing only) Trigger the workflow on any pull request
|
||||
#pull_request:
|
||||
|
||||
jobs:
|
||||
|
||||
generate_changelog:
|
||||
name: Generate Changelog
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
# Check out current repository
|
||||
- name: Fetch Sources
|
||||
uses: actions/checkout@v4.2.2
|
||||
|
||||
# Setup Java 11 environment for the next steps
|
||||
- name: Setup Java
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: zulu
|
||||
java-version: 11
|
||||
|
||||
# Set environment variables
|
||||
- name: Generate Changelog
|
||||
id: vars
|
||||
shell: bash
|
||||
working-directory: ./scripts
|
||||
run: |
|
||||
## By convention, the "next" milestone is named "next release"
|
||||
./run_generate_changelog_by_milestone_title.sh "next release"
|
||||
|
||||
SHA_LONG=$(git rev-parse HEAD)
|
||||
SHA_SHORT=$(git rev-parse --short HEAD)
|
||||
CHANGELOG="$(<temp_changelog.md)"
|
||||
RELEASE_TITLE="SNAPSHOT - $SHA_SHORT"
|
||||
RELEASE_TAG_NAME="v_snapshot_$SHA_SHORT"
|
||||
|
||||
echo "sha_long=$SHA_LONG" >> $GITHUB_OUTPUT
|
||||
echo "sha_short=$SHA_SHORT" >> $GITHUB_OUTPUT
|
||||
echo "changelog<<EOF" >> $GITHUB_OUTPUT
|
||||
echo "$CHANGELOG" >> $GITHUB_OUTPUT
|
||||
echo "EOF" >> $GITHUB_OUTPUT
|
||||
echo "release_title=$RELEASE_TITLE" >> $GITHUB_OUTPUT
|
||||
echo "release_tag_name=$RELEASE_TAG_NAME" >> $GITHUB_OUTPUT
|
||||
|
||||
|
||||
- name: Output variables
|
||||
run: |
|
||||
echo sha_short = ${{ steps.vars.outputs.sha_short }}
|
||||
echo sha_long = ${{ steps.vars.outputs.sha_long }}
|
||||
echo changelog = "${{ steps.vars.outputs.changelog }}"
|
||||
echo changelog = "${{ steps.vars.outputs.release_title }}"
|
||||
echo changelog = "${{ steps.vars.outputs.release_tag_name }}"
|
||||
|
||||
|
||||
# Remove old release drafts by using the curl request for the available releases with draft flag
|
||||
- name: Remove Old Release Drafts
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh api repos/{owner}/{repo}/releases \
|
||||
--jq '.[] | select(.draft == true) | .id' \
|
||||
| xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
|
||||
|
||||
|
||||
# Create new release draft - which is not publicly visible and requires manual acceptance
|
||||
- name: Create Release Draft
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
gh release create ${{ steps.vars.outputs.release_tag_name }} \
|
||||
--target ${{ steps.vars.outputs.sha_long }} \
|
||||
--draft \
|
||||
--prerelease \
|
||||
--title "${{ steps.vars.outputs.release_title }}" \
|
||||
--notes-file ./scripts/temp_changelog.md
|
||||
|
||||
28
Assignment-2/javaparser-javaparser-parent-3.27.0/.gitignore
vendored
Normal file
28
Assignment-2/javaparser-javaparser-parent-3.27.0/.gitignore
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
/lib
|
||||
bin
|
||||
.manager
|
||||
target
|
||||
.settings
|
||||
*~
|
||||
.project
|
||||
.classpath
|
||||
.idea/
|
||||
*.iml
|
||||
release.properties
|
||||
**/.DS_Store
|
||||
**/pom.xml.releaseBackup
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
.gradle
|
||||
*.ipr
|
||||
*.iws
|
||||
build-*
|
||||
*.asc
|
||||
build
|
||||
out
|
||||
.java-version
|
||||
117
Assignment-2/javaparser-javaparser-parent-3.27.0/.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
117
Assignment-2/javaparser-javaparser-parent-3.27.0/.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2007-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if(mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if(mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if(!outputFile.getParentFile().exists()) {
|
||||
if(!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
|
||||
}
|
||||
BIN
Assignment-2/javaparser-javaparser-parent-3.27.0/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
Assignment-2/javaparser-javaparser-parent-3.27.0/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
19
Assignment-2/javaparser-javaparser-parent-3.27.0/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
19
Assignment-2/javaparser-javaparser-parent-3.27.0/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.10/apache-maven-3.9.10-bin.zip
|
||||
@@ -0,0 +1,79 @@
|
||||
## Getting started
|
||||
Here is some information that's good to know when contributing to JavaParser:
|
||||
|
||||
- There is some interesting information on the [wiki](https://github.com/javaparser/javaparser/wiki).
|
||||
- We work on JavaParser because we like to, not because it earns us money. Please remember that we try to run a professional project in our spare time, on a budget of zero.
|
||||
- Be sure to check [the coding guidelines](https://github.com/javaparser/javaparser/wiki/Coding-Guidelines) which are easily used by installing the formatting rules as described there.
|
||||
- If you're new and like to casually contribute something, check out the [easy issues](https://github.com/javaparser/javaparser/labels/Easy).
|
||||
- If you're new and would like to become a member, start your own project that uses JavaParser.
|
||||
We noticed we get the best feedback from those.
|
||||
Here are [some fun project ideas](https://github.com/javaparser/javaparser/labels/fun%20project%20idea).
|
||||
- If you start working on an issue, please say so with a comment in the issue.
|
||||
- If you know how to fix a problem, please fix it and open a pull request instead of opening an issue.
|
||||
- If you would like to add new nodes, or new fields to existing nodes, check out the [Guide to Adding New Nodes and Fields](https://github.com/javaparser/javaparser/wiki/A-Detailed-Guide-to-Adding-New-Nodes-and-Fields).
|
||||
|
||||
Thanks for helping!
|
||||
|
||||
## Contribution Workflow
|
||||
|
||||
Our development workflow is based on Pull Request. If you are not familiar with the Pull Requests, we suggest you to checkout the [Github Documentation](https://help.github.com/articles/creating-a-pull-request/) for more information.
|
||||
|
||||
1. **Fork** the JavaParser project. If you already have a fork, ensure to fetch the latest commits.
|
||||
2. In your forked project, **create a branch** related to the issue you are working on. This is important to ensure that your pull request will not contain unrelated work.
|
||||
3. When your work in your branch is done, **push your branch to your forked repository**.
|
||||
4. Go back to the [javaparser project site](https://github.com/javaparser/javaparser) and it should have a message offering to **create a pull request**. If it doesn't you can [create one manually](https://github.com/javaparser/javaparser/compare).
|
||||
|
||||
### Remember:
|
||||
- A pull request should include tests. You can either use BDD or JUnit.
|
||||
- Every pull request will automatically be checked by a few tools. Make sure AppVeyor and Travis are green.
|
||||
- Pull requests often stay open for at least a few days to give people a chance to review it.
|
||||
- A pull request is merged when all comments on it have been resolved.
|
||||
- If you create a pull request for an issue, mention the issue in the format #123 to make github link it automatically.
|
||||
- Before creating a commit (or at least before submitting a pull request), please reformat the project with the instructions given below
|
||||
to avoid any formatting-related issues during the review.
|
||||
|
||||
### Note on formatting the project:
|
||||
|
||||
- If you are developing on a machine with bash installed, execute `./run_core_metamodel_generator.sh && ./run_core_generators.sh`. This
|
||||
will re-run all of the code generators and then re-format the entire project as a final step. This ensures that:
|
||||
- All the code that needs to be generated has been generated correctly.
|
||||
- None of the changes you've added will be overwritten by code generation in the future.
|
||||
- All of your changes are correctly formatted (including changes made during code generation, for example whitespace changes).
|
||||
|
||||
The PR check for style runs these generators and checks that the diff after doing so is empty, so if you've run this on your machine,
|
||||
then that check should not fail.
|
||||
|
||||
- If you are developing on a machine without bash, execute `./mvnw spotless:apply`. This will re-format the project, but without
|
||||
running the code generators. This will be sufficient in many cases, but it's still possible that changes are introduced during
|
||||
code generation which would cause the PR style check to fail. If this happens, some manual changes are required.
|
||||
|
||||
To fix this:
|
||||
1. Go to the job output for the failed `Spotless check` job by clicking the red cross next to the job.
|
||||
2. Scroll to the bottom of the `Generate code and format` output tab.
|
||||
3. There, you will see output from the diff command showing what failed. For example, in https://github.com/javaparser/javaparser/actions/runs/10389076737/job/28766249645,
|
||||
that output is:
|
||||
```
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/RecordPatternExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/RecordPatternExpr.java
|
||||
index 7bc7f46b9..429889e35 100644
|
||||
--- a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/RecordPatternExpr.java
|
||||
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/RecordPatternExpr.java
|
||||
@@ -17,7 +17,6 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
-
|
||||
package com.github.javaparser.ast.expr;
|
||||
|
||||
import static com.github.javaparser.utils.Utils.assertNotNull;
|
||||
Error: Process completed with exit code 1.
|
||||
```
|
||||
|
||||
4. Verify that this output does not overwrite any code you wrote which would change the behaviour. If it does, you probably implemented
|
||||
something manually when it should've been generated and this will be overwritten next time the code generators are run. This requires
|
||||
a manual fix to your code to prevent issues in the future.
|
||||
5. If no major issues are found, copy this output, excluding the `[INFO] --...` line and the `Error: Process complete with exit code 1.`
|
||||
line and paste that into a patch file (for example, `/tmp/style.patch`, but the name and location aren't important).
|
||||
6. From the javaparser project directory, run `git apply /tmp/style.patch` (substituting `/tmp/style.patch` for the path of your
|
||||
patch file). `git status` should now show that all the files mentioned in the patch are modified.
|
||||
7. Add and commit the changes and push to update the PR.
|
||||
309
Assignment-2/javaparser-javaparser-parent-3.27.0/FEATURES.md
Normal file
309
Assignment-2/javaparser-javaparser-parent-3.27.0/FEATURES.md
Normal file
@@ -0,0 +1,309 @@
|
||||
|
||||
# Features
|
||||
This page describes the changes introduced within each version.
|
||||
|
||||
Language-related changes should normally have a validator, used in conjunction with the grammar, as part of the parsing process.
|
||||
|
||||
Where a change is not a language-related change _(e.g. JVM and garbage collection changes)_, this is marked as "Not Applicable (NA)".
|
||||
|
||||
## JDK 1.0 - January 1996
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#JDK_1.0
|
||||
## JDK 1.1 - February 1997
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#JDK_1.1
|
||||
## JDK 1.2 - December 1998
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#J2SE_1.2
|
||||
## JDK 1.3 - May 2000
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#J2SE_1.3
|
||||
## JDK 1.4 - February 2002
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#J2SE_1.4
|
||||
## JDK 5 - September 2004
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#J2SE_5.0
|
||||
## JDK 6 - December 2006
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#Java_SE_6
|
||||
|
||||
## JDK 7 - July 2011
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#Java_SE_7
|
||||
|
||||
|
||||
## JDK 8 - March 2014
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#Java_SE_8
|
||||
|
||||
- JSR 335, JEP 126: Language-level support for lambda expressions (officially, lambda expressions; unofficially, closures) under Project Lambda and default methods (virtual extension methods) which allow the addition of methods to interfaces without breaking existing implementations. There was an ongoing debate in the Java community on whether to add support for lambda expressions. Sun later declared that lambda expressions would be included in Java and asked for community input to refine the feature. Supporting lambda expressions also enables functional-style operations on streams of elements, such as MapReduce-inspired transformations on collections. Default methods allow an author of an API to add new methods to an interface without breaking the old code using it. Although it was not their primary intent, default methods also allow multiple inheritance of behavior (but not state).
|
||||
- JSR 223, JEP 174: Project Nashorn, a JavaScript runtime which allows developers to embed JavaScript code within applications
|
||||
- JSR 308, JEP 104: Annotation on Java types, Unsigned integer arithmetic
|
||||
- JSR 337, JEP 120: Repeating annotations
|
||||
- JSR 310, JEP 150: Date and time API
|
||||
- JEP 178: Statically-linked JNI libraries
|
||||
- JEP 153: Launch JavaFX applications (direct launching of JavaFX application JARs)
|
||||
- JEP 122: Remove the permanent generation
|
||||
|
||||
## JDK 9 - September 2017
|
||||
Source: https://en.wikipedia.org/wiki/Java_version_history#Java_SE_9
|
||||
|
||||
- JSR 376: Modularization of the JDK under Project Jigsaw (Java Platform Module System)
|
||||
- JEP 222: JShell: The Java Shell (a Java REPL)
|
||||
- JEP 295: Ahead-of-time compilation
|
||||
- JEP 268: XML catalogs
|
||||
- JEP 266: More concurrency updates. It includes a Java implementation of Reactive Streams, including a new Flow class that included the interfaces previously provided by Reactive Streams
|
||||
- JEP 193: Variable handles: define a standard means to invoke the equivalents of various java.util.concurrent.atomic and sun.misc.Unsafe operations
|
||||
- JEP 282: jlink: The Java Linker: create a tool that can assemble and optimize a set of modules and their dependencies into a custom run-time image. It effectively allows to produce a fully usable executable including the JVM to run it. JavaDB was removed from JDK
|
||||
- JEP 263: HiDPI graphics: automatic scaling and sizing
|
||||
- JEP 254: Compact Strings
|
||||
- JEP 213: Milling Project Coin
|
||||
|
||||
## JDK 10 - March 2018
|
||||
Source: https://openjdk.java.net/projects/jdk/10/
|
||||
|
||||
Java 10 support [complete on 25/Feb/2018](https://github.com/javaparser/javaparser/blob/master/changelog.md#version-3515)
|
||||
|
||||
| JEP | Status | JavaParser Since | Description |
|
||||
|:--------------------------------------------:|:----------------:|:---------------------------------------------------------------:|---------------------------------------------------------|
|
||||
| [JEP 286](https://openjdk.java.net/jeps/286) | **Release** | **Supported Since: v3.5.15<br>Released on: 25/Feb/2018** | **Local-Variable Type Inference** |
|
||||
| [JEP 296](https://openjdk.java.net/jeps/296) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Consolidate the JDK Forest into a Single Repository~~ |
|
||||
| [JEP 304](https://openjdk.java.net/jeps/304) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Garbage-Collector Interface~~ |
|
||||
| [JEP 307](https://openjdk.java.net/jeps/307) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Parallel Full GC for G1~~ |
|
||||
| [JEP 310](https://openjdk.java.net/jeps/310) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Application Class-Data Sharing~~ |
|
||||
| [JEP 312](https://openjdk.java.net/jeps/312) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Thread-Local Handshakes~~ |
|
||||
| [JEP 313](https://openjdk.java.net/jeps/313) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Remove the Native-Header Generation Tool (javah)~~ |
|
||||
| [JEP 314](https://openjdk.java.net/jeps/314) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Additional Unicode Language-Tag Extensions~~ |
|
||||
| [JEP 316](https://openjdk.java.net/jeps/316) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Heap Allocation on Alternative Memory Devices~~ |
|
||||
| [JEP 317](https://openjdk.java.net/jeps/317) | ~~Experimental~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Experimental Java-Based JIT Compiler~~ |
|
||||
| [JEP 319](https://openjdk.java.net/jeps/319) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Root Certificates~~ |
|
||||
| [JEP 322](https://openjdk.java.net/jeps/322) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Time-Based Release Versioning~~ |
|
||||
|
||||
## JDK 11 - September 2018
|
||||
Source: https://openjdk.java.net/projects/jdk/11/
|
||||
|
||||
Java 11 support [complete on 19/Aug/2018](https://github.com/javaparser/javaparser/blob/master/changelog.md#version-3618)
|
||||
|
||||
| JEP | Status | JavaParser Since | Description |
|
||||
|:--------------------------------------------:|:----------------:|:----------------------------------------------------------------------------------------------------:|------------------------------------------------------------------|
|
||||
| [JEP 323](https://openjdk.java.net/jeps/323) | **Release** | **Supported Since: v3.xx.yy<br>Released on: dd/mmm/yyyy** | **Local-Variable Syntax for Lambda Parameters** |
|
||||
| [JEP 327](https://openjdk.java.net/jeps/327) | _Release_ | _Discussion Needed <sup id="a_11_JEP327">[JEP327](#f_11_JEP327)</sup>_ | _Unicode 10_ |
|
||||
| [JEP 181](https://openjdk.java.net/jeps/181) | _Release_ | _Discussion Needed <sup id="a_11_JEP181">[JEP181](#f_11_JEP181)</sup>_ | _Nest-Based Access Control_ |
|
||||
| [JEP 309](https://openjdk.java.net/jeps/309) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Dynamic Class-File Constants~~ |
|
||||
| [JEP 315](https://openjdk.java.net/jeps/315) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Improve Aarch64 Intrinsics~~ |
|
||||
| [JEP 318](https://openjdk.java.net/jeps/318) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Epsilon: A No-Op Garbage Collector~~ |
|
||||
| [JEP 320](https://openjdk.java.net/jeps/320) | ~~_Release_~~ | ~~_Not Applicable - Not a language change (NA) <sup id="a_11_JEP320">[JEP320](#f_11_JEP320)</sup>_~~ | ~~Remove the Java EE and CORBA Modules~~ |
|
||||
| [JEP 321](https://openjdk.java.net/jeps/321) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~HTTP Client (Standard)~~ |
|
||||
| [JEP 324](https://openjdk.java.net/jeps/324) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Key Agreement with Curve25519 and Curve448~~ |
|
||||
| [JEP 328](https://openjdk.java.net/jeps/328) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Flight Recorder~~ |
|
||||
| [JEP 329](https://openjdk.java.net/jeps/329) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~ChaCha20 and Poly1305 Cryptographic Algorithms~~ |
|
||||
| [JEP 330](https://openjdk.java.net/jeps/330) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Launch Single-File Source-Code Programs~~ |
|
||||
| [JEP 331](https://openjdk.java.net/jeps/331) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Low-Overhead Heap Profiling~~ |
|
||||
| [JEP 332](https://openjdk.java.net/jeps/332) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Transport Layer Security (TLS) 1.3~~ |
|
||||
| [JEP 333](https://openjdk.java.net/jeps/333) | ~~Experimental~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~ZGC: A Scalable Low-Latency Garbage Collector (Experimental)~~ |
|
||||
| [JEP 335](https://openjdk.java.net/jeps/335) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Deprecate the Nashorn JavaScript Engine~~ |
|
||||
| [JEP 336](https://openjdk.java.net/jeps/336) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Deprecate the Pack200 Tools and API~~ |
|
||||
|
||||
##### Footnotes:
|
||||
|
||||
- <b id="f_11_JEP181">JEP181</b> - Based on a cursory reading of this JEP, it is unclear if this is a change that affects JavaParser.
|
||||
Comments/discussion on this are welcomed. [↩](#a_11_JEP181)
|
||||
- <b id="f_11_JEP327">JEP327</b> - Based on a cursory reading of this JEP, it is unclear if this is a change that affects JavaParser.
|
||||
Comments/discussion on this are welcomed. [↩](#a_11_JEP327)
|
||||
- <b id="f_11_JEP320">JEP320</b> - JEP 320 is marked as NA. This is because JavaParser does not make use of classes within these packages,
|
||||
and any users of JavaParser will need to provide the relevant files in order to do parsing/solving
|
||||
(e.g. as source files, a jar, or via reflection). [↩](#a_11_JEP320)
|
||||
|
||||
|
||||
## JDK 12 - March 2019
|
||||
Source: https://openjdk.java.net/projects/jdk/12/
|
||||
|
||||
Parsing support for Java 12 (including preview features) [complete on 03/Feb/2019](https://github.com/javaparser/javaparser/blob/master/changelog.md#version-3110)
|
||||
|
||||
Resolution support for Java 12 complete on ??/??/2019
|
||||
|
||||
| JEP | Status | JavaParser Since | Description |
|
||||
|:--------------------------------------------:|:----------------:|:---------------------------------------------------------------:|-------------------------------------------------------------------|
|
||||
| [JEP 325](https://openjdk.java.net/jeps/325) | **_Preview_** | **Supported Since: v3.11.0<br>Released on: 03/Feb/2019** | Switch Expressions (Preview) |
|
||||
| [JEP 189](https://openjdk.java.net/jeps/189) | ~~Experimental~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Shenandoah: A Low-Pause-Time Garbage Collector (Experimental)~~ |
|
||||
| [JEP 230](https://openjdk.java.net/jeps/230) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Microbenchmark Suite~~ |
|
||||
| [JEP 334](https://openjdk.java.net/jeps/334) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~JVM Constants API~~ |
|
||||
| [JEP 340](https://openjdk.java.net/jeps/340) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~One AArch64 Port, Not Two~~ |
|
||||
| [JEP 341](https://openjdk.java.net/jeps/341) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Default CDS Archives~~ |
|
||||
| [JEP 344](https://openjdk.java.net/jeps/344) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Abortable Mixed Collections for G1~~ |
|
||||
| [JEP 346](https://openjdk.java.net/jeps/346) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Promptly Return Unused Committed Memory from G1~~ |
|
||||
|
||||
## JDK 13 - September 2018
|
||||
Source: https://openjdk.java.net/projects/jdk/13/
|
||||
|
||||
No language specification changes in JDK 13 -- thus no "complete" date. Details of preview support is below.
|
||||
|
||||
| JEP | Status | JavaParser Since | Description |
|
||||
|:--------------------------------------------:|:-------------:|:---------------------------------------------------------------:|---------------------------------------|
|
||||
| [JEP 354](https://openjdk.java.net/jeps/354) | **_Preview_** | **Supported Since: v3.11.0<br>Released on: 03/Feb/2019** | Switch Expressions (Preview) |
|
||||
| [JEP 355](https://openjdk.java.net/jeps/355) | **_Preview_** | **Supported Since: v3.14.0<br>Released on: 05/May/2019** | Text Blocks (Preview) |
|
||||
| [JEP 350](https://openjdk.java.net/jeps/350) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Dynamic CDS Archives~~ |
|
||||
| [JEP 351](https://openjdk.java.net/jeps/351) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~ZGC: Uncommit Unused Memory~~ |
|
||||
| [JEP 353](https://openjdk.java.net/jeps/353) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Reimplement the Legacy Socket API~~ |
|
||||
|
||||
|
||||
|
||||
## JDK 14 - March 2020
|
||||
Source: https://openjdk.java.net/projects/jdk/14/
|
||||
|
||||
Switch support was complete during preview status.
|
||||
|
||||
The preview features of records are work-in-progress.
|
||||
|
||||
| JEP | Status | JavaParser Since | Description |
|
||||
|:--------------------------------------------:|:---------------:|:-----------------------------------------------------------------------------------------------------------------:|---------------------------------------------------------------|
|
||||
| [JEP 361](https://openjdk.java.net/jeps/361) | **Release** | **Supported Since: v3.xx.yy<br>Released on: dd/mmm/yyyy** | **Switch Expressions (Standard)** |
|
||||
| [JEP 368](https://openjdk.java.net/jeps/368) | **2nd Preview** | **Supported Since: v3.14.0<br>Released on: 05/May/2019** | **Text Blocks (Second Preview)** |
|
||||
| [JEP 305](https://openjdk.java.net/jeps/305) | **_Preview_** | **Supported Since: v3.18.0<br>Released on: 01/Dec/2020** | **Pattern Matching for `instanceof` (Preview)** |
|
||||
| [JEP 359](https://openjdk.java.net/jeps/359) | **_Preview_** | **Partial Support Since: v3.22.0<br>Released on: 11/May/2021 <sup id="a_14_JEP359">[JEP343](#f_14_JEP359)</sup>** | **Records (Preview)** |
|
||||
| [JEP 343](https://openjdk.java.net/jeps/343) | ~~_Incubator_~~ | ~~_Not Applicable (NA)<sup id="a_14_JEP343">[JEP343](#f_14_JEP343)</sup>_~~ | ~~Packaging Tool (Incubator)~~ |
|
||||
| [JEP 345](https://openjdk.java.net/jeps/345) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~NUMA-Aware Memory Allocation for G1~~ |
|
||||
| [JEP 349](https://openjdk.java.net/jeps/349) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~JFR Event Streaming~~ |
|
||||
| [JEP 352](https://openjdk.java.net/jeps/352) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Non-Volatile Mapped Byte Buffers~~ |
|
||||
| [JEP 358](https://openjdk.java.net/jeps/358) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Helpful NullPointerExceptions~~ |
|
||||
| [JEP 362](https://openjdk.java.net/jeps/362) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Deprecate the Solaris and SPARC Ports~~ |
|
||||
| [JEP 363](https://openjdk.java.net/jeps/363) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Remove the Concurrent Mark Sweep (CMS) Garbage Collector~~ |
|
||||
| [JEP 364](https://openjdk.java.net/jeps/364) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~ZGC on macOS~~ |
|
||||
| [JEP 365](https://openjdk.java.net/jeps/365) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~ZGC on Windows~~ |
|
||||
| [JEP 366](https://openjdk.java.net/jeps/366) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Deprecate the ParallelScavenge + SerialOld GC Combination~~ |
|
||||
| [JEP 367](https://openjdk.java.net/jeps/367) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Remove the Pack200 Tools and API~~ |
|
||||
| [JEP 370](https://openjdk.java.net/jeps/370) | ~~_Release_~~ | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Foreign-Memory Access API (Incubator)~~ |
|
||||
|
||||
##### Footnotes:
|
||||
|
||||
- <b id="f_14_JEP343">JEP343</b> - JEP 343 is marked as not applicable, as it relates to packaging of apps - e.g. as `.exe`/`.msi`/`.deb`/`.rpm`/`.pkg`/`.dmg`.
|
||||
The JEP describes the layout/structure of the output file, suggesting that _maybe_ in the future the files may be examined, and _potentially_ used similarly to a `.jar` or set of `.class` files.
|
||||
This is not going to be actively pursued (_especially_ since this is still in the incubator stage), though tested PRs are always welcome.
|
||||
[↩](#a_14_JEP343)
|
||||
|
||||
|
||||
- <b id="f_14_JEP359">JEP359</b> - The behaviour of records changed between preview/2nd preview/release.
|
||||
Unless otherwise stated, the JavaParser implementation follows the released behaviour.
|
||||
Additionally, note that "partial" support refers to javaparser-core being complete since 3.21.0, and javaparser-symbol-solver-core support is TBC.
|
||||
[↩](#a_14_JEP359)
|
||||
|
||||
|
||||
|
||||
## JDK 15 - September 2020
|
||||
Source: https://openjdk.java.net/projects/jdk/15/
|
||||
|
||||
Note: Unless otherwise stated, the JavaParser implementations of features follows the released behaviour.
|
||||
|
||||
| JEP | Status | JavaParser Since | Description |
|
||||
|:--------------------------------------------:|:---------------:|:-----------------------------------------------------------------------------------------------------------------:|--------------------------------------------------------|
|
||||
| [JEP 378](https://openjdk.java.net/jeps/378) | **_Release_** | **Supported Since: v3.14.0<br>Released on: 05/May/2019** | **Text Blocks** |
|
||||
| [JEP 384](https://openjdk.java.net/jeps/384) | **_Release_** | **Partial Support Since: v3.22.0<br>Released on: 11/May/2021 <sup id="a_15_JEP384">[JEP384](#f_15_JEP384)</sup>** | **Records (Second Preview)** |
|
||||
| [JEP 375](https://openjdk.java.net/jeps/375) | **_Release_** | **Supported Since: v3.18.0<br>Released on: 01/Dec/2020** | **Pattern Matching for `instanceof` (Second Preview)** |
|
||||
| [JEP 360](https://openjdk.java.net/jeps/360) | **_Preview_** | | **Sealed Classes (Preview)** |
|
||||
| [JEP 339](https://openjdk.java.net/jeps/339) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Edwards-Curve Digital Signature Algorithm (EdDSA)~~ |
|
||||
| [JEP 371](https://openjdk.java.net/jeps/371) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Hidden Classes~~ |
|
||||
| [JEP 372](https://openjdk.java.net/jeps/372) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Remove the Nashorn JavaScript Engine~~ |
|
||||
| [JEP 373](https://openjdk.java.net/jeps/373) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Reimplement the Legacy DatagramSocket API~~ |
|
||||
| [JEP 374](https://openjdk.java.net/jeps/374) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Disable and Deprecate Biased Locking~~ |
|
||||
| [JEP 377](https://openjdk.java.net/jeps/377) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~ZGC: A Scalable Low-Latency Garbage Collector~~ |
|
||||
| [JEP 379](https://openjdk.java.net/jeps/379) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Shenandoah: A Low-Pause-Time Garbage Collector~~ |
|
||||
| [JEP 381](https://openjdk.java.net/jeps/381) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Remove the Solaris and SPARC Ports~~ |
|
||||
| [JEP 383](https://openjdk.java.net/jeps/383) | **_Incubator_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Foreign-Memory Access API (Second Incubator)~~ |
|
||||
| [JEP 385](https://openjdk.java.net/jeps/385) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Deprecate RMI Activation for Removal~~ |
|
||||
|
||||
- <b id="f_15_JEP384">JEP384</b> - The behaviour of records changed between preview/2nd preview/release.
|
||||
Unless otherwise stated, the JavaParser implementation follows the released behaviour.
|
||||
Additionally, note that "partial" support refers to javaparser-core being complete since 3.21.0, and javaparser-symbol-solver-core support is TBC.
|
||||
[↩](#a_15_JEP384)
|
||||
|
||||
|
||||
|
||||
## JDK 16 - March 2021
|
||||
Source: https://openjdk.java.net/projects/jdk/16/
|
||||
|
||||
Note: Unless otherwise stated, the JavaParser implementations of features follows the released behaviour.
|
||||
|
||||
| JEP | Status | JavaParser Since | Description |
|
||||
|:--------------------------------------------:|:---------------:|:------------------------------------------------------------------------------------------------------------------------------:|---------------------------------------------------|
|
||||
| [JEP 395](https://openjdk.java.net/jeps/395) | **_Release_** | **Parser Support Since: v3.22.0<br>Released on: 11/May/2021, Solving TBC <sup id="a_16_JEP384">[JEP395](#f_16_JEP395)</sup>** | **Records** |
|
||||
| [JEP 394](https://openjdk.java.net/jeps/394) | **_Release_** | **Supported Since: v3.18.0<br>Released on: 01/Dec/2020** | **Pattern Matching for `instanceof`** |
|
||||
| [JEP 397](https://openjdk.java.net/jeps/397) | **2nd Preview** | | **Sealed Classes (Second Preview)** |
|
||||
| [JEP 338](https://openjdk.java.net/jeps/338) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Vector API (Incubator)~~ |
|
||||
| [JEP 347](https://openjdk.java.net/jeps/347) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Enable C++14 Language Features~~ |
|
||||
| [JEP 357](https://openjdk.java.net/jeps/357) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Migrate from Mercurial to Git~~ |
|
||||
| [JEP 369](https://openjdk.java.net/jeps/369) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Migrate to GitHub~~ |
|
||||
| [JEP 376](https://openjdk.java.net/jeps/376) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~ZGC: Concurrent Thread-Stack Processing~~ |
|
||||
| [JEP 380](https://openjdk.java.net/jeps/380) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Unix-Domain Socket Channels~~ |
|
||||
| [JEP 386](https://openjdk.java.net/jeps/386) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Alpine Linux Port~~ |
|
||||
| [JEP 387](https://openjdk.java.net/jeps/387) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Elastic Metaspace~~ |
|
||||
| [JEP 388](https://openjdk.java.net/jeps/388) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Windows/AArch64 Port~~ |
|
||||
| [JEP 389](https://openjdk.java.net/jeps/389) | **_Incubator_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Foreign Linker API (Incubator)~~ |
|
||||
| [JEP 390](https://openjdk.java.net/jeps/390) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Warnings for Value-Based Classes~~ |
|
||||
| [JEP 392](https://openjdk.java.net/jeps/392) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Packaging Tool~~ |
|
||||
| [JEP 393](https://openjdk.java.net/jeps/393) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Foreign-Memory Access API (Third Incubator)~~ |
|
||||
| [JEP 396](https://openjdk.java.net/jeps/396) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | ~~Strongly Encapsulate JDK Internals by Default~~ |
|
||||
|
||||
- <b id="f_16_JEP395">JEP395</b> - The behaviour of records changed between preview/2nd preview/release.
|
||||
Unless otherwise stated, the JavaParser implementation follows the released behaviour.
|
||||
Additionally, note that "partial" support refers to javaparser-core being complete since 3.21.0, and javaparser-symbol-solver-core support is TBC.
|
||||
[↩](#a_16_JEP395)
|
||||
|
||||
|
||||
## JDK 17 - September 2021
|
||||
Source: https://openjdk.java.net/projects/jdk/17/
|
||||
|
||||
Note: Unless otherwise stated, the JavaParser implementations of features follows the released behaviour.
|
||||
|
||||
| JEP | Status | JavaParser Since | Description |
|
||||
|:--------------------------------------------:|:-------------------:|:---------------------------------------------------------------:|------------------------------------------------|
|
||||
| [JEP 306](https://openjdk.java.net/jeps/306) | **_Release_** | | Restore Always-Strict Floating-Point Semantics |
|
||||
| [JEP 409](https://openjdk.java.net/jeps/409) | **_Release_** | | Sealed Classes |
|
||||
| [JEP 406](https://openjdk.java.net/jeps/406) | **_Preview_** | | Pattern Matching for `switch` (Preview) |
|
||||
| [JEP 356](https://openjdk.java.net/jeps/356) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Enhanced Pseudo-Random Number Generators |
|
||||
| [JEP 382](https://openjdk.java.net/jeps/382) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | New macOS Rendering Pipeline |
|
||||
| [JEP 391](https://openjdk.java.net/jeps/391) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | macOS/AArch64 Port |
|
||||
| [JEP 398](https://openjdk.java.net/jeps/398) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Deprecate the Applet API for Removal |
|
||||
| [JEP 403](https://openjdk.java.net/jeps/403) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Strongly Encapsulate JDK Internals |
|
||||
| [JEP 407](https://openjdk.java.net/jeps/407) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Remove RMI Activation |
|
||||
| [JEP 410](https://openjdk.java.net/jeps/410) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Remove the Experimental AOT and JIT Compiler |
|
||||
| [JEP 411](https://openjdk.java.net/jeps/411) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Deprecate the Security Manager for Removal |
|
||||
| [JEP 412](https://openjdk.java.net/jeps/412) | **_Incubator_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Foreign Function & Memory API (Incubator) |
|
||||
| [JEP 414](https://openjdk.java.net/jeps/414) | **_2nd Incubator_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Vector API (Second Incubator) |
|
||||
| [JEP 415](https://openjdk.java.net/jeps/415) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Context-Specific Deserialization Filters |
|
||||
|
||||
|
||||
|
||||
## JDK 18 - March 2022
|
||||
Source: https://openjdk.java.net/projects/jdk/18/
|
||||
|
||||
Note: Unless otherwise stated, the JavaParser implementations of features follows the released behaviour.
|
||||
|
||||
### Schedule
|
||||
|
||||
2021/12/09 Rampdown Phase One (fork from main line)
|
||||
2022/01/20 Rampdown Phase Two
|
||||
2022/02/10 Initial Release Candidate
|
||||
2022/02/24 Final Release Candidate
|
||||
2022/03/22 General Availability
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
| JEP | Status | JavaParser Since | Description |
|
||||
|:--------------------------------------------:|:-------------------:|:---------------------------------------------------------------:|--------------------------------------------------|
|
||||
| [JEP 413](https://openjdk.java.net/jeps/413) | **_Release_** | | Code Snippets in Java API Documentation |
|
||||
| [JEP 420](https://openjdk.java.net/jeps/420) | **_Preview_** | | Pattern Matching for `switch` (Second Preview) |
|
||||
| [JEP 400](https://openjdk.java.net/jeps/400) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | UTF-8 by Default |
|
||||
| [JEP 408](https://openjdk.java.net/jeps/408) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Simple Web Server |
|
||||
| [JEP 416](https://openjdk.java.net/jeps/416) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Reimplement Core Reflection with Method Handles |
|
||||
| [JEP 417](https://openjdk.java.net/jeps/417) | **_3rd Incubator_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Vector API (Third Incubator) |
|
||||
| [JEP 418](https://openjdk.java.net/jeps/418) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Internet-Address Resolution SPI |
|
||||
| [JEP 419](https://openjdk.java.net/jeps/419) | **_2nd Incubator_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Foreign Function & Memory API (Second Incubator) |
|
||||
| [JEP 421](https://openjdk.java.net/jeps/421) | **_Release_** | ~~_Not Applicable - Not a language specification change (NA)_~~ | Deprecate Finalization for Removal |
|
||||
|
||||
|
||||
|
||||
## JDK 19 - _targeted for September 2022_
|
||||
Source: https://openjdk.java.net/projects/jdk/18/
|
||||
|
||||
Note: Unless otherwise stated, the JavaParser implementations of features follows the released behaviour.
|
||||
|
||||
### Features
|
||||
|
||||
JEPs targeted to JDK 19, so far
|
||||
422: Linux/RISC-V Port
|
||||
|
||||
Last update: 2022/3/18 16:38 UTC
|
||||
|
||||
6
Assignment-2/javaparser-javaparser-parent-3.27.0/LICENSE
Normal file
6
Assignment-2/javaparser-javaparser-parent-3.27.0/LICENSE
Normal file
@@ -0,0 +1,6 @@
|
||||
JavaParser is available either under the terms of the LGPL License or the Apache License. You as the user are entitled to choose the terms under which to adopt JavaParser.
|
||||
|
||||
For details about the LGPL License please refer to LICENSE.LGPL. Please note
|
||||
that LGPL is just an extension to GPL, located in LICENSE.GPL.
|
||||
|
||||
For details about the Apache License please refer to LICENSE.APACHE
|
||||
202
Assignment-2/javaparser-javaparser-parent-3.27.0/LICENSE.APACHE
Normal file
202
Assignment-2/javaparser-javaparser-parent-3.27.0/LICENSE.APACHE
Normal file
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
674
Assignment-2/javaparser-javaparser-parent-3.27.0/LICENSE.GPL
Normal file
674
Assignment-2/javaparser-javaparser-parent-3.27.0/LICENSE.GPL
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
Java 1.5 japa.parser and Abstract Syntax Tree
|
||||
Copyright (C) 2007 J<>lio Vilmar Gesser
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
Java 1.5 japa.parser and Abstract Syntax Tree Copyright (C) 2007 J<>lio Vilmar Gesser
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
165
Assignment-2/javaparser-javaparser-parent-3.27.0/LICENSE.LGPL
Normal file
165
Assignment-2/javaparser-javaparser-parent-3.27.0/LICENSE.LGPL
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
@@ -0,0 +1 @@
|
||||
Fixes #9999.
|
||||
@@ -0,0 +1,42 @@
|
||||
version: '{build}'
|
||||
os: Windows Server 2012
|
||||
|
||||
environment:
|
||||
appveyor_build_worker_cloud: gce
|
||||
|
||||
init:
|
||||
# Setup autocrlf -- by default, appveyor uses autocrlf input
|
||||
# ... This affects tests which expect resource files to have the systems's line separator.
|
||||
- git config --global core.autocrlf true
|
||||
|
||||
install:
|
||||
# Download maven
|
||||
- ps: |
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
if (!(Test-Path -Path "C:\maven" )) {
|
||||
(new-object System.Net.WebClient).DownloadFile(
|
||||
'http://www.us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip',
|
||||
'C:\maven-bin.zip'
|
||||
)
|
||||
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
|
||||
}
|
||||
# Setup environment variables for Maven and Java
|
||||
- cmd: SET JAVA_HOME=C:\Program Files\Java\jdk10
|
||||
- cmd: SET M2_HOME=C:\maven\apache-maven-3.6.3
|
||||
- cmd: SET MAVEN_OPTS=-Xmx1g
|
||||
- cmd: SET JAVA_OPTS=-Xmx1g
|
||||
- cmd: SET PATH=C:\maven\apache-maven-3.6.3\bin;%JAVA_HOME%\bin;%PATH%
|
||||
# Output the git config re: autocrlf to verify the "current" setting
|
||||
- cmd: git config core.autocrlf
|
||||
|
||||
# Appveyor is used for testing only -- the build script is not required.
|
||||
build_script:
|
||||
- echo ignore this
|
||||
|
||||
test_script:
|
||||
- mvn -B clean install --batch-mode
|
||||
|
||||
# Use of the cache speeds up future tests, meaning that dependencies do not need to be re-downloaded on every run.
|
||||
cache:
|
||||
- C:\maven\
|
||||
- C:\Users\appveyor\.m2
|
||||
3133
Assignment-2/javaparser-javaparser-parent-3.27.0/changelog.md
Normal file
3133
Assignment-2/javaparser-javaparser-parent-3.27.0/changelog.md
Normal file
File diff suppressed because it is too large
Load Diff
90
Assignment-2/javaparser-javaparser-parent-3.27.0/codecov.yml
Normal file
90
Assignment-2/javaparser-javaparser-parent-3.27.0/codecov.yml
Normal file
@@ -0,0 +1,90 @@
|
||||
codecov:
|
||||
require_ci_to_pass: true
|
||||
|
||||
|
||||
coverage:
|
||||
|
||||
## Configure decimal places, rounding, and the colour ranges used:
|
||||
## https://docs.codecov.com/docs/coverage-configuration
|
||||
precision: 3
|
||||
round: down
|
||||
range: "70...90" # Colour range - 70% coverage (and below) is solid red, 90% coverage (and above) is solid green.
|
||||
|
||||
|
||||
## These statuses show at the bottom of the PR.
|
||||
## Split the coverage reporting into sub-projects.
|
||||
## https://docs.codecov.io/docs/commit-status
|
||||
## https://docs.codecov.io/docs/codecovyml-reference#coveragestatus
|
||||
status:
|
||||
|
||||
## Status configuration of the whole project
|
||||
project:
|
||||
|
||||
whole_project: ## Whole project (note no flags specified)
|
||||
target: auto ## Increase overall coverage on each pull request (compared to the previous base commit)
|
||||
threshold: 0.5% ## Flexibility in allowing a minor drop in coverage
|
||||
|
||||
javaparser-core: ## Just JavaParser Core
|
||||
target: auto ## Increase overall coverage on each pull request (compared to the previous base commit)
|
||||
threshold: 0.5% ## Flexibility in allowing a minor drop in coverage
|
||||
## TBC: Unclear if setting flags AND paths is redundant
|
||||
flags:
|
||||
- javaparser-core
|
||||
paths:
|
||||
- javaparser-core/src/main/java*
|
||||
- javaparser-core-testing/src/test/java*
|
||||
- javaparser-core-testing-bdd/src/test/java*
|
||||
|
||||
javaparser-symbol-solver: ## Just the Symbol Solver
|
||||
target: auto ## Increase overall coverage on each pull request (compared to the previous base commit)
|
||||
threshold: 0.5% ## Flexibility in allowing a minor drop in coverage
|
||||
## TBC: Unclear if setting flags AND paths is redundant
|
||||
flags:
|
||||
- javaparser-symbol-solver
|
||||
paths:
|
||||
- javaparser-symbol-solver-core/src/main/java*
|
||||
- javaparser-symbol-solver-testing/src/test/java*
|
||||
|
||||
## Status configuration of ONLY the changed lines
|
||||
patch:
|
||||
|
||||
|
||||
|
||||
## Configuration of the comments that get added to PRs
|
||||
comment:
|
||||
layout: "reach,diff,flags,files,footer"
|
||||
behavior: default
|
||||
require_changes: false
|
||||
### Do not comment on the PR until coverage reports for all builds has been received
|
||||
### Note: 54 = three OSs (mac, windows, ubuntu) x nine java levels (8,9,10,11,12,13,14,15,16) x two modules (jp-core, jss)
|
||||
after_n_builds: 54
|
||||
|
||||
|
||||
## Flags defined elsewhere MUST also be defined here (required for GitHub PR checks information)
|
||||
flags:
|
||||
javaparser-core:
|
||||
paths:
|
||||
- javaparser-core/src/main/java*
|
||||
- javaparser-core-testing/src/test/java*
|
||||
- javaparser-core-testing-bdd/src/test/java*
|
||||
carryforward: false
|
||||
javaparser-symbol-solver:
|
||||
paths:
|
||||
- javaparser-symbol-solver-core/src/main/java*
|
||||
- javaparser-symbol-solver-testing/src/test/java*
|
||||
carryforward: false
|
||||
|
||||
|
||||
# ## New section re: flags
|
||||
# ## No individual flags are added to YAML and flag names are automatically ingested from the Uploader
|
||||
# ## https://docs.codecov.com/docs/flags
|
||||
# flag_management:
|
||||
# default_rules:
|
||||
# carryforward: false
|
||||
|
||||
|
||||
ignore:
|
||||
- "/javaparser-core/src/main/java-templates/**" ## This source is ...
|
||||
# - "/javaparser-core/src/main/javacc-support/**" ## This source is generated by JavaCC
|
||||
- "/javaparser-symbol-solver-testing/src/test/test_sourcecode/**" ## This source is used as inputs to test cases
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
||||
<module name="Checker">
|
||||
|
||||
<!-- Based on documentation: https://github.com/javaparser/javaparser/wiki/Coding-Guidelines -->
|
||||
|
||||
<property name="fileExtensions" value="java"/>
|
||||
|
||||
<!-- Wrap lines at 120 characters -->
|
||||
<module name="LineLength">
|
||||
<property name="max" value="120"/>
|
||||
<property name="severity" value="warning" />
|
||||
</module>
|
||||
|
||||
<module name="TreeWalker">
|
||||
|
||||
<!-- Indent with four spaces -->
|
||||
<module name="Indentation">
|
||||
<property name="severity" value="warning" />
|
||||
</module>
|
||||
|
||||
<!-- Type and Method annotations go on a separate line -->
|
||||
<module name="AnnotationLocation">
|
||||
<property name="allowSamelineMultipleAnnotations" value="false"/>
|
||||
<property name="allowSamelineSingleParameterlessAnnotation" value="false"/>
|
||||
<property name="allowSamelineParameterizedAnnotation" value="false"/>
|
||||
<property name="severity" value="warning" />
|
||||
</module>
|
||||
|
||||
<!-- Import order -->
|
||||
<module name="CustomImportOrder">
|
||||
<property name="customImportOrderRules"
|
||||
value="THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/>
|
||||
<property name="specialImportsRegExp" value="^javax\."/>
|
||||
<property name="standardPackageRegExp" value="^java\."/>
|
||||
<property name="sortImportsInGroupAlphabetically" value="false"/>
|
||||
<property name="separateLineBetweenGroups" value="false"/>
|
||||
<property name="severity" value="warning" />
|
||||
</module>
|
||||
|
||||
<!-- Imports that are not used, should be removed -->
|
||||
<module name="UnusedImports"/>
|
||||
|
||||
</module>
|
||||
</module>
|
||||
@@ -0,0 +1,295 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<profiles version="12">
|
||||
<profile kind="CodeFormatterProfile" name="JavaParser" version="12">
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="119"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_lambda_body" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="18"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.source" value="1.8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="18"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.8"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="false"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="120"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
|
||||
<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
|
||||
</profile>
|
||||
</profiles>
|
||||
@@ -0,0 +1,38 @@
|
||||
<code_scheme name="JavaParser">
|
||||
<option name="OTHER_INDENT_OPTIONS">
|
||||
<value>
|
||||
<option name="INDENT_SIZE" value="4" />
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="8" />
|
||||
<option name="TAB_SIZE" value="4" />
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="SMART_TABS" value="true" />
|
||||
<option name="LABEL_INDENT_SIZE" value="0" />
|
||||
<option name="LABEL_INDENT_ABSOLUTE" value="false" />
|
||||
<option name="USE_RELATIVE_INDENTS" value="false" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="JD_ALIGN_PARAM_COMMENTS" value="false" />
|
||||
<option name="JD_ALIGN_EXCEPTION_COMMENTS" value="false" />
|
||||
<option name="WRAP_COMMENTS" value="true" />
|
||||
<XML>
|
||||
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||
</XML>
|
||||
<codeStyleSettings language="JAVA">
|
||||
<option name="RIGHT_MARGIN" value="120" />
|
||||
<indentOptions>
|
||||
<option name="SMART_TABS" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="Scala">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="SMART_TABS" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
<codeStyleSettings language="XML">
|
||||
<indentOptions>
|
||||
<option name="USE_TAB_CHARACTER" value="true" />
|
||||
<option name="SMART_TABS" value="true" />
|
||||
</indentOptions>
|
||||
</codeStyleSettings>
|
||||
</code_scheme>
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
|
||||
<!-- THIS IS A TEMPLATE/SAMPLE FOR THE ~/.m2/settings.xml CONFIGURATION FILE, USED e.g. WHEN PERFORMING A RELEASE -->
|
||||
<!-- Values should be placed into environment variables (preferred), though you _can_ insert the values directly below. -->
|
||||
|
||||
<servers>
|
||||
<server>
|
||||
<!-- Credentials for Sonatype OSSRH (OSS Repository Hosting) -->
|
||||
<!-- These are the same credentials you use for https://oss.sonatype.org/ and their JIRA ticketing system. -->
|
||||
<!-- https://central.sonatype.org/pages/apache-maven.html -->
|
||||
<id>ossrh</id>
|
||||
<username>${env.MAVEN_OSSRH_USERNAME}</username>
|
||||
<password>${env.MAVEN_OSSRH_PASSWORD}</password>
|
||||
</server>
|
||||
</servers>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>ossrh</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<properties>
|
||||
<!-- You may need to adjust to the reflect the executable within your environment e.g. `gpg2` -->
|
||||
<gpg.executable>gpg</gpg.executable>
|
||||
<gpg.keyname>${env.MAVEN_GPG_KEYNAME}</gpg.keyname>
|
||||
<gpg.passphrase>${env.MAVEN_GPG_PASSPHRASE}</gpg.passphrase>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
</settings>
|
||||
@@ -0,0 +1,29 @@
|
||||
@startuml
|
||||
node core {
|
||||
[Java parser] <-- [AST]
|
||||
[Javadoc parser]
|
||||
[AST] <-- [lexical preserving printer]
|
||||
[AST] <-- [concrete syntax model]
|
||||
[concrete syntax model] <-- [lexical preserving printer]
|
||||
events <-- [lexical preserving printer]
|
||||
[AST] <-- [comments inserter]
|
||||
[AST] <-- [visitors]
|
||||
[AST] <-- [meta model]
|
||||
[AST] <-- [pretty printer]
|
||||
[visitors] <-- [pretty printer]
|
||||
[AST] - symbol_resolution
|
||||
[AST] - events
|
||||
[visitors] <-- [code generators]
|
||||
[AST] <-- [code generators]
|
||||
[meta model] <-- [code generators]
|
||||
[AST] <-- [JSON (de)serializer]
|
||||
[Java parser] <- [source root]
|
||||
}
|
||||
node symbol-solver {
|
||||
[AST] <- [model]
|
||||
symbol_resolution <- [model]
|
||||
[model] <-- [core]
|
||||
[model] <-- [logic]
|
||||
[logic] <-- [core]
|
||||
}
|
||||
@enduml
|
||||
132
Assignment-2/javaparser-javaparser-parent-3.27.0/doc/readme.md
Normal file
132
Assignment-2/javaparser-javaparser-parent-3.27.0/doc/readme.md
Normal file
@@ -0,0 +1,132 @@
|
||||
|
||||
<!--
|
||||
Note that edits to this readme should be done via `docs/readme.md`.
|
||||
Modifying this file directly within the root directory risks it being overwritten.
|
||||
-->
|
||||
|
||||
# JavaParser
|
||||
|
||||
[](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.github.javaparser%22%20AND%20a%3A%22javaparser-core%22)
|
||||
[](https://travis-ci.org/javaparser/javaparser)
|
||||
[](https://app.codecov.io/gh/javaparser/javaparser?branch=master)
|
||||
[](https://gitter.im/javaparser/javaparser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](LICENSE)
|
||||
[](https://doi.org/10.5281/zenodo.2667378)
|
||||
|
||||
|
||||
This project contains a set of libraries implementing a Java 1.0 - Java 15 Parser with advanced analysis functionalities. This includes preview features to Java 13, with Java 14 preview features work-in-progress.
|
||||
|
||||
Our main site is at [JavaParser.org](http://javaparser.org)
|
||||
|
||||
## Setup
|
||||
|
||||
The project binaries are available in Maven Central.
|
||||
|
||||
We strongly advise users to adopt Maven, Gradle or another build system for their projects.
|
||||
If you are not familiar with them we suggest taking a look at the maven quickstart projects
|
||||
([javaparser-maven-sample](https://github.com/javaparser/javaparser-maven-sample),
|
||||
[javasymbolsolver-maven-sample](https://github.com/javaparser/javasymbolsolver-maven-sample)).
|
||||
|
||||
Just add the following to your maven configuration or tailor to your own dependency management system.
|
||||
|
||||
[Please refer to the Migration Guide when upgrading from 2.5.1 to 3.0.0+](https://github.com/javaparser/javaparser/wiki/Migration-Guide)
|
||||
|
||||
**Maven**:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<artifactId>javaparser-symbol-solver-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**:
|
||||
|
||||
```
|
||||
implementation 'com.github.javaparser:javaparser-symbol-solver-core:${project.version}'
|
||||
```
|
||||
|
||||
Since Version 3.5.10, the JavaParser project includes the JavaSymbolSolver.
|
||||
While JavaParser generates an Abstract Syntax Tree, JavaSymbolSolver analyzes that AST and is able to find
|
||||
the relation between an element and its declaration (e.g. for a variable name it could be a parameter of a method, providing information about its type, position in the AST, ect).
|
||||
|
||||
Using the dependency above will add both JavaParser and JavaSymbolSolver to your project. If you only need the core functionality of parsing Java source code in order to traverse and manipulate the generated AST, you can reduce your projects boilerplate by only including JavaParser to your project:
|
||||
|
||||
**Maven**:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<artifactId>javaparser-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**:
|
||||
|
||||
```
|
||||
implementation 'com.github.javaparser:javaparser-core:${project.version}'
|
||||
```
|
||||
|
||||
Since version 3.6.17 the AST can be serialized to JSON.
|
||||
There is a separate module for this:
|
||||
|
||||
**Maven**:
|
||||
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<artifactId>javaparser-core-serialization</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
**Gradle**:
|
||||
|
||||
```
|
||||
implementation 'com.github.javaparser:javaparser-core-serialization:${project.version}'
|
||||
```
|
||||
|
||||
## How To Compile Sources
|
||||
|
||||
If you checked out the project's source code from GitHub, you can build the project with maven using:
|
||||
```
|
||||
mvnw clean install
|
||||
```
|
||||
|
||||
If you want to generate the packaged jar files from the source files, you run the following maven command:
|
||||
```
|
||||
mvnw package
|
||||
```
|
||||
|
||||
**NOTE** the jar files for the two modules can be found in:
|
||||
- `javaparser/javaparser-core/target/javaparser-core-\<version\>.jar`
|
||||
- `javaparser-symbol-solver-core/target/javaparser-symbol-solver-core-\<version\>.jar`
|
||||
|
||||
If you checkout the sources and want to view the project in an IDE, it is best to first generate some of the source files;
|
||||
otherwise you will get many compilation complaints in the IDE. (`mvnw clean install` already does this for you.)
|
||||
|
||||
```
|
||||
mvnw javacc:javacc
|
||||
```
|
||||
|
||||
If you modify the code of the AST nodes, specifically if you add or remove fields or node classes,
|
||||
the code generators will update a lot of code for you.
|
||||
The `run_metamodel_generator.sh` script will rebuild the metamodel,
|
||||
which is used by the code generators which are run by `run_core_generators.sh`
|
||||
Make sure that `javaparser-core` at least compiles before you run these.
|
||||
|
||||
**Note**: for Eclipse IDE follow the steps described in the wiki: https://github.com/javaparser/javaparser/wiki/Eclipse-Project-Setup-Guide
|
||||
|
||||
## More information
|
||||
|
||||
#### [JavaParser.org](https://javaparser.org) is the main information site.
|
||||
|
||||
## License
|
||||
|
||||
JavaParser is available either under the terms of the LGPL License or the Apache License. You as the user are entitled to choose the terms under which adopt JavaParser.
|
||||
|
||||
For details about the LGPL License please refer to [LICENSE.LGPL](ttps://github.com/javaparser/javaparser/blob/master/LICENSE.LGPL).
|
||||
|
||||
For details about the Apache License please refer to [LICENSE.APACHE](ttps://github.com/javaparser/javaparser/blob/master/LICENSE.APACHE).
|
||||
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>javaparser-parent</artifactId>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<version>3.27.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>javaparser-core-generators</artifactId>
|
||||
<description>A code generator framework, and the generators for javaparser-core</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<artifactId>javaparser-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>run-generators</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-javaparser-core</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<classpathScope>test</classpathScope>
|
||||
<mainClass>com.github.javaparser.generator.core.CoreGenerator</mainClass>
|
||||
<arguments>
|
||||
<argument>${project.basedir}</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator;
|
||||
|
||||
import com.github.javaparser.ParseResult;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CompilationUnitGenerator extends Generator {
|
||||
|
||||
protected CompilationUnitGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate() throws Exception {
|
||||
List<ParseResult<CompilationUnit>> parsedCus = sourceRoot.tryToParse();
|
||||
for (ParseResult<CompilationUnit> cu : parsedCus) {
|
||||
cu.ifSuccessful(this::generateCompilationUnit);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void generateCompilationUnit(CompilationUnit compilationUnit);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator;
|
||||
|
||||
import static com.github.javaparser.ast.NodeList.toNodeList;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.Generated;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.CallableDeclaration;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.expr.Expression;
|
||||
import com.github.javaparser.ast.expr.StringLiteralExpr;
|
||||
import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A general pattern that the generators in this module will follow.
|
||||
*/
|
||||
public abstract class Generator {
|
||||
protected final SourceRoot sourceRoot;
|
||||
|
||||
protected Generator(SourceRoot sourceRoot) {
|
||||
this.sourceRoot = sourceRoot;
|
||||
}
|
||||
|
||||
public abstract void generate() throws Exception;
|
||||
|
||||
protected <T extends Node & NodeWithAnnotations<?>> void annotateGenerated(T node) {
|
||||
annotate(node, Generated.class, new StringLiteralExpr(getClass().getName()));
|
||||
}
|
||||
|
||||
protected <T extends Node & NodeWithAnnotations<?>> void annotateSuppressWarnings(T node) {
|
||||
annotate(node, SuppressWarnings.class, new StringLiteralExpr("unchecked"));
|
||||
}
|
||||
|
||||
protected void annotateOverridden(MethodDeclaration method) {
|
||||
annotate(method, Override.class, null);
|
||||
}
|
||||
|
||||
private <T extends Node & NodeWithAnnotations<?>> void annotate(T node, Class<?> annotation, Expression content) {
|
||||
node.setAnnotations(node.getAnnotations().stream()
|
||||
.filter(a -> !a.getNameAsString().equals(annotation.getSimpleName()))
|
||||
.collect(toNodeList()));
|
||||
|
||||
if (content != null) {
|
||||
node.addSingleMemberAnnotation(annotation.getSimpleName(), content);
|
||||
} else {
|
||||
node.addMarkerAnnotation(annotation.getSimpleName());
|
||||
}
|
||||
node.tryAddImportToParentCompilationUnit(annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that looks for a method or constructor with an identical signature as "callable" and replaces it
|
||||
* with callable. If not found, adds callable. When the new callable has no javadoc, any old javadoc will be kept.
|
||||
*/
|
||||
protected void addOrReplaceWhenSameSignature(
|
||||
ClassOrInterfaceDeclaration containingClassOrInterface, CallableDeclaration<?> callable) {
|
||||
addMethod(containingClassOrInterface, callable, () -> containingClassOrInterface.addMember(callable));
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that looks for a method or constructor with an identical signature as "callable" and replaces it
|
||||
* with callable. If not found, fails. When the new callable has no javadoc, any old javadoc will be kept. The
|
||||
* method or constructor is annotated with the generator class.
|
||||
*/
|
||||
protected void replaceWhenSameSignature(
|
||||
ClassOrInterfaceDeclaration containingClassOrInterface, CallableDeclaration<?> callable) {
|
||||
addMethod(containingClassOrInterface, callable, () -> {
|
||||
throw new AssertionError(f(
|
||||
"Wanted to regenerate a method with signature %s in %s, but it wasn't there.",
|
||||
callable.getSignature(), containingClassOrInterface.getNameAsString()));
|
||||
});
|
||||
}
|
||||
|
||||
private void addMethod(
|
||||
ClassOrInterfaceDeclaration containingClassOrInterface,
|
||||
CallableDeclaration<?> callable,
|
||||
Runnable onNoExistingMethod) {
|
||||
List<CallableDeclaration<?>> existingCallables =
|
||||
containingClassOrInterface.getCallablesWithSignature(callable.getSignature());
|
||||
if (existingCallables.isEmpty()) {
|
||||
onNoExistingMethod.run();
|
||||
return;
|
||||
}
|
||||
if (existingCallables.size() > 1) {
|
||||
throw new AssertionError(f(
|
||||
"Wanted to regenerate a method with signature %s in %s, but found more than one.",
|
||||
callable.getSignature(), containingClassOrInterface.getNameAsString()));
|
||||
}
|
||||
final CallableDeclaration<?> existingCallable = existingCallables.get(0);
|
||||
callable.setJavadocComment(callable.getJavadocComment()
|
||||
.orElseGet(() -> existingCallable.getJavadocComment().orElse(null)));
|
||||
annotateGenerated(callable);
|
||||
containingClassOrInterface.getMembers().replace(existingCallable, callable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all methods from containingClassOrInterface that have the same signature as callable. This is not used by
|
||||
* any code, but it is useful when changing a generator and you need to get rid of a set of outdated methods.
|
||||
*/
|
||||
protected void removeMethodWithSameSignature(
|
||||
ClassOrInterfaceDeclaration containingClassOrInterface, CallableDeclaration<?> callable) {
|
||||
for (CallableDeclaration<?> existingCallable :
|
||||
containingClassOrInterface.getCallablesWithSignature(callable.getSignature())) {
|
||||
containingClassOrInterface.remove(existingCallable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.JavaParserMetaModel;
|
||||
import com.github.javaparser.utils.Log;
|
||||
import com.github.javaparser.utils.Pair;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Makes it easier to generate code in the core AST nodes. The generateNode method will get every node type passed to
|
||||
* it, ready for modification.
|
||||
*/
|
||||
public abstract class NodeGenerator extends Generator {
|
||||
protected NodeGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
public final void generate() throws Exception {
|
||||
Log.info("Running %s", () -> getClass().getSimpleName());
|
||||
for (BaseNodeMetaModel nodeMetaModel : JavaParserMetaModel.getNodeMetaModels()) {
|
||||
Pair<CompilationUnit, ClassOrInterfaceDeclaration> result = parseNode(nodeMetaModel);
|
||||
generateNode(nodeMetaModel, result.a, result.b);
|
||||
}
|
||||
after();
|
||||
}
|
||||
|
||||
protected Pair<CompilationUnit, ClassOrInterfaceDeclaration> parseNode(BaseNodeMetaModel nodeMetaModel) {
|
||||
CompilationUnit nodeCu =
|
||||
sourceRoot.parse(nodeMetaModel.getPackageName(), nodeMetaModel.getTypeName() + ".java");
|
||||
ClassOrInterfaceDeclaration nodeCoid = nodeCu.getClassByName(nodeMetaModel.getTypeName())
|
||||
.orElseThrow(() -> new AssertionError("Can't find class"));
|
||||
return new Pair<>(nodeCu, nodeCoid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Annotate a method with the {@link Override} annotation, if it overrides other method.
|
||||
*
|
||||
* @param nodeMetaModel The current meta model.
|
||||
* @param methodDeclaration The method declaration.
|
||||
*/
|
||||
protected void annotateWhenOverridden(BaseNodeMetaModel nodeMetaModel, MethodDeclaration methodDeclaration) {
|
||||
Class<? extends Node> type = nodeMetaModel.getType();
|
||||
Class<?> superClass = type.getSuperclass();
|
||||
|
||||
boolean isOverriding = Arrays.stream(superClass.getMethods())
|
||||
.filter(m -> m.getName().equals(methodDeclaration.getNameAsString()))
|
||||
.anyMatch(m -> m.getParameters().length
|
||||
== methodDeclaration.getParameters().size());
|
||||
if (isOverriding) {
|
||||
annotateOverridden(methodDeclaration);
|
||||
}
|
||||
}
|
||||
|
||||
protected void after() throws Exception {}
|
||||
|
||||
protected abstract void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid)
|
||||
throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator;
|
||||
|
||||
import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.expr.MarkerAnnotationExpr;
|
||||
import com.github.javaparser.ast.expr.Name;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.JavaParserMetaModel;
|
||||
import com.github.javaparser.utils.Log;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Makes it easier to generate visitor classes.
|
||||
* It will create missing visit methods on the fly,
|
||||
* and will ask you to fill in the bodies of the visit methods.
|
||||
*/
|
||||
public abstract class VisitorGenerator extends Generator {
|
||||
private final String pkg;
|
||||
private final String visitorClassName;
|
||||
private final String returnType;
|
||||
private final String argumentType;
|
||||
private final boolean createMissingVisitMethods;
|
||||
|
||||
protected VisitorGenerator(
|
||||
SourceRoot sourceRoot,
|
||||
String pkg,
|
||||
String visitorClassName,
|
||||
String returnType,
|
||||
String argumentType,
|
||||
boolean createMissingVisitMethods) {
|
||||
super(sourceRoot);
|
||||
this.pkg = pkg;
|
||||
this.visitorClassName = visitorClassName;
|
||||
this.returnType = returnType;
|
||||
this.argumentType = argumentType;
|
||||
this.createMissingVisitMethods = createMissingVisitMethods;
|
||||
}
|
||||
|
||||
public final void generate() throws Exception {
|
||||
Log.info("Running %s", () -> getClass().getSimpleName());
|
||||
|
||||
final CompilationUnit compilationUnit = sourceRoot
|
||||
.tryToParse(pkg, visitorClassName + ".java")
|
||||
.getResult()
|
||||
.get();
|
||||
|
||||
Optional<ClassOrInterfaceDeclaration> visitorClassOptional = compilationUnit.getClassByName(visitorClassName);
|
||||
if (!visitorClassOptional.isPresent()) {
|
||||
visitorClassOptional = compilationUnit.getInterfaceByName(visitorClassName);
|
||||
}
|
||||
final ClassOrInterfaceDeclaration visitorClass = visitorClassOptional.get();
|
||||
|
||||
JavaParserMetaModel.getNodeMetaModels().stream()
|
||||
.filter((baseNodeMetaModel) -> !baseNodeMetaModel.isAbstract())
|
||||
.forEach(node -> generateVisitMethodForNode(node, visitorClass, compilationUnit));
|
||||
after();
|
||||
}
|
||||
|
||||
protected void after() throws Exception {}
|
||||
|
||||
private void generateVisitMethodForNode(
|
||||
BaseNodeMetaModel node, ClassOrInterfaceDeclaration visitorClass, CompilationUnit compilationUnit) {
|
||||
final Optional<MethodDeclaration> existingVisitMethod = visitorClass.getMethods().stream()
|
||||
.filter(m -> "visit".equals(m.getNameAsString()))
|
||||
.filter(m -> m.getParameter(0).getType().toString().equals(node.getTypeName()))
|
||||
.findFirst();
|
||||
|
||||
if (existingVisitMethod.isPresent()) {
|
||||
generateVisitMethodBody(node, existingVisitMethod.get(), compilationUnit);
|
||||
} else if (createMissingVisitMethods) {
|
||||
MethodDeclaration newVisitMethod = visitorClass
|
||||
.addMethod("visit")
|
||||
.addParameter(node.getTypeNameGenerified(), "n")
|
||||
.addParameter(argumentType, "arg")
|
||||
.setType(returnType);
|
||||
if (!visitorClass.isInterface()) {
|
||||
newVisitMethod
|
||||
.addAnnotation(new MarkerAnnotationExpr(new Name("Override")))
|
||||
.addModifier(PUBLIC);
|
||||
}
|
||||
generateVisitMethodBody(node, newVisitMethod, compilationUnit);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core;
|
||||
|
||||
import static com.github.javaparser.ParserConfiguration.LanguageLevel.RAW;
|
||||
|
||||
import com.github.javaparser.ParserConfiguration;
|
||||
import com.github.javaparser.StaticJavaParser;
|
||||
import com.github.javaparser.generator.core.node.*;
|
||||
import com.github.javaparser.generator.core.other.BndGenerator;
|
||||
import com.github.javaparser.generator.core.other.TokenKindGenerator;
|
||||
import com.github.javaparser.generator.core.quality.NotNullGenerator;
|
||||
import com.github.javaparser.generator.core.visitor.*;
|
||||
import com.github.javaparser.utils.Log;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* Generates all generated visitors in the javaparser-core module.
|
||||
* Suggested usage is by running the run_core_generators.sh script.
|
||||
* You may want to run_metamodel_generator.sh before that.
|
||||
*/
|
||||
public class CoreGenerator {
|
||||
private static final ParserConfiguration parserConfiguration = new ParserConfiguration().setLanguageLevel(RAW)
|
||||
// .setStoreTokens(false)
|
||||
// .setAttributeComments(false)
|
||||
// .setLexicalPreservationEnabled(true)
|
||||
;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 1) {
|
||||
throw new RuntimeException("Need 1 parameter: the JavaParser source checkout root directory.");
|
||||
}
|
||||
Log.setAdapter(new Log.StandardOutStandardErrorAdapter());
|
||||
final Path root = Paths.get(args[0], "..", "javaparser-core", "src", "main", "java");
|
||||
final SourceRoot sourceRoot = new SourceRoot(root, parserConfiguration)
|
||||
// .setPrinter(LexicalPreservingPrinter::print)
|
||||
;
|
||||
StaticJavaParser.setConfiguration(parserConfiguration);
|
||||
|
||||
final Path generatedJavaCcRoot =
|
||||
Paths.get(args[0], "..", "javaparser-core", "target", "generated-sources", "javacc");
|
||||
final SourceRoot generatedJavaCcSourceRoot = new SourceRoot(generatedJavaCcRoot, parserConfiguration)
|
||||
// .setPrinter(LexicalPreservingPrinter::print)
|
||||
;
|
||||
|
||||
new CoreGenerator().run(sourceRoot, generatedJavaCcSourceRoot);
|
||||
|
||||
sourceRoot.saveAll();
|
||||
}
|
||||
|
||||
private void run(SourceRoot sourceRoot, SourceRoot generatedJavaCcSourceRoot) throws Exception {
|
||||
new TypeCastingGenerator(sourceRoot).generate();
|
||||
new GenericListVisitorAdapterGenerator(sourceRoot).generate();
|
||||
new GenericVisitorAdapterGenerator(sourceRoot).generate();
|
||||
new GenericVisitorWithDefaultsGenerator(sourceRoot).generate();
|
||||
new EqualsVisitorGenerator(sourceRoot).generate();
|
||||
new ObjectIdentityEqualsVisitorGenerator(sourceRoot).generate();
|
||||
new NoCommentEqualsVisitorGenerator(sourceRoot).generate();
|
||||
new VoidVisitorAdapterGenerator(sourceRoot).generate();
|
||||
new VoidVisitorGenerator(sourceRoot).generate();
|
||||
new VoidVisitorWithDefaultsGenerator(sourceRoot).generate();
|
||||
new GenericVisitorGenerator(sourceRoot).generate();
|
||||
new HashCodeVisitorGenerator(sourceRoot).generate();
|
||||
new ObjectIdentityHashCodeVisitorGenerator(sourceRoot).generate();
|
||||
new NoCommentHashCodeVisitorGenerator(sourceRoot).generate();
|
||||
new CloneVisitorGenerator(sourceRoot).generate();
|
||||
new ModifierVisitorGenerator(sourceRoot).generate();
|
||||
|
||||
new PropertyGenerator(sourceRoot).generate();
|
||||
new RemoveMethodGenerator(sourceRoot).generate();
|
||||
new ReplaceMethodGenerator(sourceRoot).generate();
|
||||
new CloneGenerator(sourceRoot).generate();
|
||||
new GetMetaModelGenerator(sourceRoot).generate();
|
||||
new MainConstructorGenerator(sourceRoot).generate();
|
||||
new NodeModifierGenerator(sourceRoot).generate();
|
||||
new AcceptGenerator(sourceRoot).generate();
|
||||
new TokenKindGenerator(sourceRoot, generatedJavaCcSourceRoot).generate();
|
||||
new BndGenerator(sourceRoot).generate();
|
||||
|
||||
new NotNullGenerator(sourceRoot).generate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.node;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.visitor.GenericVisitor;
|
||||
import com.github.javaparser.ast.visitor.VoidVisitor;
|
||||
import com.github.javaparser.generator.NodeGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
public class AcceptGenerator extends NodeGenerator {
|
||||
private final MethodDeclaration genericAccept;
|
||||
private final MethodDeclaration voidAccept;
|
||||
|
||||
public AcceptGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
genericAccept = parseBodyDeclaration(
|
||||
"@Override public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) { return v.visit(this, arg); }")
|
||||
.asMethodDeclaration();
|
||||
voidAccept = parseBodyDeclaration(
|
||||
"@Override public <A> void accept(final VoidVisitor<A> v, final A arg) { v.visit(this, arg); }")
|
||||
.asMethodDeclaration();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
|
||||
if (nodeMetaModel.isAbstract()) {
|
||||
return;
|
||||
}
|
||||
nodeCu.addImport(GenericVisitor.class);
|
||||
nodeCu.addImport(VoidVisitor.class);
|
||||
addOrReplaceWhenSameSignature(nodeCoid, genericAccept);
|
||||
addOrReplaceWhenSameSignature(nodeCoid, voidAccept);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.node;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.visitor.CloneVisitor;
|
||||
import com.github.javaparser.generator.NodeGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
public class CloneGenerator extends NodeGenerator {
|
||||
public CloneGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
|
||||
nodeCu.addImport(CloneVisitor.class);
|
||||
MethodDeclaration cloneMethod = (MethodDeclaration) parseBodyDeclaration(f(
|
||||
"@Override public %s clone() { return (%s) accept(new CloneVisitor(), null); }",
|
||||
nodeMetaModel.getTypeNameGenerified(), nodeMetaModel.getTypeNameGenerified()));
|
||||
addOrReplaceWhenSameSignature(nodeCoid, cloneMethod);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.node;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.generator.NodeGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.JavaParserMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
public class GetMetaModelGenerator extends NodeGenerator {
|
||||
public GetMetaModelGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
|
||||
final MethodDeclaration getMetaModelMethod = (MethodDeclaration) parseBodyDeclaration(f(
|
||||
"%s public %s getMetaModel() { return JavaParserMetaModel.%s; }",
|
||||
nodeMetaModel.isRootNode() ? "" : "@Override",
|
||||
nodeMetaModel.getClass().getSimpleName(),
|
||||
nodeMetaModel.getMetaModelFieldName()));
|
||||
|
||||
addOrReplaceWhenSameSignature(nodeCoid, getMetaModelMethod);
|
||||
nodeCu.addImport(nodeMetaModel.getClass().getName());
|
||||
nodeCu.addImport(JavaParserMetaModel.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.node;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseExplicitConstructorInvocationStmt;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.TokenRange;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.ConstructorDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.NodeGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SeparatedItemStringBuilder;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
public class MainConstructorGenerator extends NodeGenerator {
|
||||
public MainConstructorGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
|
||||
if (nodeMetaModel.is(Node.class)) {
|
||||
return;
|
||||
}
|
||||
ConstructorDeclaration constructor = new ConstructorDeclaration()
|
||||
.setPublic(true)
|
||||
.setName(nodeCoid.getNameAsString())
|
||||
.addParameter(TokenRange.class, "tokenRange")
|
||||
.setJavadocComment("\n * This constructor is used by the parser and is considered private.\n ");
|
||||
|
||||
BlockStmt body = constructor.getBody();
|
||||
|
||||
SeparatedItemStringBuilder superCall = new SeparatedItemStringBuilder("super(", ", ", ");");
|
||||
superCall.append("tokenRange");
|
||||
for (PropertyMetaModel parameter : nodeMetaModel.getConstructorParameters()) {
|
||||
constructor.addParameter(parameter.getTypeNameForSetter(), parameter.getName());
|
||||
if (nodeMetaModel.getDeclaredPropertyMetaModels().contains(parameter)) {
|
||||
body.addStatement(f("%s(%s);", parameter.getSetterMethodName(), parameter.getName()));
|
||||
} else {
|
||||
superCall.append(parameter.getName());
|
||||
}
|
||||
}
|
||||
|
||||
body.getStatements().addFirst(parseExplicitConstructorInvocationStmt(superCall.toString()));
|
||||
|
||||
body.addStatement("customInitialization();");
|
||||
|
||||
addOrReplaceWhenSameSignature(nodeCoid, constructor);
|
||||
nodeCu.addImport(TokenRange.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.node;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.generator.NodeGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
public class NodeModifierGenerator extends NodeGenerator {
|
||||
public NodeModifierGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
|
||||
nodeCoid.setFinal(false).setPublic(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.node;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseType;
|
||||
import static com.github.javaparser.ast.Modifier.Keyword.FINAL;
|
||||
import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC;
|
||||
import static com.github.javaparser.ast.Modifier.createModifierList;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
import static com.github.javaparser.utils.Utils.camelCaseToScreaming;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.EnumConstantDeclaration;
|
||||
import com.github.javaparser.ast.body.EnumDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.observer.ObservableProperty;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.NodeGenerator;
|
||||
import com.github.javaparser.generator.core.utils.CodeUtils;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.JavaParserMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.*;
|
||||
|
||||
public class PropertyGenerator extends NodeGenerator {
|
||||
|
||||
private final Map<String, PropertyMetaModel> declaredProperties = new HashMap<>();
|
||||
private final Map<String, PropertyMetaModel> derivedProperties = new HashMap<>();
|
||||
|
||||
public PropertyGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
|
||||
for (PropertyMetaModel property : nodeMetaModel.getDeclaredPropertyMetaModels()) {
|
||||
generateGetter(nodeMetaModel, nodeCoid, property);
|
||||
generateSetter(nodeMetaModel, nodeCoid, property);
|
||||
}
|
||||
nodeMetaModel.getDerivedPropertyMetaModels().forEach(p -> derivedProperties.put(p.getName(), p));
|
||||
}
|
||||
|
||||
private void generateSetter(
|
||||
BaseNodeMetaModel nodeMetaModel, ClassOrInterfaceDeclaration nodeCoid, PropertyMetaModel property) {
|
||||
// Ensure the relevant imports have been added for the methods/annotations used
|
||||
nodeCoid.findCompilationUnit().get().addImport(ObservableProperty.class);
|
||||
|
||||
final String name = property.getName();
|
||||
// Fill body
|
||||
final String observableName = camelCaseToScreaming(name.startsWith("is") ? name.substring(2) : name);
|
||||
declaredProperties.put(observableName, property);
|
||||
|
||||
if (property == JavaParserMetaModel.nodeMetaModel.commentPropertyMetaModel) {
|
||||
// Node.comment has a very specific setter that we shouldn't overwrite.
|
||||
return;
|
||||
}
|
||||
|
||||
final MethodDeclaration setter = new MethodDeclaration(
|
||||
createModifierList(PUBLIC),
|
||||
parseType(property.getContainingNodeMetaModel().getTypeNameGenerified()),
|
||||
property.getSetterMethodName());
|
||||
annotateWhenOverridden(nodeMetaModel, setter);
|
||||
if (property.getContainingNodeMetaModel().hasWildcard()) {
|
||||
setter.setType(parseType("T"));
|
||||
}
|
||||
setter.addAndGetParameter(property.getTypeNameForSetter(), property.getName())
|
||||
.addModifier(FINAL);
|
||||
|
||||
final BlockStmt body = setter.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
if (property.isRequired()) {
|
||||
Class<?> type = property.getType();
|
||||
if (property.isNonEmpty() && property.isSingular()) {
|
||||
nodeCoid.findCompilationUnit()
|
||||
.get()
|
||||
.addImport("com.github.javaparser.utils.Utils.assertNonEmpty", true, false);
|
||||
body.addStatement(f("assertNonEmpty(%s);", name));
|
||||
} else if (type != boolean.class && type != int.class) {
|
||||
nodeCoid.findCompilationUnit()
|
||||
.get()
|
||||
.addImport("com.github.javaparser.utils.Utils.assertNotNull", true, false);
|
||||
body.addStatement(f("assertNotNull(%s);", name));
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the new value is the same as the old value
|
||||
String returnValue = CodeUtils.castValue("this", setter.getType(), nodeMetaModel.getTypeName());
|
||||
body.addStatement(f("if (%s == this.%s) { return %s; }", name, name, returnValue));
|
||||
|
||||
body.addStatement(f("notifyPropertyChange(ObservableProperty.%s, this.%s, %s);", observableName, name, name));
|
||||
if (property.isNode()) {
|
||||
body.addStatement(f("if (this.%s != null) this.%s.setParentNode(null);", name, name));
|
||||
}
|
||||
body.addStatement(f("this.%s = %s;", name, name));
|
||||
if (property.isNode()) {
|
||||
body.addStatement(f("setAsParentNodeOf(%s);", name));
|
||||
}
|
||||
if (property.getContainingNodeMetaModel().hasWildcard()) {
|
||||
body.addStatement(f("return (T) this;"));
|
||||
} else {
|
||||
body.addStatement(f("return this;"));
|
||||
}
|
||||
addOrReplaceWhenSameSignature(nodeCoid, setter);
|
||||
if (property.getContainingNodeMetaModel().hasWildcard()) {
|
||||
annotateSuppressWarnings(setter);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateGetter(
|
||||
BaseNodeMetaModel nodeMetaModel, ClassOrInterfaceDeclaration nodeCoid, PropertyMetaModel property) {
|
||||
final MethodDeclaration getter = new MethodDeclaration(
|
||||
createModifierList(PUBLIC), parseType(property.getTypeNameForGetter()), property.getGetterMethodName());
|
||||
annotateWhenOverridden(nodeMetaModel, getter);
|
||||
final BlockStmt body = getter.getBody().get();
|
||||
body.getStatements().clear();
|
||||
if (property.isOptional()) {
|
||||
// Ensure imports have been included.
|
||||
nodeCoid.findCompilationUnit().get().addImport(Optional.class);
|
||||
body.addStatement(f("return Optional.ofNullable(%s);", property.getName()));
|
||||
} else {
|
||||
body.addStatement(f("return %s;", property.getName()));
|
||||
}
|
||||
addOrReplaceWhenSameSignature(nodeCoid, getter);
|
||||
}
|
||||
|
||||
private void generateObservableProperty(
|
||||
EnumDeclaration observablePropertyEnum, PropertyMetaModel property, boolean derived) {
|
||||
boolean isAttribute = !Node.class.isAssignableFrom(property.getType());
|
||||
String name = property.getName();
|
||||
String constantName = camelCaseToScreaming(name.startsWith("is") ? name.substring(2) : name);
|
||||
EnumConstantDeclaration enumConstantDeclaration = observablePropertyEnum.addEnumConstant(constantName);
|
||||
if (isAttribute) {
|
||||
enumConstantDeclaration.addArgument("Type.SINGLE_ATTRIBUTE");
|
||||
} else {
|
||||
if (property.isNodeList()) {
|
||||
enumConstantDeclaration.addArgument("Type.MULTIPLE_REFERENCE");
|
||||
} else {
|
||||
enumConstantDeclaration.addArgument("Type.SINGLE_REFERENCE");
|
||||
}
|
||||
}
|
||||
if (derived) {
|
||||
enumConstantDeclaration.addArgument("true");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void after() throws Exception {
|
||||
CompilationUnit observablePropertyCu = sourceRoot
|
||||
.tryToParse("com.github.javaparser.ast.observer", "ObservableProperty.java")
|
||||
.getResult()
|
||||
.get();
|
||||
EnumDeclaration observablePropertyEnum =
|
||||
observablePropertyCu.getEnumByName("ObservableProperty").get();
|
||||
observablePropertyEnum.getEntries().clear();
|
||||
List<String> observablePropertyNames = new LinkedList<>(declaredProperties.keySet());
|
||||
observablePropertyNames.sort(String::compareTo);
|
||||
for (String propName : observablePropertyNames) {
|
||||
generateObservableProperty(observablePropertyEnum, declaredProperties.get(propName), false);
|
||||
}
|
||||
List<String> derivedPropertyNames = new LinkedList<>(derivedProperties.keySet());
|
||||
derivedPropertyNames.sort(String::compareTo);
|
||||
for (String propName : derivedPropertyNames) {
|
||||
generateObservableProperty(observablePropertyEnum, derivedProperties.get(propName), true);
|
||||
}
|
||||
observablePropertyEnum.addEnumConstant("RANGE");
|
||||
observablePropertyEnum.addEnumConstant("COMMENTED_NODE");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.node;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
import static com.github.javaparser.utils.Utils.capitalize;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.NodeGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
public class RemoveMethodGenerator extends NodeGenerator {
|
||||
public RemoveMethodGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
|
||||
MethodDeclaration removeNodeMethod =
|
||||
(MethodDeclaration) parseBodyDeclaration("public boolean remove(Node node) {}");
|
||||
nodeCu.addImport(Node.class);
|
||||
annotateWhenOverridden(nodeMetaModel, removeNodeMethod);
|
||||
|
||||
final BlockStmt body = removeNodeMethod.getBody().get();
|
||||
|
||||
body.addStatement("if (node == null) { return false; }");
|
||||
int numberPropertiesDeclared = 0;
|
||||
for (PropertyMetaModel property : nodeMetaModel.getDeclaredPropertyMetaModels()) {
|
||||
if (!property.isNode()) {
|
||||
continue;
|
||||
}
|
||||
String check;
|
||||
if (property.isNodeList()) {
|
||||
check = nodeListCheck(property);
|
||||
} else {
|
||||
if (property.isRequired()) {
|
||||
continue;
|
||||
}
|
||||
String removeAttributeMethodName = generateRemoveMethodForAttribute(nodeCoid, nodeMetaModel, property);
|
||||
check = attributeCheck(property, removeAttributeMethodName);
|
||||
}
|
||||
if (property.isOptional()) {
|
||||
check = f("if (%s != null) { %s }", property.getName(), check);
|
||||
}
|
||||
body.addStatement(check);
|
||||
numberPropertiesDeclared++;
|
||||
}
|
||||
if (nodeMetaModel.getSuperNodeMetaModel().isPresent()) {
|
||||
body.addStatement("return super.remove(node);");
|
||||
} else {
|
||||
body.addStatement("return false;");
|
||||
}
|
||||
|
||||
if (!nodeMetaModel.isRootNode() && numberPropertiesDeclared == 0) {
|
||||
removeMethodWithSameSignature(nodeCoid, removeNodeMethod);
|
||||
} else {
|
||||
addOrReplaceWhenSameSignature(nodeCoid, removeNodeMethod);
|
||||
}
|
||||
}
|
||||
|
||||
private String attributeCheck(PropertyMetaModel property, String removeAttributeMethodName) {
|
||||
return f(
|
||||
"if (node == %s) {" + " %s();" + " return true;\n" + "}",
|
||||
property.getName(), removeAttributeMethodName);
|
||||
}
|
||||
|
||||
private String nodeListCheck(PropertyMetaModel property) {
|
||||
return f(
|
||||
"for (int i = 0; i < %s.size(); i++) {" + " if (%s.get(i) == node) {"
|
||||
+ " %s.remove(i);"
|
||||
+ " return true;"
|
||||
+ " }"
|
||||
+ "}",
|
||||
property.getName(), property.getName(), property.getName());
|
||||
}
|
||||
|
||||
private String generateRemoveMethodForAttribute(
|
||||
ClassOrInterfaceDeclaration nodeCoid, BaseNodeMetaModel nodeMetaModel, PropertyMetaModel property) {
|
||||
final String methodName = "remove" + capitalize(property.getName());
|
||||
final MethodDeclaration removeMethod = (MethodDeclaration)
|
||||
parseBodyDeclaration(f("public %s %s() {}", nodeMetaModel.getTypeName(), methodName));
|
||||
|
||||
final BlockStmt block = removeMethod.getBody().get();
|
||||
block.addStatement(f("return %s((%s) null);", property.getSetterMethodName(), property.getTypeNameForSetter()));
|
||||
|
||||
addOrReplaceWhenSameSignature(nodeCoid, removeMethod);
|
||||
return methodName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.node;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.NodeGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
public class ReplaceMethodGenerator extends NodeGenerator {
|
||||
public ReplaceMethodGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid) {
|
||||
MethodDeclaration replaceNodeMethod =
|
||||
(MethodDeclaration) parseBodyDeclaration("public boolean replace(Node node, Node replacementNode) {}");
|
||||
nodeCu.addImport(Node.class);
|
||||
annotateWhenOverridden(nodeMetaModel, replaceNodeMethod);
|
||||
|
||||
final BlockStmt body = replaceNodeMethod.getBody().get();
|
||||
|
||||
body.addStatement("if (node == null) { return false; }");
|
||||
|
||||
int numberPropertiesDeclared = 0;
|
||||
for (PropertyMetaModel property : nodeMetaModel.getDeclaredPropertyMetaModels()) {
|
||||
if (!property.isNode()) {
|
||||
continue;
|
||||
}
|
||||
String check;
|
||||
if (property.isNodeList()) {
|
||||
check = nodeListCheck(property);
|
||||
} else {
|
||||
check = attributeCheck(property, property.getSetterMethodName());
|
||||
}
|
||||
if (property.isOptional()) {
|
||||
check = f("if (%s != null) { %s }", property.getName(), check);
|
||||
}
|
||||
body.addStatement(check);
|
||||
numberPropertiesDeclared++;
|
||||
}
|
||||
if (nodeMetaModel.getSuperNodeMetaModel().isPresent()) {
|
||||
body.addStatement("return super.replace(node, replacementNode);");
|
||||
} else {
|
||||
body.addStatement("return false;");
|
||||
}
|
||||
|
||||
if (!nodeMetaModel.isRootNode() && numberPropertiesDeclared == 0) {
|
||||
removeMethodWithSameSignature(nodeCoid, replaceNodeMethod);
|
||||
} else {
|
||||
addOrReplaceWhenSameSignature(nodeCoid, replaceNodeMethod);
|
||||
}
|
||||
}
|
||||
|
||||
private String attributeCheck(PropertyMetaModel property, String attributeSetterName) {
|
||||
return f(
|
||||
"if (node == %s) {" + " %s((%s) replacementNode);" + " return true;\n" + "}",
|
||||
property.getName(), attributeSetterName, property.getTypeName());
|
||||
}
|
||||
|
||||
private String nodeListCheck(PropertyMetaModel property) {
|
||||
return f(
|
||||
"for (int i = 0; i < %s.size(); i++) {" + " if (%s.get(i) == node) {"
|
||||
+ " %s.set(i, (%s) replacementNode);"
|
||||
+ " return true;"
|
||||
+ " }"
|
||||
+ "}",
|
||||
property.getName(), property.getName(), property.getName(), property.getTypeName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.node;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseBodyDeclaration;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
import static com.github.javaparser.utils.Utils.set;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.generator.NodeGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.JavaParserMetaModel;
|
||||
import com.github.javaparser.utils.Pair;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class TypeCastingGenerator extends NodeGenerator {
|
||||
private final Set<BaseNodeMetaModel> baseNodes = set(
|
||||
JavaParserMetaModel.statementMetaModel,
|
||||
JavaParserMetaModel.expressionMetaModel,
|
||||
JavaParserMetaModel.typeMetaModel,
|
||||
JavaParserMetaModel.moduleDirectiveMetaModel,
|
||||
JavaParserMetaModel.bodyDeclarationMetaModel,
|
||||
JavaParserMetaModel.commentMetaModel);
|
||||
|
||||
public TypeCastingGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateNode(
|
||||
BaseNodeMetaModel nodeMetaModel, CompilationUnit nodeCu, ClassOrInterfaceDeclaration nodeCoid)
|
||||
throws Exception {
|
||||
Pair<CompilationUnit, ClassOrInterfaceDeclaration> baseCode = null;
|
||||
for (BaseNodeMetaModel baseNode : baseNodes) {
|
||||
if (nodeMetaModel == baseNode) {
|
||||
// We adjust the base models from the child nodes,
|
||||
// so we don't do anything when we *are* the base model.
|
||||
return;
|
||||
}
|
||||
if (nodeMetaModel.isInstanceOfMetaModel(baseNode)) {
|
||||
baseCode = parseNode(baseNode);
|
||||
}
|
||||
}
|
||||
|
||||
if (baseCode == null) {
|
||||
// Node is not a child of one of the base nodes, so we don't want to generate this method for it.
|
||||
return;
|
||||
}
|
||||
|
||||
final String typeName = nodeMetaModel.getTypeName();
|
||||
final ClassOrInterfaceDeclaration baseCoid = baseCode.b;
|
||||
final CompilationUnit baseCu = baseCode.a;
|
||||
|
||||
generateIsType(nodeMetaModel, baseCu, nodeCoid, baseCoid, typeName);
|
||||
generateAsType(nodeMetaModel, baseCu, nodeCoid, baseCoid, typeName);
|
||||
generateToType(nodeMetaModel, nodeCu, baseCu, nodeCoid, baseCoid, typeName);
|
||||
generateIfType(nodeMetaModel, nodeCu, baseCu, nodeCoid, baseCoid, typeName);
|
||||
}
|
||||
|
||||
private void generateAsType(
|
||||
BaseNodeMetaModel nodeMetaModel,
|
||||
CompilationUnit baseCu,
|
||||
ClassOrInterfaceDeclaration nodeCoid,
|
||||
ClassOrInterfaceDeclaration baseCoid,
|
||||
String typeName) {
|
||||
baseCu.addImport("com.github.javaparser.utils.CodeGenerationUtils.f", true, false);
|
||||
|
||||
final MethodDeclaration asTypeBaseMethod = (MethodDeclaration) parseBodyDeclaration(f(
|
||||
"public %s as%s() { throw new IllegalStateException(f(\"%%s is not %s, it is %%s\", this, this.getClass().getSimpleName())); }",
|
||||
typeName, typeName, typeName));
|
||||
final MethodDeclaration asTypeNodeMethod = (MethodDeclaration)
|
||||
parseBodyDeclaration(f("@Override public %s as%s() { return this; }", typeName, typeName));
|
||||
|
||||
annotateWhenOverridden(nodeMetaModel, asTypeNodeMethod);
|
||||
|
||||
addOrReplaceWhenSameSignature(baseCoid, asTypeBaseMethod);
|
||||
addOrReplaceWhenSameSignature(nodeCoid, asTypeNodeMethod);
|
||||
}
|
||||
|
||||
private void generateToType(
|
||||
BaseNodeMetaModel nodeMetaModel,
|
||||
CompilationUnit nodeCu,
|
||||
CompilationUnit baseCu,
|
||||
ClassOrInterfaceDeclaration nodeCoid,
|
||||
ClassOrInterfaceDeclaration baseCoid,
|
||||
String typeName) {
|
||||
baseCu.addImport(Optional.class);
|
||||
nodeCu.addImport(Optional.class);
|
||||
|
||||
final MethodDeclaration toTypeBaseMethod = (MethodDeclaration) parseBodyDeclaration(
|
||||
f("public Optional<%s> to%s() { return Optional.empty(); }", typeName, typeName, typeName));
|
||||
final MethodDeclaration toTypeNodeMethod = (MethodDeclaration) parseBodyDeclaration(
|
||||
f("@Override public Optional<%s> to%s() { return Optional.of(this); }", typeName, typeName));
|
||||
|
||||
annotateWhenOverridden(nodeMetaModel, toTypeNodeMethod);
|
||||
|
||||
addOrReplaceWhenSameSignature(baseCoid, toTypeBaseMethod);
|
||||
addOrReplaceWhenSameSignature(nodeCoid, toTypeNodeMethod);
|
||||
}
|
||||
|
||||
private void generateIfType(
|
||||
BaseNodeMetaModel nodeMetaModel,
|
||||
CompilationUnit nodeCu,
|
||||
CompilationUnit baseCu,
|
||||
ClassOrInterfaceDeclaration nodeCoid,
|
||||
ClassOrInterfaceDeclaration baseCoid,
|
||||
String typeName) {
|
||||
baseCu.addImport(Consumer.class);
|
||||
nodeCu.addImport(Consumer.class);
|
||||
|
||||
final MethodDeclaration ifTypeBaseMethod = (MethodDeclaration)
|
||||
parseBodyDeclaration(f("public void if%s(Consumer<%s> action) { }", typeName, typeName));
|
||||
final MethodDeclaration ifTypeNodeMethod = (MethodDeclaration) parseBodyDeclaration(
|
||||
f("public void if%s(Consumer<%s> action) { action.accept(this); }", typeName, typeName));
|
||||
|
||||
annotateWhenOverridden(nodeMetaModel, ifTypeNodeMethod);
|
||||
|
||||
addOrReplaceWhenSameSignature(baseCoid, ifTypeBaseMethod);
|
||||
addOrReplaceWhenSameSignature(nodeCoid, ifTypeNodeMethod);
|
||||
}
|
||||
|
||||
private void generateIsType(
|
||||
BaseNodeMetaModel nodeMetaModel,
|
||||
CompilationUnit baseCu,
|
||||
ClassOrInterfaceDeclaration nodeCoid,
|
||||
ClassOrInterfaceDeclaration baseCoid,
|
||||
String typeName) {
|
||||
final MethodDeclaration baseIsTypeMethod =
|
||||
(MethodDeclaration) parseBodyDeclaration(f("public boolean is%s() { return false; }", typeName));
|
||||
final MethodDeclaration overriddenIsTypeMethod = (MethodDeclaration)
|
||||
parseBodyDeclaration(f("@Override public boolean is%s() { return true; }", typeName));
|
||||
|
||||
annotateWhenOverridden(nodeMetaModel, overriddenIsTypeMethod);
|
||||
|
||||
addOrReplaceWhenSameSignature(nodeCoid, overriddenIsTypeMethod);
|
||||
addOrReplaceWhenSameSignature(baseCoid, baseIsTypeMethod);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.other;
|
||||
|
||||
import com.github.javaparser.generator.Generator;
|
||||
import com.github.javaparser.utils.Log;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Generates the bnd.bnd file in javaparser-core.
|
||||
*/
|
||||
public class BndGenerator extends Generator {
|
||||
|
||||
public BndGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate() throws IOException {
|
||||
Log.info("Running %s", () -> getClass().getSimpleName());
|
||||
Path root = sourceRoot.getRoot();
|
||||
Path projectRoot = root.getParent().getParent().getParent();
|
||||
String lineSeparator = System.getProperty("line.separator");
|
||||
try (Stream<Path> stream = Files.walk(root)) {
|
||||
String packagesList = stream.filter(Files::isRegularFile)
|
||||
.map(path -> getPackageName(root, path))
|
||||
.distinct()
|
||||
.sorted()
|
||||
.reduce(
|
||||
null,
|
||||
(packageList, packageName) -> concatPackageName(packageName, packageList, lineSeparator));
|
||||
Path output = projectRoot.resolve("bnd.bnd");
|
||||
try (Writer writer = Files.newBufferedWriter(output)) {
|
||||
Path templateFile = projectRoot.resolve("bnd.bnd.template");
|
||||
String template = new String(Files.readAllBytes(templateFile), StandardCharsets.UTF_8);
|
||||
writer.write(template.replace("{exportedPackages}", packagesList));
|
||||
}
|
||||
Log.info("Written " + output);
|
||||
}
|
||||
}
|
||||
|
||||
private String concatPackageName(String packageName, String packageList, String lineSeparator) {
|
||||
return (packageList == null ? ("\\" + lineSeparator) : (packageList + ", \\" + lineSeparator)) + " "
|
||||
+ packageName;
|
||||
}
|
||||
|
||||
private static String getPackageName(Path root, Path path) {
|
||||
return root.relativize(path.getParent()).toString().replace(File.separatorChar, '.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.other;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Prints the LETTER and PART_LETTER tokens. They should be inserted into the grammar manually.
|
||||
*/
|
||||
public class GrammarLetterGenerator {
|
||||
public static void main(String[] args) {
|
||||
generate(
|
||||
"LETTER",
|
||||
c -> Character.isJavaIdentifierStart(c)
|
||||
|| Character.isHighSurrogate((char) (int) c)
|
||||
|| Character.isLowSurrogate((char) (int) c));
|
||||
generate(
|
||||
"PART_LETTER",
|
||||
c -> Character.isJavaIdentifierPart(c)
|
||||
|| Character.isHighSurrogate((char) (int) c)
|
||||
|| Character.isLowSurrogate((char) (int) c));
|
||||
}
|
||||
|
||||
private static void generate(String tokenName, Function<Integer, Boolean> f) {
|
||||
final String indent = " ";
|
||||
System.out.println(" < #" + tokenName + ": [");
|
||||
System.out.print(indent);
|
||||
int nltime = 0;
|
||||
int i = 0;
|
||||
while (i < 0x10000) {
|
||||
while (!f.apply(i) && i < 0x10000) {
|
||||
i++;
|
||||
}
|
||||
String start = format(i);
|
||||
while (f.apply(i) && i < 0x10000) {
|
||||
i++;
|
||||
}
|
||||
String end = format(i - 1);
|
||||
if (i >= 0x10000) {
|
||||
break;
|
||||
}
|
||||
if (start.equals(end)) {
|
||||
nltime++;
|
||||
System.out.print(start + ", ");
|
||||
} else {
|
||||
nltime += 2;
|
||||
System.out.print(start + "-" + end + ", ");
|
||||
}
|
||||
if (nltime >= 10) {
|
||||
nltime = 0;
|
||||
System.out.println();
|
||||
System.out.print(indent);
|
||||
}
|
||||
}
|
||||
// Too lazy to remove the final illegal comma.
|
||||
System.out.println("]");
|
||||
System.out.println(" | <UNICODE_ESCAPE>");
|
||||
System.out.println(" >");
|
||||
}
|
||||
|
||||
private static String format(int i) {
|
||||
return String.format("\"\\u%04x\"", i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.other;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.body.BodyDeclaration;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.EnumConstantDeclaration;
|
||||
import com.github.javaparser.ast.body.EnumDeclaration;
|
||||
import com.github.javaparser.ast.expr.IntegerLiteralExpr;
|
||||
import com.github.javaparser.ast.stmt.ReturnStmt;
|
||||
import com.github.javaparser.ast.stmt.SwitchEntry;
|
||||
import com.github.javaparser.ast.stmt.SwitchStmt;
|
||||
import com.github.javaparser.generator.Generator;
|
||||
import com.github.javaparser.utils.Log;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates the TokenKind enum from {@link com.github.javaparser.GeneratedJavaParserConstants}
|
||||
*/
|
||||
public class TokenKindGenerator extends Generator {
|
||||
private final SourceRoot generatedJavaCcSourceRoot;
|
||||
|
||||
public TokenKindGenerator(SourceRoot sourceRoot, SourceRoot generatedJavaCcSourceRoot) {
|
||||
super(sourceRoot);
|
||||
this.generatedJavaCcSourceRoot = generatedJavaCcSourceRoot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate() {
|
||||
Log.info("Running %s", () -> getClass().getSimpleName());
|
||||
|
||||
final CompilationUnit javaTokenCu = sourceRoot.parse("com.github.javaparser", "JavaToken.java");
|
||||
final ClassOrInterfaceDeclaration javaToken = javaTokenCu
|
||||
.getClassByName("JavaToken")
|
||||
.orElseThrow(() -> new AssertionError("Can't find class in java file."));
|
||||
final EnumDeclaration kindEnum = javaToken
|
||||
.findFirst(EnumDeclaration.class, e -> "Kind".equals(e.getNameAsString()))
|
||||
.orElseThrow(() -> new AssertionError("Can't find class in java file."));
|
||||
|
||||
kindEnum.getEntries().clear();
|
||||
annotateGenerated(kindEnum);
|
||||
|
||||
final SwitchStmt valueOfSwitch = kindEnum.findFirst(SwitchStmt.class)
|
||||
.orElseThrow(() -> new AssertionError("Can't find valueOf switch."));
|
||||
valueOfSwitch.findAll(SwitchEntry.class).stream()
|
||||
.filter(e -> e.getLabels().isNonEmpty())
|
||||
.forEach(Node::remove);
|
||||
|
||||
final CompilationUnit constantsCu =
|
||||
generatedJavaCcSourceRoot.parse("com.github.javaparser", "GeneratedJavaParserConstants.java");
|
||||
final ClassOrInterfaceDeclaration constants = constantsCu
|
||||
.getInterfaceByName("GeneratedJavaParserConstants")
|
||||
.orElseThrow(() -> new AssertionError("Can't find class in java file."));
|
||||
for (BodyDeclaration<?> member : constants.getMembers()) {
|
||||
member.toFieldDeclaration()
|
||||
.filter(field -> {
|
||||
String javadoc = field.getJavadocComment().get().getContent();
|
||||
return javadoc.contains("RegularExpression Id") || javadoc.contains("End of File");
|
||||
})
|
||||
.map(field -> field.getVariable(0))
|
||||
.ifPresent(var -> {
|
||||
final String name = var.getNameAsString();
|
||||
final IntegerLiteralExpr kind =
|
||||
var.getInitializer().get().asIntegerLiteralExpr();
|
||||
generateEnumEntry(kindEnum, name, kind);
|
||||
generateValueOfEntry(valueOfSwitch, name, kind);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void generateValueOfEntry(SwitchStmt valueOfSwitch, String name, IntegerLiteralExpr kind) {
|
||||
final SwitchEntry entry = new SwitchEntry(
|
||||
new NodeList<>(kind),
|
||||
SwitchEntry.Type.STATEMENT_GROUP,
|
||||
new NodeList<>(new ReturnStmt(name)),
|
||||
false,
|
||||
null);
|
||||
valueOfSwitch.getEntries().addFirst(entry);
|
||||
}
|
||||
|
||||
private void generateEnumEntry(EnumDeclaration kindEnum, String name, IntegerLiteralExpr kind) {
|
||||
final EnumConstantDeclaration enumEntry = new EnumConstantDeclaration(name);
|
||||
enumEntry.getArguments().add(kind);
|
||||
kindEnum.addEntry(enumEntry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.quality;
|
||||
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.StaticJavaParser;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.body.CallableDeclaration;
|
||||
import com.github.javaparser.ast.body.ConstructorDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.body.Parameter;
|
||||
import com.github.javaparser.ast.expr.AnnotationExpr;
|
||||
import com.github.javaparser.ast.expr.MethodCallExpr;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt;
|
||||
import com.github.javaparser.ast.stmt.ExpressionStmt;
|
||||
import com.github.javaparser.ast.stmt.Statement;
|
||||
import com.github.javaparser.generator.CompilationUnitGenerator;
|
||||
import com.github.javaparser.quality.NotNull;
|
||||
import com.github.javaparser.quality.Preconditions;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Generator to process annotations {@link com.github.javaparser.quality.NotNull}.
|
||||
*/
|
||||
public class NotNullGenerator extends CompilationUnitGenerator {
|
||||
|
||||
public NotNullGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateCompilationUnit(CompilationUnit compilationUnit) {
|
||||
compilationUnit.findAll(ConstructorDeclaration.class).forEach(this::generateQualityForConstructor);
|
||||
compilationUnit.findAll(MethodDeclaration.class).forEach(this::generateQualityForMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the pre conditions based on the method parameters.
|
||||
* <br>
|
||||
* If parameters are annotated with {@link com.github.javaparser.quality.NotNull} and a {@code null} is
|
||||
* passed, the method should throw an {@link IllegalArgumentException}.
|
||||
* <br>
|
||||
* If annotated with {@link com.github.javaparser.quality.Nullable}, other annotation or none, nothing should be
|
||||
* changed.
|
||||
*
|
||||
* @param methodDeclaration The method declaration to generate.
|
||||
*/
|
||||
protected void generateQualityForMethod(MethodDeclaration methodDeclaration) {
|
||||
methodDeclaration
|
||||
.getBody()
|
||||
.ifPresent(blockStmt ->
|
||||
generateQualityForParameter(methodDeclaration, methodDeclaration.getParameters(), blockStmt));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the pre conditions based on the constructor parameters.
|
||||
* <br>
|
||||
* If parameters are annotated with {@link com.github.javaparser.quality.NotNull} and a {@code null} is
|
||||
* passed, the method should throw an {@link IllegalArgumentException}.
|
||||
* <br>
|
||||
* If annotated with {@link com.github.javaparser.quality.Nullable}, other annotation or none, nothing should be
|
||||
* changed.
|
||||
*
|
||||
* @param constructorDeclaration The constructor declaration to generate.
|
||||
*/
|
||||
protected void generateQualityForConstructor(ConstructorDeclaration constructorDeclaration) {
|
||||
generateQualityForParameter(
|
||||
constructorDeclaration, constructorDeclaration.getParameters(), constructorDeclaration.getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the pre conditions for the parameters.
|
||||
* <br>
|
||||
* If parameters are annotated with {@link com.github.javaparser.quality.NotNull} and a {@code null} is
|
||||
* passed, the method should throw an {@link IllegalArgumentException}.
|
||||
* <br>
|
||||
* If annotated with {@link com.github.javaparser.quality.Nullable}, other annotation or none, nothing should be
|
||||
* changed.
|
||||
*
|
||||
* @param callableDeclaration The declaration where the parameters belong.
|
||||
* @param parameters The list of parameters.
|
||||
* @param blockStmt The block where the assertions should be added.
|
||||
*
|
||||
* @param <N> The callable declaration type.
|
||||
*/
|
||||
protected <N extends CallableDeclaration<?>> void generateQualityForParameter(
|
||||
N callableDeclaration, NodeList<Parameter> parameters, BlockStmt blockStmt) {
|
||||
|
||||
List<Statement> assertions = new ArrayList<>();
|
||||
|
||||
for (Parameter parameter : parameters) {
|
||||
Optional<AnnotationExpr> nonNullAnnotation = parameter.getAnnotationByClass(NotNull.class);
|
||||
if (nonNullAnnotation.isPresent()) {
|
||||
assertions.add(createAssertion(parameter));
|
||||
}
|
||||
}
|
||||
|
||||
insertAssertionsInBlock(callableDeclaration, blockStmt, assertions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create assertion for the parameters.
|
||||
*
|
||||
* @param parameter The parameter to create the assertion.
|
||||
*
|
||||
* @return The assertion to be added to the code.
|
||||
*/
|
||||
private Statement createAssertion(Parameter parameter) {
|
||||
|
||||
parameter.tryAddImportToParentCompilationUnit(Preconditions.class);
|
||||
return StaticJavaParser.parseStatement(f(
|
||||
"Preconditions.checkNotNull(%s, \"Parameter %s can't be null.\");",
|
||||
parameter.getNameAsString(), parameter.getNameAsString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the assertions into the block.
|
||||
*
|
||||
* @param callableDeclaration The declaration where the parameters belong.
|
||||
* @param blockStmt The block where the assertions should be added.
|
||||
* @param assertions The list of assertions to be inserted.
|
||||
*
|
||||
* @param <N> The callable declaration type.
|
||||
*/
|
||||
private <N extends CallableDeclaration<?>> void insertAssertionsInBlock(
|
||||
N callableDeclaration, BlockStmt blockStmt, List<Statement> assertions) {
|
||||
|
||||
// If there's nothing to add, just ignore
|
||||
if (assertions.isEmpty()) return;
|
||||
|
||||
int position = 0;
|
||||
NodeList<Statement> statements = blockStmt.getStatements();
|
||||
|
||||
// When the callable is a constructor we must check if is a ExplicitConstructorInvocationStmt.
|
||||
if (callableDeclaration.isConstructorDeclaration()) {
|
||||
Optional<Statement> optionalFirstStatement = statements.getFirst();
|
||||
if (optionalFirstStatement.isPresent()) {
|
||||
|
||||
// Check if the first item is a "super" expr. If it's then we add the assertions after it.
|
||||
Statement firstStatement = optionalFirstStatement.get();
|
||||
if (firstStatement instanceof ExplicitConstructorInvocationStmt) {
|
||||
position = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register assertions
|
||||
for (int i = 0; i < assertions.size(); i++) {
|
||||
Statement assertion = assertions.get(i);
|
||||
|
||||
Optional<? extends Statement> optOldStmt = getSimilarAssertionInBlock(assertion, blockStmt);
|
||||
|
||||
if (optOldStmt.isPresent()) {
|
||||
optOldStmt.get().replace(assertion);
|
||||
} else {
|
||||
blockStmt.addStatement(position + i, assertion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<? extends Statement> getSimilarAssertionInBlock(Statement assertion, BlockStmt blockStmt) {
|
||||
|
||||
MethodCallExpr assertionCall =
|
||||
assertion.asExpressionStmt().getExpression().asMethodCallExpr();
|
||||
List<MethodCallExpr> methodCallExpressions = blockStmt.findAll(MethodCallExpr.class);
|
||||
|
||||
for (MethodCallExpr blockMethodCall : methodCallExpressions) {
|
||||
|
||||
// Check if the method calls name match
|
||||
if (blockMethodCall.getNameAsExpression().equals(assertionCall.getNameAsExpression())
|
||||
&& blockMethodCall.getScope().equals(assertionCall.getScope())
|
||||
&& blockMethodCall.getArguments().size() == 2
|
||||
&& blockMethodCall.getArguments().get(0).equals(assertionCall.getArgument(0))) {
|
||||
return blockMethodCall.findAncestor(ExpressionStmt.class);
|
||||
}
|
||||
}
|
||||
// TODO:
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.utils;
|
||||
|
||||
import com.github.javaparser.ast.type.Type;
|
||||
|
||||
public final class CodeUtils {
|
||||
|
||||
private CodeUtils() {
|
||||
// This constructor is used to hide the public one
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast the value if the current type doesn't match the required type.
|
||||
* <br>
|
||||
* Given the following example:
|
||||
* <code>
|
||||
* int withoutCast = 1;
|
||||
* double withCast = (double) 1;
|
||||
* </code>
|
||||
* The variable withoutCast doesn't need to be casted, since we have int as required type and int as value type.
|
||||
* While in the variable withCast we have double as required type and int as value type.
|
||||
*
|
||||
* @param value The value to be returned.
|
||||
* @param requiredType The expected type to be casted if needed.
|
||||
* @param valueType The type of the value to be returned.
|
||||
*
|
||||
* @return The value casted if needed.
|
||||
*/
|
||||
public static String castValue(String value, Type requiredType, String valueType) {
|
||||
String requiredTypeName = requiredType.asString();
|
||||
|
||||
if (requiredTypeName.equals(valueType)) return value;
|
||||
return String.format("(%s) %s", requiredTypeName, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.CompilationUnitMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SeparatedItemStringBuilder;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's CloneVisitor.
|
||||
*/
|
||||
public class CloneVisitorGenerator extends VisitorGenerator {
|
||||
public CloneVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "CloneVisitor", "Visitable", "Object", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
for (PropertyMetaModel field : node.getAllPropertyMetaModels()) {
|
||||
final String getter = field.getGetterMethodName() + "()";
|
||||
if (field.getNodeReference().isPresent()) {
|
||||
if (field.isOptional() && field.isNodeList()) {
|
||||
body.addStatement(f(
|
||||
"NodeList<%s> %s = cloneList(n.%s.orElse(null), arg);",
|
||||
field.getTypeNameGenerified(), field.getName(), getter));
|
||||
} else if (field.isNodeList()) {
|
||||
body.addStatement(f(
|
||||
"NodeList<%s> %s = cloneList(n.%s, arg);",
|
||||
field.getTypeNameGenerified(), field.getName(), getter));
|
||||
} else {
|
||||
body.addStatement(
|
||||
f("%s %s = cloneNode(n.%s, arg);", field.getTypeNameGenerified(), field.getName(), getter));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder(
|
||||
f("%s r = new %s(", node.getTypeNameGenerified(), node.getTypeNameGenerified()), ",", ");");
|
||||
builder.append("n.getTokenRange().orElse(null)");
|
||||
for (PropertyMetaModel field : node.getConstructorParameters()) {
|
||||
if ("comment".equals(field.getName())) {
|
||||
continue;
|
||||
}
|
||||
if (field.getNodeReference().isPresent()) {
|
||||
builder.append(field.getName());
|
||||
} else {
|
||||
builder.append(f("n.%s()", field.getGetterMethodName()));
|
||||
}
|
||||
}
|
||||
|
||||
body.addStatement(builder.toString());
|
||||
if (node instanceof CompilationUnitMetaModel) {
|
||||
body.addStatement("n.getStorage().ifPresent(s -> r.setStorage(s.getPath(), s.getEncoding()));");
|
||||
}
|
||||
body.addStatement("r.setComment(comment);");
|
||||
body.addStatement("n.getOrphanComments().stream().map(Comment::clone).forEach(r::addOrphanComment);");
|
||||
body.addStatement("copyData(n, r);");
|
||||
body.addStatement("return r;");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's EqualsVisitor.
|
||||
*/
|
||||
public class EqualsVisitorGenerator extends VisitorGenerator {
|
||||
public EqualsVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "EqualsVisitor", "Boolean", "Visitable", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
body.addStatement(f("final %s n2 = (%s) arg;", node.getTypeName(), node.getTypeName()));
|
||||
|
||||
for (PropertyMetaModel field : node.getAllPropertyMetaModels()) {
|
||||
final String getter = field.getGetterMethodName() + "()";
|
||||
if (field.getNodeReference().isPresent()) {
|
||||
if (field.isNodeList()) {
|
||||
body.addStatement(f("if (!nodesEquals(n.%s, n2.%s)) return false;", getter, getter));
|
||||
} else {
|
||||
body.addStatement(f("if (!nodeEquals(n.%s, n2.%s)) return false;", getter, getter));
|
||||
}
|
||||
} else {
|
||||
body.addStatement(f("if (!objEquals(n.%s, n2.%s)) return false;", getter, getter));
|
||||
}
|
||||
}
|
||||
if (body.getStatements().size() == 1) {
|
||||
// Only the cast line was added, but nothing is using it, so remove it again.
|
||||
body.getStatements().clear();
|
||||
}
|
||||
body.addStatement("return true;");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's GenericListVisitorAdapter.
|
||||
*/
|
||||
public class GenericListVisitorAdapterGenerator extends VisitorGenerator {
|
||||
public GenericListVisitorAdapterGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "GenericListVisitorAdapter", "List<R>", "A", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
body.addStatement("List<R> result = new ArrayList<>();");
|
||||
body.addStatement("List<R> tmp;");
|
||||
|
||||
final String resultCheck = "if (tmp != null) result.addAll(tmp);";
|
||||
|
||||
for (PropertyMetaModel field : node.getAllPropertyMetaModels()) {
|
||||
final String getter = field.getGetterMethodName() + "()";
|
||||
if (field.getNodeReference().isPresent()) {
|
||||
if (field.isOptional()) {
|
||||
body.addStatement(f(
|
||||
"if (n.%s.isPresent()) {" + " tmp = n.%s.get().accept(this, arg);" + " %s" + "}",
|
||||
getter, getter, resultCheck));
|
||||
} else {
|
||||
body.addStatement(f("{ tmp = n.%s.accept(this, arg); %s }", getter, resultCheck));
|
||||
}
|
||||
}
|
||||
}
|
||||
body.addStatement("return result;");
|
||||
Arrays.stream(new Class<?>[] {List.class, ArrayList.class})
|
||||
.filter(c -> compilationUnit.getImports().stream()
|
||||
.noneMatch(i -> c.getName().equals(i.getName().asString())))
|
||||
.forEach(compilationUnit::addImport);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's VoidVisitorAdapter.
|
||||
*/
|
||||
public class GenericVisitorAdapterGenerator extends VisitorGenerator {
|
||||
public GenericVisitorAdapterGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "GenericVisitorAdapter", "R", "A", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
body.addStatement("R result;");
|
||||
|
||||
final String resultCheck = "if (result != null) return result;";
|
||||
|
||||
for (PropertyMetaModel field : node.getAllPropertyMetaModels()) {
|
||||
final String getter = field.getGetterMethodName() + "()";
|
||||
if (field.getNodeReference().isPresent()) {
|
||||
if (field.isOptional()) {
|
||||
body.addStatement(f(
|
||||
"if (n.%s.isPresent()) {" + " result = n.%s.get().accept(this, arg);" + " %s" + "}",
|
||||
getter, getter, resultCheck));
|
||||
} else {
|
||||
body.addStatement(f("{ result = n.%s.accept(this, arg); %s }", getter, resultCheck));
|
||||
}
|
||||
}
|
||||
}
|
||||
body.addStatement("return null;");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's GenericVisitor.
|
||||
*/
|
||||
public class GenericVisitorGenerator extends VisitorGenerator {
|
||||
public GenericVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "GenericVisitor", "R", "A", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(false));
|
||||
|
||||
visitMethod.setBody(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's GenericVisitorWithDefaults.
|
||||
*/
|
||||
public class GenericVisitorWithDefaultsGenerator extends VisitorGenerator {
|
||||
public GenericVisitorWithDefaultsGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "GenericVisitorWithDefaults", "R", "A", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
body.addStatement("return defaultAction(n, arg);");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseStatement;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SeparatedItemStringBuilder;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's HashCodeVisitor.
|
||||
*/
|
||||
public class HashCodeVisitorGenerator extends VisitorGenerator {
|
||||
public HashCodeVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "HashCodeVisitor", "Integer", "Void", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
final BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
final SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder("return ", "* 31 +", ";");
|
||||
final List<PropertyMetaModel> propertyMetaModels = node.getAllPropertyMetaModels();
|
||||
if (propertyMetaModels.isEmpty()) {
|
||||
builder.append("0");
|
||||
} else {
|
||||
for (PropertyMetaModel field : propertyMetaModels) {
|
||||
final String getter = field.getGetterMethodName() + "()";
|
||||
// Is this field another AST node? Visit it.
|
||||
if (field.getNodeReference().isPresent()) {
|
||||
if (field.isOptional()) {
|
||||
builder.append("(n.%s.isPresent()? n.%s.get().accept(this, arg):0)", getter, getter);
|
||||
} else {
|
||||
builder.append("(n.%s.accept(this, arg))", getter);
|
||||
}
|
||||
} else {
|
||||
Class<?> type = field.getType();
|
||||
if (type.equals(boolean.class)) {
|
||||
builder.append("(n.%s?1:0)", getter);
|
||||
} else if (type.equals(int.class)) {
|
||||
builder.append("n.%s", getter);
|
||||
} else {
|
||||
builder.append("(n.%s.hashCode())", getter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
body.addStatement(parseStatement(builder.toString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.expr.BinaryExpr;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SeparatedItemStringBuilder;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModifierVisitorGenerator extends VisitorGenerator {
|
||||
public ModifierVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "ModifierVisitor", "Visitable", "A", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
// FIXME: Bit of a hacky way to get this fixed order, and then have everything else (note this list is reversed)
|
||||
List<String> order = Arrays.asList(
|
||||
// "comment", "name", "members", "parameters", "name",
|
||||
"modifiers", "annotations");
|
||||
List<PropertyMetaModel> sortedPropertyMetaModels = node.getAllPropertyMetaModels().stream()
|
||||
.sorted(
|
||||
Comparator.comparingInt((PropertyMetaModel o) -> order.indexOf(o.getName()))
|
||||
.reversed()
|
||||
// .thenComparing(PropertyMetaModel::getName)
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//
|
||||
sortedPropertyMetaModels.forEach(property -> extracted(body, property));
|
||||
|
||||
//
|
||||
if (node.is(BinaryExpr.class)) {
|
||||
body.addStatement("if (left == null) return right;");
|
||||
body.addStatement("if (right == null) return left;");
|
||||
} else {
|
||||
final SeparatedItemStringBuilder collapseCheck =
|
||||
new SeparatedItemStringBuilder("if(", "||", ") return null;");
|
||||
sortedPropertyMetaModels.forEach(property -> {
|
||||
if (property.isRequired() && property.isNode()) {
|
||||
if (property.isNodeList()) {
|
||||
if (property.isNonEmpty()) {
|
||||
collapseCheck.append(f("%s.isEmpty()", property.getName()));
|
||||
}
|
||||
} else {
|
||||
collapseCheck.append(f("%s==null", property.getName()));
|
||||
}
|
||||
}
|
||||
});
|
||||
if (collapseCheck.hasItems()) {
|
||||
body.addStatement(collapseCheck.toString());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
sortedPropertyMetaModels.forEach(property -> {
|
||||
if (property.isNode()) {
|
||||
body.addStatement(f("n.%s(%s);", property.getSetterMethodName(), property.getName()));
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
body.addStatement("return n;");
|
||||
}
|
||||
|
||||
private void extracted(BlockStmt body, PropertyMetaModel property) {
|
||||
if (property.isNode()) {
|
||||
if (property.isNodeList()) {
|
||||
body.addStatement(f(
|
||||
"NodeList<%s> %s = modifyList(n.%s(), arg);",
|
||||
property.getTypeNameGenerified(), property.getName(), property.getGetterMethodName()));
|
||||
} else if (property.isOptional()) {
|
||||
body.addStatement(f(
|
||||
"%s %s = n.%s().map(s -> (%s) s.accept(this, arg)).orElse(null);",
|
||||
property.getTypeNameGenerified(),
|
||||
property.getName(),
|
||||
property.getGetterMethodName(),
|
||||
property.getTypeNameGenerified()));
|
||||
} else {
|
||||
body.addStatement(f(
|
||||
"%s %s = (%s) n.%s().accept(this, arg);",
|
||||
property.getTypeNameGenerified(),
|
||||
property.getName(),
|
||||
property.getTypeNameGenerified(),
|
||||
property.getGetterMethodName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.JavaParserMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
public class NoCommentEqualsVisitorGenerator extends VisitorGenerator {
|
||||
|
||||
public NoCommentEqualsVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "NoCommentEqualsVisitor", "Boolean", "Visitable", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
if (!(node.equals(JavaParserMetaModel.lineCommentMetaModel)
|
||||
|| node.equals(JavaParserMetaModel.blockCommentMetaModel)
|
||||
|| node.equals(JavaParserMetaModel.javadocCommentMetaModel))) {
|
||||
|
||||
body.addStatement(f("final %s n2 = (%s) arg;", node.getTypeName(), node.getTypeName()));
|
||||
|
||||
for (PropertyMetaModel field : node.getAllPropertyMetaModels()) {
|
||||
final String getter = field.getGetterMethodName() + "()";
|
||||
if (field.equals(JavaParserMetaModel.nodeMetaModel.commentPropertyMetaModel)) continue;
|
||||
if (field.getNodeReference().isPresent()) {
|
||||
if (field.isNodeList()) {
|
||||
body.addStatement(f("if (!nodesEquals(n.%s, n2.%s)) return false;", getter, getter));
|
||||
} else {
|
||||
body.addStatement(f("if (!nodeEquals(n.%s, n2.%s)) return false;", getter, getter));
|
||||
}
|
||||
} else {
|
||||
body.addStatement(f("if (!objEquals(n.%s, n2.%s)) return false;", getter, getter));
|
||||
}
|
||||
}
|
||||
if (body.getStatements().size() == 1) {
|
||||
// Only the cast line was added, but nothing is using it, so remove it again.
|
||||
body.getStatements().clear();
|
||||
}
|
||||
}
|
||||
body.addStatement("return true;");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseStatement;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.JavaParserMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SeparatedItemStringBuilder;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.util.List;
|
||||
|
||||
public class NoCommentHashCodeVisitorGenerator extends VisitorGenerator {
|
||||
|
||||
public NoCommentHashCodeVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "NoCommentHashCodeVisitor", "Integer", "Void", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
final BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
final SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder("return ", "* 31 +", ";");
|
||||
final List<PropertyMetaModel> propertyMetaModels = node.getAllPropertyMetaModels();
|
||||
if (node.equals(JavaParserMetaModel.lineCommentMetaModel)
|
||||
|| node.equals(JavaParserMetaModel.blockCommentMetaModel)
|
||||
|| node.equals(JavaParserMetaModel.javadocCommentMetaModel)
|
||||
|| propertyMetaModels.isEmpty()) {
|
||||
builder.append("0");
|
||||
} else {
|
||||
for (PropertyMetaModel field : propertyMetaModels) {
|
||||
final String getter = field.getGetterMethodName() + "()";
|
||||
if (field.equals(JavaParserMetaModel.nodeMetaModel.commentPropertyMetaModel)) {
|
||||
if (propertyMetaModels.size() == 1) {
|
||||
builder.append("0");
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Is this field another AST node? Visit it.
|
||||
if (field.getNodeReference().isPresent()) {
|
||||
if (field.isOptional()) {
|
||||
builder.append("(n.%s.isPresent()? n.%s.get().accept(this, arg):0)", getter, getter);
|
||||
} else {
|
||||
builder.append("(n.%s.accept(this, arg))", getter);
|
||||
}
|
||||
} else {
|
||||
Class<?> type = field.getType();
|
||||
if (type.equals(boolean.class)) {
|
||||
builder.append("(n.%s?1:0)", getter);
|
||||
} else if (type.equals(int.class)) {
|
||||
builder.append("n.%s", getter);
|
||||
} else {
|
||||
builder.append("(n.%s.hashCode())", getter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
body.addStatement(parseStatement(builder.toString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's ObjectIdentityEqualsVisitor.
|
||||
*/
|
||||
public class ObjectIdentityEqualsVisitorGenerator extends VisitorGenerator {
|
||||
public ObjectIdentityEqualsVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(
|
||||
sourceRoot,
|
||||
"com.github.javaparser.ast.visitor",
|
||||
"ObjectIdentityEqualsVisitor",
|
||||
"Boolean",
|
||||
"Visitable",
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
body.addStatement("return n == arg;");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's ObjectIdentityHashCodeVisitor.
|
||||
*/
|
||||
public class ObjectIdentityHashCodeVisitorGenerator extends VisitorGenerator {
|
||||
public ObjectIdentityHashCodeVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(
|
||||
sourceRoot,
|
||||
"com.github.javaparser.ast.visitor",
|
||||
"ObjectIdentityHashCodeVisitor",
|
||||
"Integer",
|
||||
"Void",
|
||||
true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
final BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
body.addStatement("return n.hashCode();");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's VoidVisitorAdapter.
|
||||
*/
|
||||
public class VoidVisitorAdapterGenerator extends VisitorGenerator {
|
||||
public VoidVisitorAdapterGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "VoidVisitorAdapter", "void", "A", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
for (PropertyMetaModel field : node.getAllPropertyMetaModels()) {
|
||||
final String getter = field.getGetterMethodName() + "()";
|
||||
if (field.getNodeReference().isPresent()) {
|
||||
if (field.isOptional() && field.isNodeList()) {
|
||||
body.addStatement(f("n.%s.ifPresent( l -> l.forEach( v -> v.accept(this, arg)));", getter));
|
||||
} else if (field.isOptional()) {
|
||||
body.addStatement(f("n.%s.ifPresent(l -> l.accept(this, arg));", getter));
|
||||
} else if (field.isNodeList()) {
|
||||
body.addStatement(f("n.%s.forEach(p -> p.accept(this, arg));", getter));
|
||||
} else {
|
||||
body.addStatement(f("n.%s.accept(this, arg);", getter));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's VoidVisitor.
|
||||
*/
|
||||
public class VoidVisitorGenerator extends VisitorGenerator {
|
||||
public VoidVisitorGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "VoidVisitor", "void", "A", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(false));
|
||||
|
||||
visitMethod.setBody(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.visitor;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.generator.VisitorGenerator;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
|
||||
/**
|
||||
* Generates JavaParser's VoidVisitorWithDefaults.
|
||||
*/
|
||||
public class VoidVisitorWithDefaultsGenerator extends VisitorGenerator {
|
||||
public VoidVisitorWithDefaultsGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot, "com.github.javaparser.ast.visitor", "VoidVisitorWithDefaults", "void", "A", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void generateVisitMethodBody(
|
||||
BaseNodeMetaModel node, MethodDeclaration visitMethod, CompilationUnit compilationUnit) {
|
||||
visitMethod.getParameters().forEach(p -> p.setFinal(true));
|
||||
|
||||
BlockStmt body = visitMethod.getBody().get();
|
||||
body.getStatements().clear();
|
||||
|
||||
body.addStatement("defaultAction(n, arg);");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.quality;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.printer.DefaultPrettyPrinter;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class NotNullGeneratorTest {
|
||||
|
||||
@Test
|
||||
void testExecutionOfGenerator() throws Exception {
|
||||
|
||||
// Setup the
|
||||
String resourcesFolderPath = getClass().getCanonicalName().replace(".", File.separator);
|
||||
|
||||
String basePath = Paths.get("src", "test", "resources").toString();
|
||||
Path originalFile = Paths.get(basePath, resourcesFolderPath, "original");
|
||||
Path expectedFile = Paths.get(basePath, resourcesFolderPath, "expected");
|
||||
|
||||
SourceRoot originalSources = new SourceRoot(originalFile);
|
||||
SourceRoot expectedSources = new SourceRoot(expectedFile);
|
||||
expectedSources.tryToParse();
|
||||
|
||||
// Generate the information
|
||||
new NotNullGenerator(originalSources).generate();
|
||||
|
||||
List<CompilationUnit> editedSourceCus = originalSources.getCompilationUnits();
|
||||
List<CompilationUnit> expectedSourcesCus = expectedSources.getCompilationUnits();
|
||||
assertEquals(expectedSourcesCus.size(), editedSourceCus.size());
|
||||
|
||||
// Check if all the files match the expected result
|
||||
for (int i = 0; i < editedSourceCus.size(); i++) {
|
||||
|
||||
DefaultPrettyPrinter printer = new DefaultPrettyPrinter();
|
||||
String expectedCode = printer.print(expectedSourcesCus.get(i));
|
||||
String editedCode = printer.print(editedSourceCus.get(i));
|
||||
|
||||
if (!expectedCode.equals(editedCode)) {
|
||||
System.out.println("Expected:");
|
||||
System.out.println("####");
|
||||
System.out.println(expectedSourcesCus.get(i));
|
||||
System.out.println("####");
|
||||
System.out.println("Actual:");
|
||||
System.out.println("####");
|
||||
System.out.println(editedSourceCus.get(i));
|
||||
System.out.println("####");
|
||||
fail("Actual code doesn't match with the expected code.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.core.utils;
|
||||
|
||||
import static com.github.javaparser.generator.core.utils.CodeUtils.castValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.github.javaparser.StaticJavaParser;
|
||||
import com.github.javaparser.ast.type.PrimitiveType;
|
||||
import com.github.javaparser.ast.type.Type;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class CodeUtilsTest {
|
||||
|
||||
private static final String RETURN_VALUE = "this";
|
||||
|
||||
@Test
|
||||
void castReturnValue_whenAValueMatchesTheExpectedTypeNoCastIsNeeded() {
|
||||
Type returnType = PrimitiveType.booleanType();
|
||||
Type valueType = PrimitiveType.booleanType();
|
||||
|
||||
assertEquals(RETURN_VALUE, castValue(RETURN_VALUE, returnType, valueType.asString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void castReturnValue_whenAValueIsNotAssignedByReturnShouldBeCasted() {
|
||||
Type returnType = StaticJavaParser.parseType("String");
|
||||
Type valueType = StaticJavaParser.parseType("Object");
|
||||
|
||||
assertEquals(
|
||||
String.format("(%s) %s", returnType, RETURN_VALUE),
|
||||
castValue(RETURN_VALUE, returnType, valueType.asString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2021 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.example;
|
||||
|
||||
import com.github.javaparser.quality.NotNull;
|
||||
import com.github.javaparser.quality.Nullable;
|
||||
import com.github.javaparser.quality.Preconditions;
|
||||
|
||||
class ConstructorParameterTest {
|
||||
|
||||
private final String a;
|
||||
|
||||
private final String b;
|
||||
|
||||
private final String c;
|
||||
|
||||
public ConstructorParameterTest(@NotNull String notNullString, @Nullable String nullableString, String otherString) {
|
||||
Preconditions.checkNotNull(notNullString, "Parameter notNullString can't be null.");
|
||||
this.a = notNullString;
|
||||
this.b = nullableString;
|
||||
this.c = otherString;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2021 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
import com.github.javaparser.quality.NotNull;
|
||||
import com.github.javaparser.quality.Preconditions;
|
||||
|
||||
class A {
|
||||
|
||||
public A(String a) {
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
|
||||
public B(@NotNull String c) {
|
||||
super("ok");
|
||||
Preconditions.checkNotNull(c, "Parameter c can't be null.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2021 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
import com.github.javaparser.quality.NotNull;
|
||||
import com.github.javaparser.quality.Preconditions;
|
||||
|
||||
class A {
|
||||
|
||||
public void method(@NotNull String notNull, @NotNull String secondNotNull) {
|
||||
Preconditions.checkNotNull(notNull, "Parameter notNull can't be null.");
|
||||
Preconditions.checkNotNull(secondNotNull, "Parameter secondNotNull can't be null.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2021 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
import com.github.javaparser.quality.NotNull;
|
||||
import com.github.javaparser.quality.Preconditions;
|
||||
|
||||
class A {
|
||||
|
||||
public void method(@NotNull String notNull) {
|
||||
Preconditions.checkNotNull(notNull, "Parameter notNull can't be null.");
|
||||
}
|
||||
|
||||
public void method(int age) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2021 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.example;
|
||||
|
||||
import com.github.javaparser.quality.NotNull;
|
||||
import com.github.javaparser.quality.Nullable;
|
||||
|
||||
class ConstructorParameterTest {
|
||||
|
||||
private final String a;
|
||||
private final String b;
|
||||
private final String c;
|
||||
|
||||
public ConstructorParameterTest(@NotNull String notNullString, @Nullable String nullableString,
|
||||
String otherString) {
|
||||
this.a = notNullString;
|
||||
this.b = nullableString;
|
||||
this.c = otherString;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2021 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
import com.github.javaparser.quality.NotNull;
|
||||
|
||||
class A {
|
||||
public A(String a) {}
|
||||
}
|
||||
|
||||
class B {
|
||||
|
||||
public B(@NotNull String c) {
|
||||
super("ok");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2021 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
import com.github.javaparser.quality.NotNull;
|
||||
import com.github.javaparser.quality.Preconditions;
|
||||
|
||||
class A {
|
||||
|
||||
public void method(@NotNull String notNull, @NotNull String secondNotNull) {
|
||||
Preconditions.checkNotNull(notNull, "This was aan old message.");
|
||||
Preconditions.checkNotNull(secondNotNull, "Parameter secondNotNull can't be null.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2021 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
import com.github.javaparser.quality.NotNull;
|
||||
import com.github.javaparser.quality.Preconditions;
|
||||
|
||||
class A {
|
||||
|
||||
public void method(@NotNull String notNull) {}
|
||||
|
||||
public void method(int age) {}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>javaparser-parent</artifactId>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<version>3.27.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>javaparser-core-metamodel-generator</artifactId>
|
||||
<description>The tool that generates the code in the javaparser-metamodel module</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<artifactId>javaparser-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- no need to release this module -->
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>run-generators</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>generate-javaparser-metamodel</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<classpathScope>test</classpathScope>
|
||||
<mainClass>com.github.javaparser.generator.metamodel.MetaModelGenerator</mainClass>
|
||||
<arguments>
|
||||
<argument>${project.basedir}</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator;
|
||||
|
||||
import static com.github.javaparser.ast.NodeList.toNodeList;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ParseResult;
|
||||
import com.github.javaparser.Problem;
|
||||
import com.github.javaparser.StaticJavaParser;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Generated;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.body.*;
|
||||
import com.github.javaparser.ast.comments.Comment;
|
||||
import com.github.javaparser.ast.comments.JavadocComment;
|
||||
import com.github.javaparser.ast.expr.AnnotationExpr;
|
||||
import com.github.javaparser.ast.expr.Expression;
|
||||
import com.github.javaparser.ast.expr.StringLiteralExpr;
|
||||
import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
|
||||
import com.github.javaparser.ast.stmt.Statement;
|
||||
import com.github.javaparser.ast.stmt.SwitchStmt;
|
||||
import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter;
|
||||
import com.github.javaparser.utils.Log;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* A general pattern that the generators in this module will follow.
|
||||
*/
|
||||
public abstract class AbstractGenerator {
|
||||
|
||||
protected static final String COPYRIGHT_NOTICE_JP_CORE = "\n" + " * Copyright (C) 2007-2010 Júlio Vilmar Gesser.\n"
|
||||
+ " * Copyright (C) 2011, 2013-2024 The JavaParser Team.\n"
|
||||
+ " *\n"
|
||||
+ " * This file is part of JavaParser.\n"
|
||||
+ " *\n"
|
||||
+ " * JavaParser can be used either under the terms of\n"
|
||||
+ " * a) the GNU Lesser General Public License as published by\n"
|
||||
+ " * the Free Software Foundation, either version 3 of the License, or\n"
|
||||
+ " * (at your option) any later version.\n"
|
||||
+ " * b) the terms of the Apache License\n"
|
||||
+ " *\n"
|
||||
+ " * You should have received a copy of both licenses in LICENCE.LGPL and\n"
|
||||
+ " * LICENCE.APACHE. Please refer to those files for details.\n"
|
||||
+ " *\n"
|
||||
+ " * JavaParser is distributed in the hope that it will be useful,\n"
|
||||
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
||||
+ " * GNU Lesser General Public License for more details.\n"
|
||||
+ " ";
|
||||
|
||||
protected static final String COPYRIGHT_NOTICE_JP_SS = "\n" + " * Copyright (C) 2015-2016 Federico Tomassetti\n"
|
||||
+ " * Copyright (C) 2017-2024 The JavaParser Team.\n"
|
||||
+ " *\n"
|
||||
+ " * This file is part of JavaParser.\n"
|
||||
+ " *\n"
|
||||
+ " * JavaParser can be used either under the terms of\n"
|
||||
+ " * a) the GNU Lesser General Public License as published by\n"
|
||||
+ " * the Free Software Foundation, either version 3 of the License, or\n"
|
||||
+ " * (at your option) any later version.\n"
|
||||
+ " * b) the terms of the Apache License\n"
|
||||
+ " *\n"
|
||||
+ " * You should have received a copy of both licenses in LICENCE.LGPL and\n"
|
||||
+ " * LICENCE.APACHE. Please refer to those files for details.\n"
|
||||
+ " *\n"
|
||||
+ " * JavaParser is distributed in the hope that it will be useful,\n"
|
||||
+ " * but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||
+ " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
|
||||
+ " * GNU Lesser General Public License for more details.\n"
|
||||
+ " ";
|
||||
|
||||
protected final SourceRoot sourceRoot;
|
||||
|
||||
protected AbstractGenerator(SourceRoot sourceRoot) {
|
||||
this.sourceRoot = sourceRoot;
|
||||
}
|
||||
|
||||
private void addOrReplaceMethod(
|
||||
ClassOrInterfaceDeclaration containingClassOrInterface,
|
||||
CallableDeclaration<?> callable,
|
||||
Runnable onNoExistingMethod) {
|
||||
List<CallableDeclaration<?>> existingMatchingCallables =
|
||||
containingClassOrInterface.getCallablesWithSignature(callable.getSignature());
|
||||
if (existingMatchingCallables.isEmpty()) {
|
||||
// A matching callable exists -- will now normally add/insert.
|
||||
onNoExistingMethod.run();
|
||||
} else {
|
||||
// A matching callable doe NOT exist -- will now normally replace.
|
||||
if (existingMatchingCallables.size() > 1) {
|
||||
throw new AssertionError(f(
|
||||
"Wanted to regenerate a method with signature %s in %s, but found more than one, and unable to disambiguate.",
|
||||
callable.getSignature(), containingClassOrInterface.getNameAsString()));
|
||||
}
|
||||
|
||||
final CallableDeclaration<?> existingCallable = existingMatchingCallables.get(0);
|
||||
|
||||
// Attempt to retain any existing javadoc.
|
||||
|
||||
// TODO: Confirm what is done with normal comments...
|
||||
Optional<JavadocComment> callableJavadocComment = callable.getJavadocComment();
|
||||
Optional<JavadocComment> existingCallableJavadocComment = existingCallable.getJavadocComment();
|
||||
|
||||
Optional<Comment> callableComment = callable.getComment();
|
||||
Optional<Comment> existingCallableComment = existingCallable.getComment();
|
||||
|
||||
callable.setComment(callableComment.orElseGet(
|
||||
() -> existingCallable.getComment().orElse(null)));
|
||||
//
|
||||
// callable.setJavadocComment(callableJavadocComment.orElse(existingCallableJavadocComment.orElse(null)));
|
||||
|
||||
// Mark the method as having been fully/partially generated.
|
||||
annotateGenerated(callable);
|
||||
|
||||
if (callable.isMethodDeclaration()) {
|
||||
// We want the methods that we generate/insert to be pretty printed.
|
||||
MethodDeclaration prettyMethodDeclaration = prettyPrint(callable.asMethodDeclaration(), " ");
|
||||
|
||||
// Do the replacement.
|
||||
containingClassOrInterface.getMembers().replace(existingCallable, prettyMethodDeclaration);
|
||||
} else {
|
||||
// TODO: Unable to parse a constructor directly...?
|
||||
|
||||
// Do the replacement.
|
||||
containingClassOrInterface.getMembers().replace(existingCallable, callable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that looks for a method or constructor with an identical signature as "callable" and replaces it
|
||||
* with callable. If not found, adds callable. When the new callable has no javadoc, any old javadoc will be kept.
|
||||
*/
|
||||
protected void addOrReplaceWhenSameSignature(
|
||||
ClassOrInterfaceDeclaration containingClassOrInterface, CallableDeclaration<?> callable) {
|
||||
addOrReplaceMethod(containingClassOrInterface, callable, () -> {
|
||||
annotateGenerated(callable);
|
||||
containingClassOrInterface.addMember(callable);
|
||||
});
|
||||
}
|
||||
|
||||
protected void after() throws Exception {}
|
||||
|
||||
/**
|
||||
* @param node The node to which the annotation will be added.
|
||||
* @param annotation The annotation to be added to the given node.
|
||||
* @param content Where an annotation has content, it is passed here (otherwise null).
|
||||
* @param <T> Only accept nodes which accept annotations.
|
||||
*/
|
||||
private <T extends NodeWithAnnotations<?>> void annotate(T node, Class<?> annotation, Expression content) {
|
||||
NodeList<AnnotationExpr> annotations = node.getAnnotations().stream()
|
||||
.filter(a -> !a.getNameAsString().equals(annotation.getSimpleName()))
|
||||
.collect(toNodeList());
|
||||
|
||||
node.setAnnotations(annotations);
|
||||
|
||||
if (content != null) {
|
||||
node.addSingleMemberAnnotation(annotation.getSimpleName(), content);
|
||||
} else {
|
||||
node.addMarkerAnnotation(annotation.getSimpleName());
|
||||
}
|
||||
|
||||
// The annotation class will normally need to be imported.
|
||||
node.tryAddImportToParentCompilationUnit(annotation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param node The node to which the {@code @Annotated} annotation will be added.
|
||||
* @param <T>
|
||||
*/
|
||||
protected <T extends Node & NodeWithAnnotations<?>> void annotateGenerated(T node) {
|
||||
annotate(node, Generated.class, new StringLiteralExpr(getClass().getName()));
|
||||
}
|
||||
|
||||
protected <T extends Node & NodeWithAnnotations<?>> void removeAnnotation(T node, Class<?> annotation) {
|
||||
node.getAnnotations()
|
||||
.removeIf(annotationExpr -> annotationExpr.getName().asString().equals(annotation.getSimpleName()));
|
||||
|
||||
node.findAncestor(CompilationUnit.class).ifPresent(compilationUnit -> {
|
||||
removeAnnotationImportIfUnused(compilationUnit, annotation);
|
||||
});
|
||||
}
|
||||
|
||||
protected <T extends Node & NodeWithAnnotations<?>> void removeGenerated(T node) {
|
||||
removeAnnotation(node, Generated.class);
|
||||
}
|
||||
|
||||
protected void removeAnnotationImportIfUnused(CompilationUnit compilationUnit, Class<?> annotation) {
|
||||
|
||||
List<AnnotationExpr> staleAnnotations = compilationUnit.findAll(AnnotationExpr.class).stream()
|
||||
.filter(annotationExpr -> annotationExpr.getName().asString().equals(annotation.getSimpleName()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (staleAnnotations.isEmpty()) {
|
||||
// If there are no usages of this annotation, remove the import.
|
||||
boolean isRemoved = compilationUnit.getImports().removeIf(importDeclaration -> {
|
||||
return importDeclaration.getNameAsString().equals(annotation.getCanonicalName());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param method The node to which the {@code @Override} annotation will be added.
|
||||
*/
|
||||
protected void annotateOverridden(MethodDeclaration method) {
|
||||
annotate(method, Override.class, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param node The node to which the {@code @SuppressWarnings} annotation will be added.
|
||||
* @param <T> Only accept nodes which accept annotations.
|
||||
*/
|
||||
protected <T extends NodeWithAnnotations<?>> void annotateSuppressWarnings(T node, String warningType) {
|
||||
annotate(node, SuppressWarnings.class, new StringLiteralExpr(warningType));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all methods from containingClassOrInterface that have the same signature as callable.
|
||||
* This is not currently used directly by any current generators, but may be useful when changing a generator
|
||||
* and you need to get rid of a set of outdated methods.
|
||||
*/
|
||||
protected void removeMethodWithSameSignature(
|
||||
ClassOrInterfaceDeclaration containingClassOrInterface, CallableDeclaration<?> callable) {
|
||||
for (CallableDeclaration<?> existingCallable :
|
||||
containingClassOrInterface.getCallablesWithSignature(callable.getSignature())) {
|
||||
containingClassOrInterface.remove(existingCallable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that looks for a method or constructor with an identical signature as "callable" and replaces it
|
||||
* with callable. If not found, fails. When the new callable has no javadoc, any old javadoc will be kept. The
|
||||
* method or constructor is annotated with the generator class.
|
||||
*/
|
||||
protected void replaceWhenSameSignature(
|
||||
ClassOrInterfaceDeclaration containingClassOrInterface, CallableDeclaration<?> callable) {
|
||||
addOrReplaceMethod(containingClassOrInterface, callable, () -> {
|
||||
throw new AssertionError(f(
|
||||
"Wanted to regenerate a method with signature %s in %s, but it wasn't there.",
|
||||
callable.getSignature(), containingClassOrInterface.getNameAsString()));
|
||||
});
|
||||
}
|
||||
|
||||
protected List<CompilationUnit> getParsedCompilationUnitsFromSourceRoot(SourceRoot sourceRoot) throws IOException {
|
||||
List<CompilationUnit> cus = sourceRoot.getCompilationUnits();
|
||||
List<ParseResult<CompilationUnit>> parseResults = sourceRoot.tryToParse();
|
||||
|
||||
boolean allParsed = parseResults.stream().allMatch(ParseResult::isSuccessful);
|
||||
if (!allParsed) {
|
||||
List<ParseResult<CompilationUnit>> problemResults = parseResults.stream()
|
||||
.filter(compilationUnitParseResult -> !compilationUnitParseResult.isSuccessful())
|
||||
.collect(Collectors.toList());
|
||||
for (int i = 0; i < problemResults.size(); i++) {
|
||||
ParseResult<CompilationUnit> parseResult = problemResults.get(i);
|
||||
List<Problem> problems = parseResult.getProblems();
|
||||
Log.info("");
|
||||
Log.info("Problems (" + (i + 1) + " of " + problemResults.size() + "): ");
|
||||
Log.info(problems.toString());
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Expected all files to parse.");
|
||||
}
|
||||
|
||||
Log.info("parseResults.size() = " + parseResults.size());
|
||||
|
||||
return parseResults.stream()
|
||||
.map(ParseResult::getResult)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected MethodDeclaration prettyPrint(MethodDeclaration methodDeclaration) {
|
||||
return prettyPrint(methodDeclaration, "");
|
||||
}
|
||||
|
||||
protected MethodDeclaration prettyPrint(MethodDeclaration methodDeclaration, String indent) {
|
||||
String methodDeclarationString = indent + methodDeclaration.toString().replaceAll("(\\R)", "$1" + indent);
|
||||
MethodDeclaration prettyMethodDeclaration = StaticJavaParser.parseMethodDeclaration(methodDeclarationString);
|
||||
|
||||
return prettyMethodDeclaration;
|
||||
}
|
||||
|
||||
protected EnumDeclaration prettyPrint(EnumDeclaration enumDeclaration) {
|
||||
return prettyPrint(enumDeclaration, "");
|
||||
}
|
||||
|
||||
protected EnumDeclaration prettyPrint(EnumDeclaration enumDeclaration, String indent) {
|
||||
String enumDeclarationString = indent + enumDeclaration.toString().replaceAll("(\\R)", "$1" + indent);
|
||||
TypeDeclaration<?> prettyEnumDeclaration = StaticJavaParser.parseTypeDeclaration(enumDeclarationString);
|
||||
|
||||
LexicalPreservingPrinter.setup(prettyEnumDeclaration);
|
||||
|
||||
// We know that it is an enum declaration.
|
||||
return prettyEnumDeclaration.asEnumDeclaration();
|
||||
}
|
||||
|
||||
protected SwitchStmt prettyPrint(SwitchStmt switchStmt) {
|
||||
return prettyPrint(switchStmt, "");
|
||||
}
|
||||
|
||||
protected SwitchStmt prettyPrint(SwitchStmt switchStmt, String indent) {
|
||||
String switchStmtString = indent + switchStmt.toString().replaceAll("(\\R)", "$1" + indent);
|
||||
Statement prettySwitchStmt = StaticJavaParser.parseStatement(switchStmtString);
|
||||
|
||||
LexicalPreservingPrinter.setup(prettySwitchStmt);
|
||||
|
||||
// We know that it is an switch statement.
|
||||
return prettySwitchStmt.asSwitchStmt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.metamodel;
|
||||
|
||||
import static java.lang.reflect.Modifier.isAbstract;
|
||||
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A hacky thing that collects flags we need from AST types to generate the metamodel.
|
||||
*/
|
||||
class AstTypeAnalysis {
|
||||
final boolean isAbstract;
|
||||
boolean isOptional = false;
|
||||
boolean isNodeList = false;
|
||||
boolean isSelfType = false;
|
||||
Class<?> innerType;
|
||||
|
||||
AstTypeAnalysis(Type type) {
|
||||
if (type instanceof Class<?>) {
|
||||
TypeVariable<? extends Class<?>>[] typeParameters = ((Class<?>) type).getTypeParameters();
|
||||
if (typeParameters.length > 0) {
|
||||
isSelfType = true;
|
||||
}
|
||||
} else {
|
||||
while (type instanceof ParameterizedType) {
|
||||
ParameterizedType t = (ParameterizedType) type;
|
||||
Type currentOuterType = t.getRawType();
|
||||
if (currentOuterType == NodeList.class) {
|
||||
isNodeList = true;
|
||||
}
|
||||
if (currentOuterType == Optional.class) {
|
||||
isOptional = true;
|
||||
}
|
||||
|
||||
if (t.getActualTypeArguments()[0] instanceof WildcardType) {
|
||||
type = t.getRawType();
|
||||
isSelfType = true;
|
||||
break;
|
||||
}
|
||||
type = t.getActualTypeArguments()[0];
|
||||
}
|
||||
}
|
||||
innerType = (Class<?>) type;
|
||||
isAbstract = isAbstract(innerType.getModifiers());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.metamodel;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseStatement;
|
||||
import static com.github.javaparser.generator.metamodel.MetaModelGenerator.nodeMetaModelFieldName;
|
||||
import static com.github.javaparser.generator.metamodel.MetaModelGenerator.propertyMetaModelFieldName;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
|
||||
import com.github.javaparser.ast.AllFieldsConstructor;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.stmt.Statement;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
class InitializeConstructorParametersStatementsGenerator {
|
||||
void generate(Class<? extends Node> nodeClass, NodeList<Statement> initializeConstructorParametersStatements) {
|
||||
if (nodeClass == Node.class) {
|
||||
return;
|
||||
}
|
||||
Constructor<?> constructor = findAllFieldsConstructor(nodeClass);
|
||||
for (java.lang.reflect.Parameter parameter : constructor.getParameters()) {
|
||||
Field field = findFieldInClass(nodeClass, parameter.getName());
|
||||
|
||||
String addFieldStatement = f(
|
||||
"%s.getConstructorParameters().add(%s.%s);",
|
||||
nodeMetaModelFieldName(nodeClass),
|
||||
nodeMetaModelFieldName(field.getDeclaringClass()),
|
||||
propertyMetaModelFieldName(field));
|
||||
|
||||
initializeConstructorParametersStatements.add(parseStatement(addFieldStatement));
|
||||
}
|
||||
}
|
||||
|
||||
private Field findFieldInClass(Class<?> nodeClass, String name) {
|
||||
Class<?> searchClass = nodeClass;
|
||||
do {
|
||||
for (Field field : searchClass.getDeclaredFields()) {
|
||||
if (field.getName().equals(name)) {
|
||||
return field;
|
||||
}
|
||||
}
|
||||
searchClass = searchClass.getSuperclass();
|
||||
} while (searchClass != null);
|
||||
throw new AssertionError(
|
||||
f("Couldn't find constructor parameter %s as a field, class %s", name, nodeClass.getSimpleName()));
|
||||
}
|
||||
|
||||
private Constructor<?> findAllFieldsConstructor(Class<? extends Node> nodeClass) {
|
||||
for (Constructor<?> constructor : nodeClass.getDeclaredConstructors()) {
|
||||
for (Annotation annotation : constructor.getAnnotations()) {
|
||||
if (annotation.annotationType() == AllFieldsConstructor.class) {
|
||||
return constructor;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new AssertionError(
|
||||
f("Node class %s has no constructor annotated with @AllFieldsConstructor", nodeClass.getSimpleName()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.metamodel;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parseStatement;
|
||||
import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC;
|
||||
import static com.github.javaparser.generator.metamodel.MetaModelGenerator.isNode;
|
||||
import static com.github.javaparser.generator.metamodel.MetaModelGenerator.nodeMetaModelName;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.*;
|
||||
import static com.github.javaparser.utils.Utils.decapitalize;
|
||||
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.stmt.Statement;
|
||||
import com.github.javaparser.metamodel.NonEmptyProperty;
|
||||
import com.github.javaparser.metamodel.OptionalProperty;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
class InitializePropertyMetaModelsStatementsGenerator {
|
||||
void generate(
|
||||
Field field,
|
||||
ClassOrInterfaceDeclaration nodeMetaModelClass,
|
||||
String nodeMetaModelFieldName,
|
||||
NodeList<Statement> initializePropertyMetaModelsStatements) {
|
||||
final AstTypeAnalysis fieldTypeAnalysis = new AstTypeAnalysis(field.getGenericType());
|
||||
|
||||
final Class<?> fieldType = fieldTypeAnalysis.innerType;
|
||||
final String typeName = fieldType.getTypeName().replace('$', '.');
|
||||
final String propertyMetaModelFieldName = field.getName() + "PropertyMetaModel";
|
||||
nodeMetaModelClass.addField("PropertyMetaModel", propertyMetaModelFieldName, PUBLIC);
|
||||
final String propertyInitializer = f(
|
||||
"new PropertyMetaModel(%s, \"%s\", %s.class, %s, %s, %s, %s, %s)",
|
||||
nodeMetaModelFieldName,
|
||||
field.getName(),
|
||||
typeName,
|
||||
optionalOf(decapitalize(nodeMetaModelName(fieldType)), isNode(fieldType)),
|
||||
isOptional(field),
|
||||
isNonEmpty(field),
|
||||
fieldTypeAnalysis.isNodeList,
|
||||
fieldTypeAnalysis.isSelfType);
|
||||
final String fieldSetting =
|
||||
f("%s.%s=%s;", nodeMetaModelFieldName, propertyMetaModelFieldName, propertyInitializer);
|
||||
final String fieldAddition = f(
|
||||
"%s.getDeclaredPropertyMetaModels().add(%s.%s);",
|
||||
nodeMetaModelFieldName, nodeMetaModelFieldName, propertyMetaModelFieldName);
|
||||
|
||||
initializePropertyMetaModelsStatements.add(parseStatement(fieldSetting));
|
||||
initializePropertyMetaModelsStatements.add(parseStatement(fieldAddition));
|
||||
}
|
||||
|
||||
void generateDerivedProperty(
|
||||
Method method,
|
||||
ClassOrInterfaceDeclaration nodeMetaModelClass,
|
||||
String nodeMetaModelFieldName,
|
||||
NodeList<Statement> initializePropertyMetaModelsStatements) {
|
||||
final AstTypeAnalysis returnTypeAnalysis = new AstTypeAnalysis(method.getGenericReturnType());
|
||||
|
||||
final Class<?> innermostReturnType = returnTypeAnalysis.innerType;
|
||||
final String typeName = innermostReturnType.getTypeName().replace('$', '.');
|
||||
final String propertyMetaModelFieldName = getterToPropertyName(method.getName()) + "PropertyMetaModel";
|
||||
nodeMetaModelClass.addField("PropertyMetaModel", propertyMetaModelFieldName, PUBLIC);
|
||||
final String propertyInitializer = f(
|
||||
"new PropertyMetaModel(%s, \"%s\", %s.class, %s, %s, %s, %s, %s)",
|
||||
nodeMetaModelFieldName,
|
||||
getterToPropertyName(method.getName()),
|
||||
typeName,
|
||||
optionalOf(decapitalize(nodeMetaModelName(innermostReturnType)), isNode(innermostReturnType)),
|
||||
returnTypeAnalysis.isOptional,
|
||||
isNonEmpty(method),
|
||||
returnTypeAnalysis.isNodeList,
|
||||
returnTypeAnalysis.isSelfType);
|
||||
final String fieldSetting =
|
||||
f("%s.%s=%s;", nodeMetaModelFieldName, propertyMetaModelFieldName, propertyInitializer);
|
||||
final String fieldAddition = f(
|
||||
"%s.getDerivedPropertyMetaModels().add(%s.%s);",
|
||||
nodeMetaModelFieldName, nodeMetaModelFieldName, propertyMetaModelFieldName);
|
||||
|
||||
initializePropertyMetaModelsStatements.add(parseStatement(fieldSetting));
|
||||
initializePropertyMetaModelsStatements.add(parseStatement(fieldAddition));
|
||||
}
|
||||
|
||||
private boolean isNonEmpty(Field field) {
|
||||
return field.isAnnotationPresent(NonEmptyProperty.class);
|
||||
}
|
||||
|
||||
private boolean isNonEmpty(Method method) {
|
||||
return method.isAnnotationPresent(NonEmptyProperty.class);
|
||||
}
|
||||
|
||||
private boolean isOptional(Field field) {
|
||||
return field.isAnnotationPresent(OptionalProperty.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.metamodel;
|
||||
|
||||
import static com.github.javaparser.utils.Utils.decapitalize;
|
||||
|
||||
import com.github.javaparser.ParserConfiguration;
|
||||
import com.github.javaparser.StaticJavaParser;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.CompactConstructorDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.stmt.Statement;
|
||||
import com.github.javaparser.generator.AbstractGenerator;
|
||||
import com.github.javaparser.printer.DefaultPrettyPrinter;
|
||||
import com.github.javaparser.printer.Printer;
|
||||
import com.github.javaparser.printer.configuration.DefaultConfigurationOption;
|
||||
import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration;
|
||||
import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption;
|
||||
import com.github.javaparser.printer.configuration.PrinterConfiguration;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class MetaModelGenerator extends AbstractGenerator {
|
||||
|
||||
static final String BASE_NODE_META_MODEL = "BaseNodeMetaModel";
|
||||
static final String METAMODEL_PACKAGE = "com.github.javaparser.metamodel";
|
||||
|
||||
/**
|
||||
* Note that order of this list is manually set and maintained.
|
||||
*/
|
||||
private static final List<Class<? extends Node>> ALL_NODE_CLASSES = new ArrayList<Class<? extends Node>>() {
|
||||
{
|
||||
/* Base classes go first, so we don't have to do any sorting to make sure
|
||||
generated classes can refer to their base generated classes without
|
||||
being afraid those are not initialized yet. */
|
||||
|
||||
// Fully qualified names used to make logical groupings (somewhat) more explicit.
|
||||
|
||||
//
|
||||
add(com.github.javaparser.ast.Node.class);
|
||||
|
||||
add(com.github.javaparser.ast.body.BodyDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.CallableDeclaration.class);
|
||||
add(com.github.javaparser.ast.expr.Expression.class);
|
||||
add(com.github.javaparser.ast.stmt.Statement.class);
|
||||
add(com.github.javaparser.ast.type.Type.class);
|
||||
|
||||
add(com.github.javaparser.ast.expr.AnnotationExpr.class);
|
||||
add(com.github.javaparser.ast.type.ReferenceType.class);
|
||||
add(com.github.javaparser.ast.body.TypeDeclaration.class);
|
||||
|
||||
add(com.github.javaparser.ast.expr.LiteralExpr.class);
|
||||
add(com.github.javaparser.ast.expr.LiteralStringValueExpr.class);
|
||||
add(com.github.javaparser.ast.expr.StringLiteralExpr.class);
|
||||
|
||||
add(com.github.javaparser.ast.modules.ModuleDeclaration.class);
|
||||
add(com.github.javaparser.ast.modules.ModuleDirective.class);
|
||||
|
||||
//
|
||||
add(com.github.javaparser.ast.ArrayCreationLevel.class);
|
||||
add(com.github.javaparser.ast.CompilationUnit.class);
|
||||
add(com.github.javaparser.ast.ImportDeclaration.class);
|
||||
add(com.github.javaparser.ast.Modifier.class);
|
||||
add(com.github.javaparser.ast.PackageDeclaration.class);
|
||||
|
||||
//
|
||||
add(com.github.javaparser.ast.body.AnnotationDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.AnnotationMemberDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.ConstructorDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.EnumConstantDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.EnumDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.FieldDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.InitializerDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.MethodDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.Parameter.class);
|
||||
add(com.github.javaparser.ast.body.ReceiverParameter.class);
|
||||
add(com.github.javaparser.ast.body.RecordDeclaration.class);
|
||||
add(CompactConstructorDeclaration.class);
|
||||
add(com.github.javaparser.ast.body.VariableDeclarator.class);
|
||||
|
||||
add(com.github.javaparser.ast.comments.Comment.class); // First, as it is the base of other comment types
|
||||
add(com.github.javaparser.ast.comments.BlockComment.class);
|
||||
add(com.github.javaparser.ast.comments.JavadocComment.class);
|
||||
add(com.github.javaparser.ast.comments.LineComment.class);
|
||||
|
||||
add(com.github.javaparser.ast.expr.ArrayAccessExpr.class);
|
||||
add(com.github.javaparser.ast.expr.ArrayCreationExpr.class);
|
||||
add(com.github.javaparser.ast.expr.ArrayInitializerExpr.class);
|
||||
add(com.github.javaparser.ast.expr.AssignExpr.class);
|
||||
add(com.github.javaparser.ast.expr.BinaryExpr.class);
|
||||
add(com.github.javaparser.ast.expr.BooleanLiteralExpr.class);
|
||||
add(com.github.javaparser.ast.expr.CastExpr.class);
|
||||
add(com.github.javaparser.ast.expr.CharLiteralExpr.class);
|
||||
add(com.github.javaparser.ast.expr.ClassExpr.class);
|
||||
add(com.github.javaparser.ast.expr.ConditionalExpr.class);
|
||||
add(com.github.javaparser.ast.expr.DoubleLiteralExpr.class);
|
||||
add(com.github.javaparser.ast.expr.EnclosedExpr.class);
|
||||
add(com.github.javaparser.ast.expr.FieldAccessExpr.class);
|
||||
add(com.github.javaparser.ast.expr.InstanceOfExpr.class);
|
||||
add(com.github.javaparser.ast.expr.IntegerLiteralExpr.class);
|
||||
add(com.github.javaparser.ast.expr.LambdaExpr.class);
|
||||
add(com.github.javaparser.ast.expr.LongLiteralExpr.class);
|
||||
add(com.github.javaparser.ast.expr.MarkerAnnotationExpr.class);
|
||||
add(com.github.javaparser.ast.expr.MemberValuePair.class);
|
||||
add(com.github.javaparser.ast.expr.MethodCallExpr.class);
|
||||
add(com.github.javaparser.ast.expr.MethodReferenceExpr.class);
|
||||
add(com.github.javaparser.ast.expr.NameExpr.class);
|
||||
add(com.github.javaparser.ast.expr.Name.class);
|
||||
add(com.github.javaparser.ast.expr.NormalAnnotationExpr.class);
|
||||
add(com.github.javaparser.ast.expr.NullLiteralExpr.class);
|
||||
add(com.github.javaparser.ast.expr.ObjectCreationExpr.class);
|
||||
add(com.github.javaparser.ast.expr.PatternExpr.class);
|
||||
add(com.github.javaparser.ast.expr.RecordPatternExpr.class);
|
||||
add(com.github.javaparser.ast.expr.SingleMemberAnnotationExpr.class);
|
||||
add(com.github.javaparser.ast.expr.SimpleName.class);
|
||||
add(com.github.javaparser.ast.expr.SuperExpr.class);
|
||||
add(com.github.javaparser.ast.expr.SwitchExpr.class);
|
||||
add(com.github.javaparser.ast.expr.TextBlockLiteralExpr.class);
|
||||
add(com.github.javaparser.ast.expr.ThisExpr.class);
|
||||
add(com.github.javaparser.ast.expr.TypeExpr.class);
|
||||
add(com.github.javaparser.ast.expr.TypePatternExpr.class);
|
||||
add(com.github.javaparser.ast.expr.UnaryExpr.class);
|
||||
add(com.github.javaparser.ast.expr.VariableDeclarationExpr.class);
|
||||
|
||||
add(com.github.javaparser.ast.stmt.AssertStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.BlockStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.BreakStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.CatchClause.class);
|
||||
add(com.github.javaparser.ast.stmt.ContinueStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.DoStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.EmptyStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.ExpressionStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.ForEachStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.ForStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.IfStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.LabeledStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.LocalClassDeclarationStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.LocalRecordDeclarationStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.ReturnStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.SwitchEntry.class);
|
||||
add(com.github.javaparser.ast.stmt.SwitchStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.SynchronizedStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.ThrowStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.TryStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.UnparsableStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.WhileStmt.class);
|
||||
add(com.github.javaparser.ast.stmt.YieldStmt.class);
|
||||
|
||||
add(com.github.javaparser.ast.type.ArrayType.class);
|
||||
add(com.github.javaparser.ast.type.ClassOrInterfaceType.class);
|
||||
add(com.github.javaparser.ast.type.IntersectionType.class);
|
||||
add(com.github.javaparser.ast.type.PrimitiveType.class);
|
||||
add(com.github.javaparser.ast.type.TypeParameter.class);
|
||||
add(com.github.javaparser.ast.type.UnionType.class);
|
||||
add(com.github.javaparser.ast.type.UnknownType.class);
|
||||
add(com.github.javaparser.ast.type.VarType.class);
|
||||
add(com.github.javaparser.ast.type.VoidType.class);
|
||||
add(com.github.javaparser.ast.type.WildcardType.class);
|
||||
|
||||
add(com.github.javaparser.ast.modules.ModuleExportsDirective.class);
|
||||
add(com.github.javaparser.ast.modules.ModuleOpensDirective.class);
|
||||
add(com.github.javaparser.ast.modules.ModuleProvidesDirective.class);
|
||||
add(com.github.javaparser.ast.modules.ModuleRequiresDirective.class);
|
||||
add(com.github.javaparser.ast.modules.ModuleUsesDirective.class);
|
||||
}
|
||||
};
|
||||
|
||||
public MetaModelGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 1) {
|
||||
throw new RuntimeException("Need 1 parameter: the JavaParser source checkout root directory.");
|
||||
}
|
||||
final Path root = Paths.get(args[0], "..", "javaparser-core", "src", "main", "java");
|
||||
final ParserConfiguration parserConfiguration = new ParserConfiguration()
|
||||
.setLanguageLevel(ParserConfiguration.LanguageLevel.RAW)
|
||||
.setStoreTokens(false);
|
||||
final SourceRoot sourceRoot = new SourceRoot(root, parserConfiguration);
|
||||
PrinterConfiguration config = new DefaultPrinterConfiguration()
|
||||
.addOption(new DefaultConfigurationOption(ConfigOption.END_OF_LINE_CHARACTER, ("\n")));
|
||||
Printer printer = new DefaultPrettyPrinter(config);
|
||||
sourceRoot.setPrinter(printer::print);
|
||||
StaticJavaParser.setConfiguration(parserConfiguration);
|
||||
|
||||
new MetaModelGenerator(sourceRoot).generate();
|
||||
|
||||
sourceRoot.saveAll();
|
||||
}
|
||||
|
||||
public void generate() throws Exception {
|
||||
final CompilationUnit javaParserMetaModelCu = sourceRoot.parse(METAMODEL_PACKAGE, "JavaParserMetaModel.java");
|
||||
javaParserMetaModelCu.setBlockComment(COPYRIGHT_NOTICE_JP_CORE);
|
||||
|
||||
generateNodeMetaModels(javaParserMetaModelCu, sourceRoot);
|
||||
}
|
||||
|
||||
private void generateNodeMetaModels(CompilationUnit javaParserMetaModelCu, SourceRoot sourceRoot)
|
||||
throws NoSuchMethodException {
|
||||
final ClassOrInterfaceDeclaration metaModelCoid =
|
||||
javaParserMetaModelCu.getClassByName("JavaParserMetaModel").get();
|
||||
|
||||
// Initialiser methods
|
||||
final MethodDeclaration initializeNodeMetaModelsMethod =
|
||||
metaModelCoid.getMethodsByName("initializeNodeMetaModels").get(0);
|
||||
final MethodDeclaration initializePropertyMetaModelsMethod =
|
||||
metaModelCoid.getMethodsByName("initializePropertyMetaModels").get(0);
|
||||
final MethodDeclaration initializeConstructorParametersVariable = metaModelCoid
|
||||
.getMethodsByName("initializeConstructorParameters")
|
||||
.get(0);
|
||||
|
||||
// Ensure annotation `@Generated` is added to indicate the contents of each are generated.
|
||||
annotateGenerated(initializeNodeMetaModelsMethod);
|
||||
annotateGenerated(initializePropertyMetaModelsMethod);
|
||||
annotateGenerated(initializeConstructorParametersVariable);
|
||||
|
||||
// Empty the body of the initialiser methods, to be (re-)generated below.
|
||||
final NodeList<Statement> initializeNodeMetaModelsStatements =
|
||||
initializeNodeMetaModelsMethod.getBody().get().getStatements();
|
||||
final NodeList<Statement> initializePropertyMetaModelsStatements =
|
||||
initializePropertyMetaModelsMethod.getBody().get().getStatements();
|
||||
final NodeList<Statement> initializeConstructorParametersStatements =
|
||||
initializeConstructorParametersVariable.getBody().get().getStatements();
|
||||
initializeNodeMetaModelsStatements.clear();
|
||||
initializePropertyMetaModelsStatements.clear();
|
||||
initializeConstructorParametersStatements.clear();
|
||||
|
||||
// Remove fields, to be (re-)generated below.
|
||||
metaModelCoid.getFields().stream()
|
||||
.filter(f -> f.getVariable(0).getNameAsString().endsWith("MetaModel"))
|
||||
.forEach(Node::remove);
|
||||
|
||||
// Do the generation of each node metamodel class.
|
||||
final NodeMetaModelGenerator nodeMetaModelGenerator = new NodeMetaModelGenerator(sourceRoot);
|
||||
for (Class<? extends Node> nodeClass : ALL_NODE_CLASSES) {
|
||||
nodeMetaModelGenerator.generate(
|
||||
nodeClass,
|
||||
metaModelCoid,
|
||||
initializeNodeMetaModelsStatements,
|
||||
initializePropertyMetaModelsStatements,
|
||||
initializeConstructorParametersStatements,
|
||||
sourceRoot);
|
||||
}
|
||||
|
||||
// TODO: Document why sorting occurs.
|
||||
initializeNodeMetaModelsStatements.sort(Comparator.comparing(Node::toString));
|
||||
}
|
||||
|
||||
static boolean isNode(Class<?> c) {
|
||||
return Node.class.isAssignableFrom(c);
|
||||
}
|
||||
|
||||
static String nodeMetaModelName(Class<?> c) {
|
||||
return c.getSimpleName() + "MetaModel";
|
||||
}
|
||||
|
||||
static String propertyMetaModelFieldName(Field field) {
|
||||
return field.getName() + "PropertyMetaModel";
|
||||
}
|
||||
|
||||
static String nodeMetaModelFieldName(Class<?> nodeClass) {
|
||||
return decapitalize(nodeMetaModelName(nodeClass));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.generator.metamodel;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.*;
|
||||
import static com.github.javaparser.ast.Modifier.Keyword.*;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.f;
|
||||
import static com.github.javaparser.utils.CodeGenerationUtils.optionalOf;
|
||||
import static com.github.javaparser.utils.Utils.decapitalize;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.body.*;
|
||||
import com.github.javaparser.ast.stmt.Statement;
|
||||
import com.github.javaparser.generator.AbstractGenerator;
|
||||
import com.github.javaparser.metamodel.DerivedProperty;
|
||||
import com.github.javaparser.metamodel.InternalProperty;
|
||||
import com.github.javaparser.utils.SourceRoot;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
public class NodeMetaModelGenerator extends AbstractGenerator {
|
||||
|
||||
private final InitializePropertyMetaModelsStatementsGenerator initializePropertyMetaModelsStatementsGenerator =
|
||||
new InitializePropertyMetaModelsStatementsGenerator();
|
||||
private final InitializeConstructorParametersStatementsGenerator
|
||||
initializeConstructorParametersStatementsGenerator =
|
||||
new InitializeConstructorParametersStatementsGenerator();
|
||||
|
||||
public static final String GENERATED_CLASS_COMMENT =
|
||||
"" + "This file, class, and its contents are completely generated based on:"
|
||||
+ "\n<ul>"
|
||||
+ "\n <li>The contents and annotations within the package `com.github.javaparser.ast`, and</li>"
|
||||
+ "\n <li>`ALL_NODE_CLASSES` within the class `com.github.javaparser.generator.metamodel.MetaModelGenerator`.</li>"
|
||||
+ "\n</ul>"
|
||||
+ "\n"
|
||||
+ "\nFor this reason, any changes made directly to this file will be overwritten the next time generators are run."
|
||||
+ "";
|
||||
|
||||
private static final String GENERATED_JAVADOC_COMMENT =
|
||||
"Warning: The content of this class is partially or completely generated - manual edits risk being overwritten.";
|
||||
|
||||
protected NodeMetaModelGenerator(SourceRoot sourceRoot) {
|
||||
super(sourceRoot);
|
||||
}
|
||||
|
||||
public void generate(
|
||||
Class<? extends Node> nodeClass,
|
||||
ClassOrInterfaceDeclaration metaModelCoid,
|
||||
NodeList<Statement> initializeNodeMetaModelsStatements,
|
||||
NodeList<Statement> initializePropertyMetaModelsStatements,
|
||||
NodeList<Statement> initializeConstructorParametersStatements,
|
||||
SourceRoot sourceRoot)
|
||||
throws NoSuchMethodException {
|
||||
metaModelCoid.setJavadocComment(GENERATED_JAVADOC_COMMENT);
|
||||
|
||||
final AstTypeAnalysis typeAnalysis = new AstTypeAnalysis(nodeClass);
|
||||
|
||||
final String className = MetaModelGenerator.nodeMetaModelName(nodeClass);
|
||||
final String nodeMetaModelFieldName = decapitalize(className);
|
||||
metaModelCoid.getFieldByName(nodeMetaModelFieldName).ifPresent(Node::remove);
|
||||
|
||||
initializeNodeMetaModelsStatements.add(parseStatement(f("nodeMetaModels.add(%s);", nodeMetaModelFieldName)));
|
||||
this.initializeConstructorParametersStatementsGenerator.generate(
|
||||
nodeClass, initializeConstructorParametersStatements);
|
||||
|
||||
final Class<?> superclass = nodeClass.getSuperclass();
|
||||
final String superNodeMetaModel = MetaModelGenerator.nodeMetaModelName(superclass);
|
||||
final boolean isRootNode = !MetaModelGenerator.isNode(superclass);
|
||||
|
||||
final FieldDeclaration nodeField =
|
||||
metaModelCoid.addField(className, nodeMetaModelFieldName, PUBLIC, STATIC, FINAL);
|
||||
annotateGenerated(nodeField);
|
||||
nodeField
|
||||
.getVariable(0)
|
||||
.setInitializer(parseExpression(
|
||||
f("new %s(%s)", className, optionalOf(decapitalize(superNodeMetaModel), !isRootNode))));
|
||||
|
||||
// The node-specific metamodel file
|
||||
final CompilationUnit classMetaModelJavaFile = new CompilationUnit(MetaModelGenerator.METAMODEL_PACKAGE);
|
||||
classMetaModelJavaFile.setBlockComment(COPYRIGHT_NOTICE_JP_CORE);
|
||||
classMetaModelJavaFile.addImport(Optional.class);
|
||||
classMetaModelJavaFile.addImport(nodeClass);
|
||||
|
||||
//
|
||||
final ClassOrInterfaceDeclaration nodeMetaModelClass = classMetaModelJavaFile.addClass(className, PUBLIC);
|
||||
annotateGenerated(nodeMetaModelClass);
|
||||
nodeMetaModelClass.setJavadocComment(GENERATED_CLASS_COMMENT);
|
||||
|
||||
if (isRootNode) {
|
||||
nodeMetaModelClass.addExtendedType(MetaModelGenerator.BASE_NODE_META_MODEL);
|
||||
} else {
|
||||
nodeMetaModelClass.addExtendedType(superNodeMetaModel);
|
||||
}
|
||||
|
||||
// Constructors
|
||||
final ConstructorDeclaration classMMConstructor = nodeMetaModelClass
|
||||
.addConstructor()
|
||||
.addParameter(
|
||||
f("Optional<%s>", MetaModelGenerator.BASE_NODE_META_MODEL),
|
||||
f("super%s", MetaModelGenerator.BASE_NODE_META_MODEL));
|
||||
classMMConstructor
|
||||
.getBody()
|
||||
.addStatement(parseExplicitConstructorInvocationStmt(f(
|
||||
"super(super%s, %s.class, \"%s\", \"%s\", %s, %s);",
|
||||
MetaModelGenerator.BASE_NODE_META_MODEL,
|
||||
nodeClass.getSimpleName(),
|
||||
nodeClass.getSimpleName(),
|
||||
nodeClass.getPackage().getName(),
|
||||
typeAnalysis.isAbstract,
|
||||
typeAnalysis.isSelfType)));
|
||||
annotateGenerated(classMMConstructor);
|
||||
|
||||
// ?Abstract protected constructor?
|
||||
if (typeAnalysis.isAbstract) {
|
||||
classMetaModelJavaFile.addImport(Node.class);
|
||||
BodyDeclaration<?> bodyDeclaration = parseBodyDeclaration(f(
|
||||
"protected %s(Optional<%s> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {"
|
||||
+ "super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);"
|
||||
+ " }",
|
||||
className, MetaModelGenerator.BASE_NODE_META_MODEL));
|
||||
annotateGenerated(bodyDeclaration);
|
||||
nodeMetaModelClass.addMember(bodyDeclaration);
|
||||
}
|
||||
|
||||
// Fields, sorted by name.
|
||||
final List<Field> fields = new ArrayList<>(Arrays.asList(nodeClass.getDeclaredFields()));
|
||||
fields.sort(Comparator.comparing(Field::getName));
|
||||
for (Field field : fields) {
|
||||
if (this.fieldShouldBeIgnored(field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.initializePropertyMetaModelsStatementsGenerator.generate(
|
||||
field, nodeMetaModelClass, nodeMetaModelFieldName, initializePropertyMetaModelsStatements);
|
||||
}
|
||||
|
||||
// Methods, sorted by name.
|
||||
final List<Method> methods = new ArrayList<>(Arrays.asList(nodeClass.getMethods()));
|
||||
methods.sort(Comparator.comparing(Method::getName));
|
||||
for (Method method : methods) {
|
||||
if (method.isAnnotationPresent(DerivedProperty.class)) {
|
||||
this.initializePropertyMetaModelsStatementsGenerator.generateDerivedProperty(
|
||||
method, nodeMetaModelClass, nodeMetaModelFieldName, initializePropertyMetaModelsStatements);
|
||||
}
|
||||
}
|
||||
|
||||
this.moveStaticInitializeToTheEndOfTheClassBecauseWeNeedTheFieldsToInitializeFirst(metaModelCoid);
|
||||
|
||||
// Add the file to the source root, enabling it to be saved later.
|
||||
sourceRoot.add(MetaModelGenerator.METAMODEL_PACKAGE, className + ".java", classMetaModelJavaFile);
|
||||
}
|
||||
|
||||
private void moveStaticInitializeToTheEndOfTheClassBecauseWeNeedTheFieldsToInitializeFirst(
|
||||
ClassOrInterfaceDeclaration metaModelCoid) {
|
||||
for (BodyDeclaration<?> m : metaModelCoid.getMembers()) {
|
||||
if (m instanceof InitializerDeclaration) {
|
||||
m.remove();
|
||||
metaModelCoid.addMember(m);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean fieldShouldBeIgnored(Field reflectionField) {
|
||||
return java.lang.reflect.Modifier.isStatic(reflectionField.getModifiers())
|
||||
|| reflectionField.isAnnotationPresent(InternalProperty.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>javaparser-parent</artifactId>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<version>3.27.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>javaparser-core-serialization</artifactId>
|
||||
<description>Serializers for the JavaParser AST.</description>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU Lesser General Public License</name>
|
||||
<url>http://www.gnu.org/licenses/lgpl-3.0.html</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
<comments>A business-friendly OSS license</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Automatic-Module-Name>com.github.javaparser.core.serialization</Automatic-Module-Name>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<artifactId>javaparser-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.json</groupId>
|
||||
<artifactId>jakarta.json-api</artifactId>
|
||||
<version>2.1.3</version>
|
||||
</dependency>
|
||||
<!-- The jakarta.json variant of Glassfish is now available under a new name, Eclipse Parsson -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.parsson</groupId>
|
||||
<artifactId>parsson</artifactId>
|
||||
<version>1.1.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
package com.github.javaparser.serialization;
|
||||
|
||||
import static com.github.javaparser.ast.NodeList.toNodeList;
|
||||
import static com.github.javaparser.metamodel.JavaParserMetaModel.getNodeMetaModel;
|
||||
import static com.github.javaparser.serialization.JavaParserJsonSerializer.*;
|
||||
|
||||
import com.github.javaparser.*;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.comments.Comment;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.Log;
|
||||
import jakarta.json.JsonArray;
|
||||
import jakarta.json.JsonObject;
|
||||
import jakarta.json.JsonReader;
|
||||
import jakarta.json.JsonValue;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Deserializes the JSON file that was built by {@link JavaParserJsonSerializer}.
|
||||
*/
|
||||
public class JavaParserJsonDeserializer {
|
||||
/**
|
||||
* Deserializes json, contained by JsonReader, into AST node.
|
||||
* The root node and all its child nodes will be deserialized.
|
||||
* @param reader json-p reader (object-level reader, <a href="https://javaee.github.io/jsonp/">see their docs</a>)
|
||||
* @return the root level deserialized node
|
||||
*/
|
||||
public Node deserializeObject(JsonReader reader) {
|
||||
Log.info("Deserializing JSON to Node.");
|
||||
JsonObject jsonObject = reader.readObject();
|
||||
return deserializeObject(jsonObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive depth-first deserializing method that creates a Node instance from JsonObject.
|
||||
*
|
||||
* @param nodeJson json object at current level containg values as properties
|
||||
* @return deserialized node including all children.
|
||||
* @implNote the Node instance will be constructed by the properties defined in the meta model.
|
||||
* Non meta properties will be set after Node is instantiated.
|
||||
* @implNote comment is included in the propertyKey meta model, but not set when constructing the Node instance.
|
||||
* That is, comment is not included in the constructor propertyKey list, and therefore needs to be set
|
||||
* after constructing the node.
|
||||
* See {@link com.github.javaparser.metamodel.BaseNodeMetaModel#construct(Map)} how the node is contructed
|
||||
*/
|
||||
private Node deserializeObject(JsonObject nodeJson) {
|
||||
try {
|
||||
String serializedNodeType = nodeJson.getString(JsonNode.CLASS.propertyKey);
|
||||
BaseNodeMetaModel nodeMetaModel = getNodeMetaModel(Class.forName(serializedNodeType))
|
||||
.orElseThrow(() -> new IllegalStateException(
|
||||
"Trying to deserialize an unknown node type: " + serializedNodeType));
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
Map<String, JsonValue> deferredJsonValues = new HashMap<>();
|
||||
|
||||
for (String name : nodeJson.keySet()) {
|
||||
if (name.equals(JsonNode.CLASS.propertyKey)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Optional<PropertyMetaModel> optionalPropertyMetaModel =
|
||||
nodeMetaModel.getAllPropertyMetaModels().stream()
|
||||
.filter(mm -> mm.getName().equals(name))
|
||||
.findFirst();
|
||||
if (!optionalPropertyMetaModel.isPresent()) {
|
||||
deferredJsonValues.put(name, nodeJson.get(name));
|
||||
continue;
|
||||
}
|
||||
|
||||
PropertyMetaModel propertyMetaModel = optionalPropertyMetaModel.get();
|
||||
if (propertyMetaModel.isNodeList()) {
|
||||
JsonArray nodeListJson = nodeJson.getJsonArray(name);
|
||||
parameters.put(name, deserializeNodeList(nodeListJson));
|
||||
} else if (propertyMetaModel.isNode()) {
|
||||
parameters.put(name, deserializeObject(nodeJson.getJsonObject(name)));
|
||||
} else {
|
||||
Class<?> type = propertyMetaModel.getType();
|
||||
if (type == String.class) {
|
||||
parameters.put(name, nodeJson.getString(name));
|
||||
} else if (type == boolean.class) {
|
||||
parameters.put(name, Boolean.parseBoolean(nodeJson.getString(name)));
|
||||
} else if (Enum.class.isAssignableFrom(type)) {
|
||||
parameters.put(name, Enum.valueOf((Class<? extends Enum>) type, nodeJson.getString(name)));
|
||||
} else {
|
||||
throw new IllegalStateException("Don't know how to convert: " + type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Node node = nodeMetaModel.construct(parameters);
|
||||
// COMMENT is in the propertyKey meta model, but not required as constructor parameter.
|
||||
// Set it after construction
|
||||
if (parameters.containsKey(JsonNode.COMMENT.propertyKey)) {
|
||||
node.setComment((Comment) parameters.get(JsonNode.COMMENT.propertyKey));
|
||||
}
|
||||
|
||||
for (String name : deferredJsonValues.keySet()) {
|
||||
if (!readNonMetaProperties(name, deferredJsonValues.get(name), node)) {
|
||||
throw new IllegalStateException(
|
||||
"Unknown propertyKey: " + nodeMetaModel.getQualifiedClassName() + "." + name);
|
||||
}
|
||||
}
|
||||
setSymbolResolverIfCompilationUnit(node);
|
||||
|
||||
return node;
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private NodeList<?> deserializeNodeList(JsonArray nodeListJson) {
|
||||
return nodeListJson.stream()
|
||||
.map(nodeJson -> deserializeObject((JsonObject) nodeJson))
|
||||
.collect(toNodeList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads properties from json not included in meta model (i.e., RANGE and TOKEN_RANGE).
|
||||
* When read, it sets the deserialized value to the node instance.
|
||||
* @param name propertyKey name for json value
|
||||
* @param jsonValue json value that needs to be deserialized for this propertyKey
|
||||
* @param node instance to which the deserialized value will be set to
|
||||
* @return true if propertyKey is read from json and set to Node instance
|
||||
*/
|
||||
protected boolean readNonMetaProperties(String name, JsonValue jsonValue, Node node) {
|
||||
return readRange(name, jsonValue, node) || readTokenRange(name, jsonValue, node);
|
||||
}
|
||||
|
||||
protected boolean readRange(String name, JsonValue jsonValue, Node node) {
|
||||
if (name.equals(JsonNode.RANGE.propertyKey)) {
|
||||
JsonObject jsonObject = (JsonObject) jsonValue;
|
||||
Position begin = new Position(
|
||||
jsonObject.getInt(JsonRange.BEGIN_LINE.propertyKey),
|
||||
jsonObject.getInt(JsonRange.BEGIN_COLUMN.propertyKey));
|
||||
Position end = new Position(
|
||||
jsonObject.getInt(JsonRange.END_LINE.propertyKey),
|
||||
jsonObject.getInt(JsonRange.END_COLUMN.propertyKey));
|
||||
node.setRange(new Range(begin, end));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean readTokenRange(String name, JsonValue jsonValue, Node node) {
|
||||
if (name.equals(JsonNode.TOKEN_RANGE.propertyKey)) {
|
||||
JsonObject jsonObject = (JsonObject) jsonValue;
|
||||
JavaToken begin = readToken(JsonTokenRange.BEGIN_TOKEN.propertyKey, jsonObject);
|
||||
JavaToken end = readToken(JsonTokenRange.END_TOKEN.propertyKey, jsonObject);
|
||||
node.setTokenRange(new TokenRange(begin, end));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected JavaToken readToken(String name, JsonObject jsonObject) {
|
||||
JsonObject tokenJson = jsonObject.getJsonObject(name);
|
||||
return new JavaToken(
|
||||
tokenJson.getInt(JsonToken.KIND.propertyKey), tokenJson.getString(JsonToken.TEXT.propertyKey));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets symbol resolver to Node if it is an instance of CompilationUnit
|
||||
* and a SymbolResolver is configured in the static configuration. This is necessary to be able to resolve symbols
|
||||
* within the cu after deserialization. Normally, when parsing java with JavaParser, the symbol resolver is injected
|
||||
* to the cu as a data element with key SYMBOL_RESOLVER_KEY.
|
||||
* @param node instance to which symbol resolver will be set to when instance of a Compilation Unit
|
||||
* @see com.github.javaparser.ast.Node#SYMBOL_RESOLVER_KEY
|
||||
* @see com.github.javaparser.ParserConfiguration#ParserConfiguration()
|
||||
*/
|
||||
private void setSymbolResolverIfCompilationUnit(Node node) {
|
||||
if (node instanceof CompilationUnit
|
||||
&& StaticJavaParser.getConfiguration().getSymbolResolver().isPresent()) {
|
||||
CompilationUnit cu = (CompilationUnit) node;
|
||||
cu.setData(
|
||||
Node.SYMBOL_RESOLVER_KEY,
|
||||
StaticJavaParser.getConfiguration().getSymbolResolver().get());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
package com.github.javaparser.serialization;
|
||||
|
||||
import static com.github.javaparser.utils.Utils.decapitalize;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import com.github.javaparser.JavaToken;
|
||||
import com.github.javaparser.Range;
|
||||
import com.github.javaparser.TokenRange;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.metamodel.BaseNodeMetaModel;
|
||||
import com.github.javaparser.metamodel.JavaParserMetaModel;
|
||||
import com.github.javaparser.metamodel.PropertyMetaModel;
|
||||
import com.github.javaparser.utils.Log;
|
||||
import jakarta.json.stream.JsonGenerator;
|
||||
|
||||
/**
|
||||
* Serializes an AST or a partial AST to JSON.
|
||||
*/
|
||||
public class JavaParserJsonSerializer {
|
||||
|
||||
/**
|
||||
* Serializes node and all its children into json. Any node siblings will be ignored.
|
||||
*
|
||||
* @param node the node that will be the root level json object
|
||||
* @param generator the json-p generator for writing the json
|
||||
* @see <a href="https://javaee.github.io/jsonp/">json-p</a>
|
||||
*/
|
||||
public void serialize(Node node, JsonGenerator generator) {
|
||||
requireNonNull(node);
|
||||
Log.info("Serializing Node to JSON.");
|
||||
try {
|
||||
serialize(null, node, generator);
|
||||
} finally {
|
||||
generator.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive depth-first method that serializes nodes into json
|
||||
*
|
||||
* @param nodeName nullable String. If null, it is the root object, otherwise it is the property key for the object
|
||||
* @param node the current node to be serialized
|
||||
* @param generator the json-p generator for writing the json
|
||||
*/
|
||||
private void serialize(String nodeName, Node node, JsonGenerator generator) {
|
||||
requireNonNull(node);
|
||||
BaseNodeMetaModel nodeMetaModel = JavaParserMetaModel.getNodeMetaModel(node.getClass())
|
||||
.orElseThrow(() -> new IllegalStateException("Unknown Node: " + node.getClass()));
|
||||
|
||||
if (nodeName == null) {
|
||||
generator.writeStartObject();
|
||||
} else {
|
||||
generator.writeStartObject(nodeName);
|
||||
}
|
||||
generator.write(JsonNode.CLASS.propertyKey, node.getClass().getName());
|
||||
this.writeNonMetaProperties(node, generator);
|
||||
for (PropertyMetaModel propertyMetaModel : nodeMetaModel.getAllPropertyMetaModels()) {
|
||||
String name = propertyMetaModel.getName();
|
||||
Object value = propertyMetaModel.getValue(node);
|
||||
if (value != null) {
|
||||
if (propertyMetaModel.isNodeList()) {
|
||||
NodeList<Node> list = (NodeList<Node>) value;
|
||||
generator.writeStartArray(name);
|
||||
for (Node n : list) {
|
||||
serialize(null, n, generator);
|
||||
}
|
||||
generator.writeEnd();
|
||||
} else if (propertyMetaModel.isNode()) {
|
||||
serialize(name, (Node) value, generator);
|
||||
} else {
|
||||
generator.write(name, value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
generator.writeEnd();
|
||||
}
|
||||
|
||||
/***
|
||||
* This method writes json for properties not included in meta model (i.e., RANGE and TOKEN_RANGE).
|
||||
* This method could be overriden so that - for example - tokens are not written to json to save space
|
||||
*
|
||||
* @see com.github.javaparser.metamodel.BaseNodeMetaModel#getAllPropertyMetaModels()
|
||||
*/
|
||||
protected void writeNonMetaProperties(Node node, JsonGenerator generator) {
|
||||
this.writeRange(node, generator);
|
||||
this.writeTokens(node, generator);
|
||||
}
|
||||
|
||||
protected void writeRange(Node node, JsonGenerator generator) {
|
||||
if (node.hasRange()) {
|
||||
Range range = node.getRange().get();
|
||||
generator.writeStartObject(JsonNode.RANGE.propertyKey);
|
||||
generator.write(JsonRange.BEGIN_LINE.propertyKey, range.begin.line);
|
||||
generator.write(JsonRange.BEGIN_COLUMN.propertyKey, range.begin.column);
|
||||
generator.write(JsonRange.END_LINE.propertyKey, range.end.line);
|
||||
generator.write(JsonRange.END_COLUMN.propertyKey, range.end.column);
|
||||
generator.writeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeTokens(Node node, JsonGenerator generator) {
|
||||
if (node.getTokenRange().isPresent()) {
|
||||
TokenRange tokenRange = node.getTokenRange().get();
|
||||
generator.writeStartObject(JsonNode.TOKEN_RANGE.propertyKey);
|
||||
writeToken(JsonTokenRange.BEGIN_TOKEN.propertyKey, tokenRange.getBegin(), generator);
|
||||
writeToken(JsonTokenRange.END_TOKEN.propertyKey, tokenRange.getEnd(), generator);
|
||||
generator.writeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeToken(String name, JavaToken token, JsonGenerator generator) {
|
||||
generator.writeStartObject(name);
|
||||
generator.write(JsonToken.KIND.propertyKey, token.getKind());
|
||||
generator.write(JsonToken.TEXT.propertyKey, token.getText());
|
||||
generator.writeEnd();
|
||||
}
|
||||
|
||||
/**
|
||||
* excludes properties from meta model (except comment)
|
||||
**/
|
||||
public enum JsonNode {
|
||||
RANGE("range"),
|
||||
TOKEN_RANGE("tokenRange"),
|
||||
COMMENT(decapitalize(JavaParserMetaModel.commentMetaModel.getTypeName())),
|
||||
CLASS("!");
|
||||
final String propertyKey;
|
||||
|
||||
JsonNode(String p) {
|
||||
this.propertyKey = p;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.propertyKey;
|
||||
}
|
||||
}
|
||||
|
||||
public enum JsonRange {
|
||||
BEGIN_LINE("beginLine"),
|
||||
BEGIN_COLUMN("beginColumn"),
|
||||
END_LINE("endLine"),
|
||||
END_COLUMN("endColumn");
|
||||
final String propertyKey;
|
||||
|
||||
JsonRange(String p) {
|
||||
this.propertyKey = p;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.propertyKey;
|
||||
}
|
||||
}
|
||||
|
||||
public enum JsonTokenRange {
|
||||
BEGIN_TOKEN("beginToken"),
|
||||
END_TOKEN("endToken");
|
||||
final String propertyKey;
|
||||
|
||||
JsonTokenRange(String p) {
|
||||
this.propertyKey = p;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.propertyKey;
|
||||
}
|
||||
}
|
||||
|
||||
public enum JsonToken {
|
||||
TEXT("text"),
|
||||
KIND("kind");
|
||||
final String propertyKey;
|
||||
|
||||
JsonToken(String p) {
|
||||
this.propertyKey = p;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.propertyKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
package com.github.javaparser.serialization;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.*;
|
||||
import static com.github.javaparser.serialization.JavaParserJsonSerializerTest.serialize;
|
||||
import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.github.javaparser.ParserConfiguration;
|
||||
import com.github.javaparser.Range;
|
||||
import com.github.javaparser.StaticJavaParser;
|
||||
import com.github.javaparser.TokenRange;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.comments.Comment;
|
||||
import com.github.javaparser.ast.expr.Expression;
|
||||
import com.github.javaparser.ast.type.Type;
|
||||
import com.github.javaparser.javadoc.Javadoc;
|
||||
import com.github.javaparser.javadoc.JavadocBlockTag;
|
||||
import com.github.javaparser.resolution.SymbolResolver;
|
||||
import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
|
||||
import com.github.javaparser.resolution.types.ResolvedType;
|
||||
import com.github.javaparser.utils.LineSeparator;
|
||||
import jakarta.json.Json;
|
||||
import java.io.StringReader;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class JavaParserJsonDeserializerTest {
|
||||
private final JavaParserJsonDeserializer deserializer = new JavaParserJsonDeserializer();
|
||||
|
||||
@Test
|
||||
void simpleTest() {
|
||||
CompilationUnit cu = parse("public class X{} class Z{}");
|
||||
String serialized = serialize(cu, false);
|
||||
|
||||
Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
|
||||
assertEqualsStringIgnoringEol("public class X {\n}\n\nclass Z {\n}\n", deserialized.toString());
|
||||
assertEquals(cu.hashCode(), deserialized.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRawType() {
|
||||
Type type = parseType("Blub");
|
||||
String serialized = serialize(type, false);
|
||||
|
||||
Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
|
||||
assertEqualsStringIgnoringEol("Blub", deserialized.toString());
|
||||
assertEquals(type.hashCode(), deserialized.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDiamondType() {
|
||||
Type type = parseType("Blub<>");
|
||||
String serialized = serialize(type, false);
|
||||
|
||||
Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
|
||||
assertEqualsStringIgnoringEol("Blub<>", deserialized.toString());
|
||||
assertEquals(type.hashCode(), deserialized.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerics() {
|
||||
Type type = parseType("Blub<Blab, Bleb>");
|
||||
String serialized = serialize(type, false);
|
||||
|
||||
Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
|
||||
assertEqualsStringIgnoringEol("Blub<Blab, Bleb>", deserialized.toString());
|
||||
assertEquals(type.hashCode(), deserialized.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOperator() {
|
||||
Expression expr = parseExpression("1+1");
|
||||
String serialized = serialize(expr, false);
|
||||
|
||||
Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
|
||||
assertEqualsStringIgnoringEol("1 + 1", deserialized.toString());
|
||||
assertEquals(expr.hashCode(), deserialized.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPrimitiveType() {
|
||||
Type type = parseType("int");
|
||||
String serialized = serialize(type, false);
|
||||
|
||||
Node deserialized = deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
|
||||
assertEqualsStringIgnoringEol("int", deserialized.toString());
|
||||
assertEquals(type.hashCode(), deserialized.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComment() {
|
||||
CompilationUnit cu = parse("/* block comment */\npublic class X{ \n // line comment\npublic void test() {}\n}");
|
||||
String serialized = serialize(cu, false);
|
||||
|
||||
CompilationUnit deserialized =
|
||||
(CompilationUnit) deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
ClassOrInterfaceDeclaration classXDeclaration =
|
||||
deserialized.getClassByName("X").get();
|
||||
assertTrue(classXDeclaration.getComment().isPresent());
|
||||
|
||||
Comment comment = classXDeclaration.getComment().get();
|
||||
assertEquals(
|
||||
"com.github.javaparser.ast.comments.BlockComment",
|
||||
comment.getClass().getName());
|
||||
assertEquals(" block comment ", comment.getContent());
|
||||
|
||||
MethodDeclaration methodDeclaration = classXDeclaration.getMethods().get(0);
|
||||
assertTrue(methodDeclaration.getComment().isPresent());
|
||||
assertEquals(
|
||||
"com.github.javaparser.ast.comments.LineComment",
|
||||
methodDeclaration.getComment().get().getClass().getName());
|
||||
assertEquals(" line comment", methodDeclaration.getComment().get().getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJavaDocComment() {
|
||||
CompilationUnit cu = parse("public class X{ " + " /**\n"
|
||||
+ " * Woke text.\n"
|
||||
+ " * @param a blub\n"
|
||||
+ " * @return true \n"
|
||||
+ " */"
|
||||
+ " public boolean test(int a) { return true; }\n"
|
||||
+ "}");
|
||||
String serialized = serialize(cu, false);
|
||||
|
||||
CompilationUnit deserialized =
|
||||
(CompilationUnit) deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
ClassOrInterfaceDeclaration classDeclaration =
|
||||
deserialized.getClassByName("X").get();
|
||||
MethodDeclaration methodDeclaration = classDeclaration.getMethods().get(0);
|
||||
assertTrue(methodDeclaration.getJavadoc().isPresent());
|
||||
Javadoc javadoc = methodDeclaration.getJavadoc().get();
|
||||
|
||||
JavadocBlockTag paramBlockTag = javadoc.getBlockTags().get(0);
|
||||
assertEquals("param", paramBlockTag.getTagName());
|
||||
assertEquals("blub", paramBlockTag.getContent().toText());
|
||||
|
||||
JavadocBlockTag returnBlockTag = javadoc.getBlockTags().get(1);
|
||||
assertEquals("return", returnBlockTag.getTagName());
|
||||
assertEquals("true", returnBlockTag.getContent().toText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNonMetaProperties() {
|
||||
CompilationUnit cu = parse("public class X{} class Z{}");
|
||||
String serialized = serialize(cu, false);
|
||||
|
||||
CompilationUnit deserialized =
|
||||
(CompilationUnit) deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
|
||||
assertTrue(deserialized.hasRange());
|
||||
Range range = deserialized.getRange().get();
|
||||
assertEquals(1, range.begin.line);
|
||||
assertEquals(1, range.begin.line);
|
||||
assertEquals(26, range.end.column);
|
||||
|
||||
assertTrue(deserialized.getTokenRange().isPresent());
|
||||
TokenRange tokenRange = deserialized.getTokenRange().get();
|
||||
assertEquals("public", tokenRange.getBegin().getText());
|
||||
assertEquals("", tokenRange.getEnd().getText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAttachingSymbolResolver() {
|
||||
SymbolResolver stubResolver = new SymbolResolver() {
|
||||
@Override
|
||||
public <T> T resolveDeclaration(Node node, Class<T> resultClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T toResolvedType(Type javaparserType, Class<T> resultClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResolvedType calculateType(Expression expression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResolvedReferenceTypeDeclaration toTypeDeclaration(Node node) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
StaticJavaParser.getConfiguration().setSymbolResolver(stubResolver);
|
||||
CompilationUnit cu = parse("public class X{} class Z{}");
|
||||
String serialized = serialize(cu, false);
|
||||
|
||||
CompilationUnit deserialized =
|
||||
(CompilationUnit) deserializer.deserializeObject(Json.createReader(new StringReader(serialized)));
|
||||
assertTrue(deserialized.containsData(Node.SYMBOL_RESOLVER_KEY));
|
||||
assertEquals(stubResolver, deserialized.getData(Node.SYMBOL_RESOLVER_KEY));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void clearConfiguration() {
|
||||
StaticJavaParser.setConfiguration(new ParserConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that "actual" equals "expected", and that any EOL characters in "actual" are correct for the platform.
|
||||
*/
|
||||
private static void assertEqualsStringIgnoringEol(String expected, String actual) {
|
||||
assertEquals(
|
||||
normalizeEolInTextBlock(expected, LineSeparator.ARBITRARY),
|
||||
normalizeEolInTextBlock(actual, LineSeparator.ARBITRARY));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
package com.github.javaparser.serialization;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parse;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import jakarta.json.Json;
|
||||
import jakarta.json.stream.JsonGenerator;
|
||||
import jakarta.json.stream.JsonGeneratorFactory;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class JavaParserJsonSerializerTest {
|
||||
@Test
|
||||
void test() {
|
||||
CompilationUnit cu = parse("class X{java.util.Y y;}");
|
||||
|
||||
String serialized = serialize(cu, false);
|
||||
|
||||
assertEquals(
|
||||
"{\"!\":\"com.github.javaparser.ast.CompilationUnit\",\"range\":{\"beginLine\":1,\"beginColumn\":1,\"endLine\":1,\"endColumn\":23},\"tokenRange\":{\"beginToken\":{\"kind\":19,\"text\":\"class\"},\"endToken\":{\"kind\":0,\"text\":\"\"}},\"imports\":[],\"types\":[{\"!\":\"com.github.javaparser.ast.body.ClassOrInterfaceDeclaration\",\"range\":{\"beginLine\":1,\"beginColumn\":1,\"endLine\":1,\"endColumn\":23},\"tokenRange\":{\"beginToken\":{\"kind\":19,\"text\":\"class\"},\"endToken\":{\"kind\":104,\"text\":\"}\"}},\"extendedTypes\":[],\"implementedTypes\":[],\"isInterface\":\"false\",\"permittedTypes\":[],\"typeParameters\":[],\"members\":[{\"!\":\"com.github.javaparser.ast.body.FieldDeclaration\",\"range\":{\"beginLine\":1,\"beginColumn\":9,\"endLine\":1,\"endColumn\":22},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"java\"},\"endToken\":{\"kind\":107,\"text\":\";\"}},\"modifiers\":[],\"variables\":[{\"!\":\"com.github.javaparser.ast.body.VariableDeclarator\",\"range\":{\"beginLine\":1,\"beginColumn\":21,\"endLine\":1,\"endColumn\":21},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"y\"},\"endToken\":{\"kind\":98,\"text\":\"y\"}},\"name\":{\"!\":\"com.github.javaparser.ast.expr.SimpleName\",\"range\":{\"beginLine\":1,\"beginColumn\":21,\"endLine\":1,\"endColumn\":21},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"y\"},\"endToken\":{\"kind\":98,\"text\":\"y\"}},\"identifier\":\"y\"},\"type\":{\"!\":\"com.github.javaparser.ast.type.ClassOrInterfaceType\",\"range\":{\"beginLine\":1,\"beginColumn\":9,\"endLine\":1,\"endColumn\":19},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"java\"},\"endToken\":{\"kind\":98,\"text\":\"Y\"}},\"name\":{\"!\":\"com.github.javaparser.ast.expr.SimpleName\",\"range\":{\"beginLine\":1,\"beginColumn\":19,\"endLine\":1,\"endColumn\":19},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"Y\"},\"endToken\":{\"kind\":98,\"text\":\"Y\"}},\"identifier\":\"Y\"},\"scope\":{\"!\":\"com.github.javaparser.ast.type.ClassOrInterfaceType\",\"range\":{\"beginLine\":1,\"beginColumn\":9,\"endLine\":1,\"endColumn\":17},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"java\"},\"endToken\":{\"kind\":98,\"text\":\"util\"}},\"name\":{\"!\":\"com.github.javaparser.ast.expr.SimpleName\",\"range\":{\"beginLine\":1,\"beginColumn\":14,\"endLine\":1,\"endColumn\":17},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"util\"},\"endToken\":{\"kind\":98,\"text\":\"util\"}},\"identifier\":\"util\"},\"scope\":{\"!\":\"com.github.javaparser.ast.type.ClassOrInterfaceType\",\"range\":{\"beginLine\":1,\"beginColumn\":9,\"endLine\":1,\"endColumn\":12},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"java\"},\"endToken\":{\"kind\":98,\"text\":\"java\"}},\"name\":{\"!\":\"com.github.javaparser.ast.expr.SimpleName\",\"range\":{\"beginLine\":1,\"beginColumn\":9,\"endLine\":1,\"endColumn\":12},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"java\"},\"endToken\":{\"kind\":98,\"text\":\"java\"}},\"identifier\":\"java\"},\"annotations\":[]},\"annotations\":[]},\"annotations\":[]}}],\"annotations\":[]}],\"modifiers\":[],\"name\":{\"!\":\"com.github.javaparser.ast.expr.SimpleName\",\"range\":{\"beginLine\":1,\"beginColumn\":7,\"endLine\":1,\"endColumn\":7},\"tokenRange\":{\"beginToken\":{\"kind\":98,\"text\":\"X\"},\"endToken\":{\"kind\":98,\"text\":\"X\"}},\"identifier\":\"X\"},\"annotations\":[]}]}",
|
||||
serialized);
|
||||
}
|
||||
|
||||
static String serialize(Node node, boolean prettyPrint) {
|
||||
Map<String, ?> config = new HashMap<>();
|
||||
if (prettyPrint) {
|
||||
config.put(JsonGenerator.PRETTY_PRINTING, null);
|
||||
}
|
||||
JsonGeneratorFactory generatorFactory = Json.createGeneratorFactory(config);
|
||||
JavaParserJsonSerializer serializer = new JavaParserJsonSerializer();
|
||||
StringWriter jsonWriter = new StringWriter();
|
||||
try (JsonGenerator generator = generatorFactory.createGenerator(jsonWriter)) {
|
||||
serializer.serialize(node, generator);
|
||||
}
|
||||
return jsonWriter.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>javaparser-parent</artifactId>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<version>3.27.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>javaparser-core-testing-bdd</artifactId>
|
||||
<description>The BDD test suite for javaparser-core</description>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU Lesser General Public License</name>
|
||||
<url>http://www.gnu.org/licenses/lgpl-3.0.html</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
<license>
|
||||
<name>Apache License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
<comments>A business-friendly OSS license</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- no need to release this module -->
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<reportFormat>plain</reportFormat>
|
||||
<failIfNoTests>true</failIfNoTests>
|
||||
<argLine>@{jacoco.javaagent}</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.javaparser</groupId>
|
||||
<artifactId>javaparser-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jbehave</groupId>
|
||||
<artifactId>jbehave-core</artifactId>
|
||||
<version>5.2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser;
|
||||
|
||||
import static org.jbehave.core.io.CodeLocations.codeLocationFromClass;
|
||||
|
||||
import java.util.List;
|
||||
import org.jbehave.core.configuration.Configuration;
|
||||
import org.jbehave.core.configuration.MostUsefulConfiguration;
|
||||
import org.jbehave.core.failures.FailingUponPendingStep;
|
||||
import org.jbehave.core.io.LoadFromClasspath;
|
||||
import org.jbehave.core.io.StoryFinder;
|
||||
import org.jbehave.core.junit.JUnit4StoryRunner;
|
||||
import org.jbehave.core.junit.JUnitStories;
|
||||
import org.jbehave.core.reporters.Format;
|
||||
import org.jbehave.core.reporters.StoryReporterBuilder;
|
||||
|
||||
abstract class BasicJBehaveTest extends JUnitStories {
|
||||
|
||||
private final String storiesPath;
|
||||
|
||||
BasicJBehaveTest(String storiesPath) {
|
||||
this.storiesPath = storiesPath;
|
||||
JUnit4StoryRunner.recommendedControls(configuredEmbedder());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Configuration configuration() {
|
||||
return new MostUsefulConfiguration()
|
||||
// where to find the stories
|
||||
.useStoryLoader(new LoadFromClasspath(this.getClass()))
|
||||
// Fails if Steps are not implemented
|
||||
.usePendingStepStrategy(new FailingUponPendingStep())
|
||||
// CONSOLE and HTML reporting
|
||||
.useStoryReporterBuilder(
|
||||
new StoryReporterBuilder().withDefaultFormats().withFormats(Format.CONSOLE, Format.HTML));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<String> storyPaths() {
|
||||
return new StoryFinder().findPaths(codeLocationFromClass(this.getClass()), storiesPath, "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser;
|
||||
|
||||
import com.github.javaparser.steps.CommentParsingSteps;
|
||||
import org.jbehave.core.junit.JUnit4StoryRunner;
|
||||
import org.jbehave.core.steps.InjectableStepsFactory;
|
||||
import org.jbehave.core.steps.InstanceStepsFactory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(JUnit4StoryRunner.class)
|
||||
public class CommentParsingTest extends BasicJBehaveTest {
|
||||
|
||||
@Override
|
||||
public InjectableStepsFactory stepsFactory() {
|
||||
return new InstanceStepsFactory(configuration(), new CommentParsingSteps());
|
||||
}
|
||||
|
||||
public CommentParsingTest() {
|
||||
super("**/comment*.story");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser;
|
||||
|
||||
import com.github.javaparser.steps.ComparingSteps;
|
||||
import com.github.javaparser.steps.SharedSteps;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jbehave.core.junit.JUnit4StoryRunner;
|
||||
import org.jbehave.core.steps.InjectableStepsFactory;
|
||||
import org.jbehave.core.steps.InstanceStepsFactory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(JUnit4StoryRunner.class)
|
||||
public class ComparingTest extends BasicJBehaveTest {
|
||||
|
||||
@Override
|
||||
public InjectableStepsFactory stepsFactory() {
|
||||
Map<String, Object> state = new HashMap<>();
|
||||
|
||||
return new InstanceStepsFactory(configuration(), new SharedSteps(state), new ComparingSteps());
|
||||
}
|
||||
|
||||
public ComparingTest() {
|
||||
super("**/comparing*.story");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser;
|
||||
|
||||
import com.github.javaparser.steps.ManipulationSteps;
|
||||
import com.github.javaparser.steps.SharedSteps;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jbehave.core.junit.JUnit4StoryRunner;
|
||||
import org.jbehave.core.steps.InjectableStepsFactory;
|
||||
import org.jbehave.core.steps.InstanceStepsFactory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(JUnit4StoryRunner.class)
|
||||
public class ManipulationTest extends BasicJBehaveTest {
|
||||
|
||||
@Override
|
||||
public InjectableStepsFactory stepsFactory() {
|
||||
Map<String, Object> state = new HashMap<>();
|
||||
|
||||
return new InstanceStepsFactory(configuration(), new SharedSteps(state), new ManipulationSteps(state));
|
||||
}
|
||||
|
||||
public ManipulationTest() {
|
||||
super("**/manipulation*.story");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser;
|
||||
|
||||
import com.github.javaparser.steps.ParsingSteps;
|
||||
import com.github.javaparser.steps.SharedSteps;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jbehave.core.junit.JUnit4StoryRunner;
|
||||
import org.jbehave.core.steps.InjectableStepsFactory;
|
||||
import org.jbehave.core.steps.InstanceStepsFactory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(JUnit4StoryRunner.class)
|
||||
public class ParsingTest extends BasicJBehaveTest {
|
||||
|
||||
@Override
|
||||
public InjectableStepsFactory stepsFactory() {
|
||||
Map<String, Object> state = new HashMap<>();
|
||||
|
||||
return new InstanceStepsFactory(configuration(), new SharedSteps(state), new ParsingSteps(state));
|
||||
}
|
||||
|
||||
public ParsingTest() {
|
||||
super("**/parsing*.story");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser;
|
||||
|
||||
import com.github.javaparser.steps.PositionRangeSteps;
|
||||
import com.github.javaparser.steps.SharedSteps;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jbehave.core.junit.JUnit4StoryRunner;
|
||||
import org.jbehave.core.steps.InjectableStepsFactory;
|
||||
import org.jbehave.core.steps.InstanceStepsFactory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(JUnit4StoryRunner.class)
|
||||
public class PositionRangeTest extends BasicJBehaveTest {
|
||||
|
||||
@Override
|
||||
public InjectableStepsFactory stepsFactory() {
|
||||
Map<String, Object> state = new HashMap<>();
|
||||
|
||||
return new InstanceStepsFactory(configuration(), new SharedSteps(state), new PositionRangeSteps());
|
||||
}
|
||||
|
||||
public PositionRangeTest() {
|
||||
super("**/position_range*.story");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser;
|
||||
|
||||
import com.github.javaparser.steps.PrettyPrintingSteps;
|
||||
import org.jbehave.core.junit.JUnit4StoryRunner;
|
||||
import org.jbehave.core.steps.InjectableStepsFactory;
|
||||
import org.jbehave.core.steps.InstanceStepsFactory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(JUnit4StoryRunner.class)
|
||||
public class PrettyPrintingTest extends BasicJBehaveTest {
|
||||
|
||||
@Override
|
||||
public InjectableStepsFactory stepsFactory() {
|
||||
return new InstanceStepsFactory(configuration(), new PrettyPrintingSteps());
|
||||
}
|
||||
|
||||
public PrettyPrintingTest() {
|
||||
super("**/pretty_printing*.story");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
public static InputStream getSampleStream(String sampleName) {
|
||||
InputStream is = TestUtils.class
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("com/github/javaparser/samples/" + sampleName + ".java");
|
||||
if (is == null) {
|
||||
throw new RuntimeException("Example not found, check your test. Sample name: " + sampleName);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser;
|
||||
|
||||
import com.github.javaparser.steps.SharedSteps;
|
||||
import com.github.javaparser.steps.VisitorSteps;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.jbehave.core.junit.JUnit4StoryRunner;
|
||||
import org.jbehave.core.steps.InjectableStepsFactory;
|
||||
import org.jbehave.core.steps.InstanceStepsFactory;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(JUnit4StoryRunner.class)
|
||||
public class VisitorTest extends BasicJBehaveTest {
|
||||
|
||||
@Override
|
||||
public InjectableStepsFactory stepsFactory() {
|
||||
Map<String, Object> state = new HashMap<>();
|
||||
return new InstanceStepsFactory(configuration(), new SharedSteps(state), new VisitorSteps(state));
|
||||
}
|
||||
|
||||
public VisitorTest() {
|
||||
super("**/visitor*.story");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.steps;
|
||||
|
||||
import static com.github.javaparser.ParseStart.COMPILATION_UNIT;
|
||||
import static com.github.javaparser.Providers.provider;
|
||||
import static com.github.javaparser.Range.range;
|
||||
import static com.github.javaparser.steps.SharedSteps.getMemberByTypeAndPosition;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.text.IsEqualCompressingWhiteSpace.equalToCompressingWhiteSpace;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import com.github.javaparser.*;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.body.*;
|
||||
import com.github.javaparser.ast.comments.*;
|
||||
import com.github.javaparser.ast.expr.Expression;
|
||||
import com.github.javaparser.ast.expr.IntegerLiteralExpr;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.ast.stmt.ExpressionStmt;
|
||||
import com.github.javaparser.ast.type.PrimitiveType;
|
||||
import com.github.javaparser.printer.PrettyPrinter;
|
||||
import com.github.javaparser.printer.Printer;
|
||||
import com.github.javaparser.printer.configuration.PrettyPrinterConfiguration;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import org.jbehave.core.annotations.Alias;
|
||||
import org.jbehave.core.annotations.Given;
|
||||
import org.jbehave.core.annotations.Then;
|
||||
import org.jbehave.core.annotations.When;
|
||||
import org.jbehave.core.model.ExamplesTable;
|
||||
import org.jbehave.core.steps.Parameters;
|
||||
|
||||
public class CommentParsingSteps {
|
||||
|
||||
private CompilationUnit compilationUnit;
|
||||
private CommentsCollection commentsCollection;
|
||||
private String sourceUnderTest;
|
||||
private ParserConfiguration configuration = new ParserConfiguration();
|
||||
private Printer prettyPrinter = new PrettyPrinter(new PrettyPrinterConfiguration());
|
||||
|
||||
@Given("the class:$classSrc")
|
||||
public void givenTheClass(String classSrc) {
|
||||
this.sourceUnderTest = classSrc.trim();
|
||||
}
|
||||
|
||||
@When("read sample \"$sampleName\" using encoding \"$encoding\"")
|
||||
public void givenTheClassWithEncoding(String sampleName, String encoding) {
|
||||
sourceUnderTest = null;
|
||||
ParseResult<CompilationUnit> parseResult = new JavaParser(new ParserConfiguration())
|
||||
.parse(COMPILATION_UNIT, provider(TestUtils.getSampleStream(sampleName), Charset.forName(encoding)));
|
||||
commentsCollection = parseResult.getCommentsCollection().orElse(new CommentsCollection());
|
||||
}
|
||||
|
||||
@When("the class is parsed by the comment parser")
|
||||
public void whenTheClassIsParsedByTheCommentParser() {
|
||||
ParseResult<CompilationUnit> parseResult =
|
||||
new JavaParser(new ParserConfiguration()).parse(COMPILATION_UNIT, provider(sourceUnderTest));
|
||||
commentsCollection = parseResult.getCommentsCollection().orElse(new CommentsCollection());
|
||||
}
|
||||
|
||||
@When("the do not consider annotations as node start for code attribution is $value on the Java parser")
|
||||
public void whenTheDoNotConsiderAnnotationsAsNodeStartForCodeAttributionIsTrueOnTheJavaParser(boolean value) {
|
||||
configuration.setIgnoreAnnotationsWhenAttributingComments(value);
|
||||
}
|
||||
|
||||
@When("the do not assign comments preceding empty lines is $value on the Java parser")
|
||||
public void whenTheDoNotAssignCommentsPrecedingEmptyLinesIsTrueOnTheJavaParser(boolean value) {
|
||||
configuration.setDoNotAssignCommentsPrecedingEmptyLines(value);
|
||||
}
|
||||
|
||||
@When("the class is parsed by the Java parser")
|
||||
public void whenTheClassIsParsedByTheJavaParser() {
|
||||
ParseResult<CompilationUnit> result =
|
||||
new JavaParser(configuration).parse(COMPILATION_UNIT, provider(sourceUnderTest));
|
||||
compilationUnit = result.getResult().get();
|
||||
}
|
||||
|
||||
@Then("the Java parser cannot parse it because of an error")
|
||||
public void javaParserCannotParseBecauseOfLexicalErrors() {
|
||||
ParseResult<CompilationUnit> result =
|
||||
new JavaParser(configuration).parse(COMPILATION_UNIT, provider(sourceUnderTest));
|
||||
if (result.isSuccessful()) {
|
||||
fail("Lexical error expected");
|
||||
}
|
||||
}
|
||||
|
||||
@Then("the total number of comments is $expectedCount")
|
||||
public void thenTheTotalNumberOfCommentsIs(int expectedCount) {
|
||||
assertThat(commentsCollection.size(), is(expectedCount));
|
||||
}
|
||||
|
||||
private <T extends Comment> T getCommentAt(Set<T> set, int index) {
|
||||
Iterator<T> iterator = set.iterator();
|
||||
T comment = null;
|
||||
while (index >= 0) {
|
||||
comment = iterator.next();
|
||||
index--;
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
|
||||
@Then("line comment $position is \"$expectedContent\"")
|
||||
public void thenLineCommentIs(int position, String expectedContent) {
|
||||
LineComment lineCommentUnderTest = getCommentAt(commentsCollection.getLineComments(), position - 1);
|
||||
|
||||
assertThat(lineCommentUnderTest.getContent(), is(expectedContent));
|
||||
}
|
||||
|
||||
@Then("block comment $position is \"$expectedContent\"")
|
||||
public void thenBlockCommentIs(int position, String expectedContent) {
|
||||
BlockComment lineCommentUnderTest = getCommentAt(commentsCollection.getBlockComments(), position - 1);
|
||||
|
||||
assertThat(lineCommentUnderTest.getContent(), is(equalToCompressingWhiteSpace(expectedContent)));
|
||||
}
|
||||
|
||||
@Then("Javadoc comment $position is \"$expectedContent\"")
|
||||
public void thenJavadocCommentIs(int position, String expectedContent) {
|
||||
JavadocComment commentUnderTest = getCommentAt(commentsCollection.getJavadocComments(), position - 1);
|
||||
|
||||
assertThat(commentUnderTest.getContent(), is(equalToCompressingWhiteSpace(expectedContent)));
|
||||
}
|
||||
|
||||
@Then("the line comments have the following positions: $table")
|
||||
public void thenTheLineCommentsHaveTheFollowingPositions(ExamplesTable examplesTable) {
|
||||
int index = 0;
|
||||
for (Parameters exampleRow : examplesTable.getRowsAsParameters()) {
|
||||
Comment expectedLineComment = toComment(exampleRow, new LineComment());
|
||||
Comment lineCommentUnderTest = getCommentAt(commentsCollection.getLineComments(), index);
|
||||
|
||||
Range underTestRange = lineCommentUnderTest.getRange().get();
|
||||
Range expectedRange = expectedLineComment.getRange().get();
|
||||
|
||||
assertThat(underTestRange.begin.line, is(expectedRange.begin.line));
|
||||
assertThat(underTestRange.begin.column, is(expectedRange.begin.column));
|
||||
assertThat(underTestRange.end.line, is(expectedRange.end.line));
|
||||
assertThat(underTestRange.end.column, is(expectedRange.end.column));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
@Then("the block comments have the following positions: $table")
|
||||
public void thenTheBlockCommentsHaveTheFollowingPositions(ExamplesTable examplesTable) {
|
||||
int index = 0;
|
||||
for (Parameters exampleRow : examplesTable.getRowsAsParameters()) {
|
||||
Comment expectedLineComment = toComment(exampleRow, new BlockComment());
|
||||
Comment lineCommentUnderTest = getCommentAt(commentsCollection.getBlockComments(), index);
|
||||
|
||||
Range underTestRange = lineCommentUnderTest.getRange().get();
|
||||
Range expectedRange = expectedLineComment.getRange().get();
|
||||
|
||||
assertThat(underTestRange.begin.line, is(expectedRange.begin.line));
|
||||
assertThat(underTestRange.begin.column, is(expectedRange.begin.column));
|
||||
assertThat(underTestRange.end.line, is(expectedRange.end.line));
|
||||
assertThat(underTestRange.end.column, is(expectedRange.end.column));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
@Then("the Javadoc comments have the following positions: $table")
|
||||
public void thenTheJavadocCommentsHaveTheFollowingPositions(ExamplesTable examplesTable) {
|
||||
int index = 0;
|
||||
for (Parameters exampleRow : examplesTable.getRowsAsParameters()) {
|
||||
Comment expectedLineComment = toComment(exampleRow, new BlockComment());
|
||||
Comment lineCommentUnderTest = getCommentAt(commentsCollection.getJavadocComments(), index);
|
||||
|
||||
Range underTestRange = lineCommentUnderTest.getRange().get();
|
||||
Range expectedRange = expectedLineComment.getRange().get();
|
||||
|
||||
assertThat(underTestRange.begin.line, is(expectedRange.begin.line));
|
||||
assertThat(underTestRange.begin.column, is(expectedRange.begin.column));
|
||||
assertThat(underTestRange.end.line, is(expectedRange.end.line));
|
||||
assertThat(underTestRange.end.column, is(expectedRange.end.column));
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
@Then("it is printed as:$src")
|
||||
public void isPrintedAs(String src) {
|
||||
assertThat(prettyPrinter.print(compilationUnit).trim(), is(src.trim()));
|
||||
}
|
||||
|
||||
@Then("the compilation unit is not commented")
|
||||
public void thenTheCompilationUnitIsNotCommented() {
|
||||
assertEquals(false, compilationUnit.getComment().isPresent());
|
||||
}
|
||||
|
||||
@Then("the compilation is commented \"$expectedContent\"")
|
||||
public void thenTheCompilationIsCommentedCompilationUnitComment(String expectedContent) {
|
||||
assertThat(compilationUnit.getComment().get().getContent(), is(expectedContent));
|
||||
}
|
||||
|
||||
@Then("the compilation unit has $expectedCount contained comments")
|
||||
public void thenTheCompilationUnitHasContainedComments(int expectedCount) {
|
||||
assertThat(compilationUnit.getComments().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then("the compilation unit has $expectedCount orphan comments")
|
||||
public void thenTheCompilationUnitHasExpectedCountOrphanComments(int expectedCount) {
|
||||
assertThat(compilationUnit.getOrphanComments().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then("the compilation unit orphan comment $position is \"$expectedContent\"")
|
||||
public void thenTheCompilationUnitOrphanCommentIs(int position, String expectedContent) {
|
||||
Comment commentUnderTest = compilationUnit.getOrphanComments().get(position - 1);
|
||||
assertThat(commentUnderTest.getContent(), is(equalToCompressingWhiteSpace(expectedContent)));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in compilation unit is not an orphan")
|
||||
public void thenCommentInCompilationUnitIsNotAnOrphan(int commentPosition) {
|
||||
Comment commentUnderTest = compilationUnit.getAllContainedComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.isOrphan(), is(false));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in compilation unit is an orphan")
|
||||
public void thenCommentInCompilationUnitIsAnOrphan(int commentPosition) {
|
||||
Comment commentUnderTest = compilationUnit.getAllContainedComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.isOrphan(), is(true));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in compilation unit is \"$expectedContent\"")
|
||||
public void thenCommentInCompilationUnitIs(int position, String expectedContent) {
|
||||
Comment commentUnderTest = compilationUnit.getAllContainedComments().get(position - 1);
|
||||
assertThat(commentUnderTest.getContent(), is(equalToCompressingWhiteSpace(expectedContent)));
|
||||
}
|
||||
|
||||
@Then("class $position is not commented")
|
||||
public void thenClassIsNotCommented(int position) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(position - 1);
|
||||
assertEquals(false, classUnderTest.getComment().isPresent());
|
||||
}
|
||||
|
||||
@Then("class $position is commented \"$expectedContent\"")
|
||||
public void thenClassIsCommented(int position, String expectedContent) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(position - 1);
|
||||
assertThat(classUnderTest.getComment().get().getContent(), is(expectedContent));
|
||||
}
|
||||
|
||||
@Then("class $position has $expectedCount total contained comments")
|
||||
public void thenClassHasTotalContainedComments(int position, int expectedCount) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(position - 1);
|
||||
assertThat(classUnderTest.getAllContainedComments().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then("class $position has $expectedCount orphan comment")
|
||||
@Alias("class $position has $expectedCount orphan comments")
|
||||
public void thenClassHasOrphanComments(int position, int expectedCount) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(position - 1);
|
||||
assertThat(classUnderTest.getOrphanComments().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then("class $classPosition orphan comment $commentPosition is \"$expectedContent\"")
|
||||
public void thenClassOrphanCommentIs(int classPosition, int commentPosition, String expectedContent) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
Comment commentUnderTest = classUnderTest.getOrphanComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.getContent(), is(equalToCompressingWhiteSpace(expectedContent)));
|
||||
}
|
||||
|
||||
@Then("method $methodPosition in class $classPosition is commented \"$expectedContent\"")
|
||||
public void thenMethodInClassIsCommented(int methodPosition, int classPosition, String expectedContent) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
|
||||
assertThat(methodUnderTest.getComment().get().getContent(), equalToCompressingWhiteSpace(expectedContent));
|
||||
}
|
||||
|
||||
@Then("method $methodPosition in class $classPosition has $expectedCount total contained comments")
|
||||
public void thenMethodInClassHasTotalContainedComments(int methodPosition, int classPosition, int expectedCount) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
|
||||
assertThat(methodUnderTest.getAllContainedComments().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in method $methodPosition in class $classPosition is \"$expectedContent\"")
|
||||
public void thenCommentInMethodInClassIs(
|
||||
int commentPosition, int methodPosition, int classPosition, String expectedContent) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
|
||||
Comment commentUnderTest = methodUnderTest.getAllContainedComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.getContent(), is(equalToCompressingWhiteSpace(expectedContent)));
|
||||
}
|
||||
|
||||
@Then("method $methodPosition in class $classPosition has $expectedCount orphan comments")
|
||||
public void thenMethodInClassHasOrphanComments(int methodPosition, int classPosition, int expectedCount) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
|
||||
assertThat(methodUnderTest.getOrphanComments().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"block statement in method $methodPosition in class $classPosition has $expectedCount total contained comments")
|
||||
public void thenBlockStatementInMethodInClassHasTotalContainedComments(
|
||||
int methodPosition, int classPosition, int expectedCount) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
|
||||
BlockStmt blockStmtUnderTest = methodUnderTest.getBody().orElse(null);
|
||||
assertThat(blockStmtUnderTest.getAllContainedComments().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then("block statement in method $methodPosition in class $classPosition has $expectedCount orphan comments")
|
||||
public void thenBlockStatementInMethodInClassHasOrphanComments(
|
||||
int methodPosition, int classPosition, int expectedCount) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
|
||||
BlockStmt blockStmtUnderTest = methodUnderTest.getBody().orElse(null);
|
||||
assertThat(blockStmtUnderTest.getOrphanComments().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"block statement in method $methodPosition in class $classPosition orphan comment $commentPosition is \"$expectedContent\"")
|
||||
public void thenBlockStatementInMethodInClassIs(
|
||||
int methodPosition, int classPosition, int commentPosition, String expectedContent) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
|
||||
BlockStmt blockStmtUnderTest = methodUnderTest.getBody().orElse(null);
|
||||
Comment commentUnderTest = blockStmtUnderTest.getOrphanComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.getContent(), is(equalToCompressingWhiteSpace(expectedContent)));
|
||||
}
|
||||
|
||||
@Then("type of method $methodPosition in class $classPosition is commented \"$expectedContent\"")
|
||||
public void thenTypeOfMethodInClassIsCommented(int methodPosition, int classPosition, String expectedContent) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, methodPosition - 1, MethodDeclaration.class);
|
||||
Comment commentUnderTest = methodUnderTest.getType().getComment().get();
|
||||
assertThat(commentUnderTest.getContent(), is(equalToCompressingWhiteSpace(expectedContent)));
|
||||
}
|
||||
|
||||
@Then("field $fieldPosition in class $classPosition contains $expectedCount comments")
|
||||
public void thenFieldInClassContainsComments(int fieldPosition, int classPosition, int expectedCount) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
FieldDeclaration fieldUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, fieldPosition - 1, FieldDeclaration.class);
|
||||
assertThat(fieldUnderTest.getAllContainedComments().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then("field $fieldPosition in class $classPosition is not commented")
|
||||
public void thenFieldInClassIsNotCommented(int fieldPosition, int classPosition) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
FieldDeclaration fieldUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, fieldPosition - 1, FieldDeclaration.class);
|
||||
assertEquals(false, fieldUnderTest.getComment().isPresent());
|
||||
}
|
||||
|
||||
@Then("field $fieldPosition in class $classPosition is commented \"$expectedContent\"")
|
||||
public void thenFieldInClassIsCommented(int fieldPosition, int classPosition, String expectedContent) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
FieldDeclaration fieldUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, fieldPosition - 1, FieldDeclaration.class);
|
||||
Comment commentUnderTest = fieldUnderTest.getComment().get();
|
||||
assertThat(commentUnderTest.getContent(), is(equalToCompressingWhiteSpace(expectedContent)));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"variable $variablePosition value of field $fieldPosition in class $classPosition is commented \"$expectedContent\"")
|
||||
public void thenVariableValueOfFieldInClassIsCommented(
|
||||
int variablePosition, int fieldPosition, int classPosition, String expectedContent) {
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
FieldDeclaration fieldUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, fieldPosition - 1, FieldDeclaration.class);
|
||||
VariableDeclarator variableUnderTest = fieldUnderTest.getVariable(variablePosition - 1);
|
||||
Expression valueUnderTest = variableUnderTest.getInitializer().orElse(null);
|
||||
Comment commentUnderTest = valueUnderTest.getComment().get();
|
||||
assertThat(commentUnderTest.getContent(), is(expectedContent));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in compilation unit parent is ClassOrInterfaceDeclaration")
|
||||
public void thenCommentInCompilationUnitParentIsClassOrInterfaceDeclaration(int commentPosition) {
|
||||
Comment commentUnderTest = compilationUnit.getAllContainedComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.getParentNode().get(), instanceOf(ClassOrInterfaceDeclaration.class));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in compilation unit commented node is ClassOrInterfaceDeclaration")
|
||||
public void thenCommentInCompilationUnitCommentedNodeIsClassOrInterfaceDeclaration(int commentPosition) {
|
||||
Comment commentUnderTest = compilationUnit.getAllContainedComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.getCommentedNode().get(), instanceOf(ClassOrInterfaceDeclaration.class));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in compilation unit commented node is FieldDeclaration")
|
||||
public void thenCommentInCompilationUnitCommentedNodeIsFieldDeclaration(int commentPosition) {
|
||||
Comment commentUnderTest = compilationUnit.getAllContainedComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.getCommentedNode().get(), instanceOf(FieldDeclaration.class));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in compilation unit commented node is IntegerLiteralExpr")
|
||||
public void thenCommentInCompilationUnitCommentedNodeIsIntegerLiteralExpr(int commentPosition) {
|
||||
Comment commentUnderTest = compilationUnit.getAllContainedComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.getCommentedNode().get(), instanceOf(IntegerLiteralExpr.class));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in compilation unit commented node is ExpressionStmt")
|
||||
public void thenCommentInCompilationUnitCommentedNodeIsIntegerExpressionStmt(int commentPosition) {
|
||||
Comment commentUnderTest = compilationUnit.getAllContainedComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.getCommentedNode().get(), instanceOf(ExpressionStmt.class));
|
||||
}
|
||||
|
||||
@Then("comment $commentPosition in compilation unit commented node is PrimitiveType")
|
||||
public void thenCommentInCompilationUnitCommentedNodeIsIntegerPrimitiveType(int commentPosition) {
|
||||
Comment commentUnderTest = compilationUnit.getAllContainedComments().get(commentPosition - 1);
|
||||
assertThat(commentUnderTest.getCommentedNode().get(), instanceOf(PrimitiveType.class));
|
||||
}
|
||||
|
||||
private Comment toComment(Parameters row, Comment comment) {
|
||||
comment.setRange(range(
|
||||
Integer.parseInt(row.values().get("beginLine")),
|
||||
Integer.parseInt(row.values().get("beginColumn")),
|
||||
Integer.parseInt(row.values().get("endLine")),
|
||||
Integer.parseInt(row.values().get("endColumn"))));
|
||||
return comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.steps;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.parse;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import org.jbehave.core.annotations.Given;
|
||||
import org.jbehave.core.annotations.Then;
|
||||
|
||||
public class ComparingSteps {
|
||||
|
||||
private CompilationUnit first;
|
||||
private CompilationUnit second;
|
||||
|
||||
/*
|
||||
* Given steps
|
||||
*/
|
||||
|
||||
@Given("the first class:$classSrc")
|
||||
public void givenTheFirstClass(String classSrc) {
|
||||
this.first = parse(classSrc.trim());
|
||||
}
|
||||
|
||||
@Given("the second class:$classSrc")
|
||||
public void givenTheSecondClass(String classSrc) {
|
||||
this.second = parse(classSrc.trim());
|
||||
}
|
||||
|
||||
/*
|
||||
* Then steps
|
||||
*/
|
||||
|
||||
@Then("they are equals")
|
||||
public void thenTheyAreEquals() {
|
||||
assertThat(first, is(equalTo(second)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,550 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.steps;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
||||
import com.github.javaparser.HasParentNode;
|
||||
import com.github.javaparser.ast.ArrayCreationLevel;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.PackageDeclaration;
|
||||
import com.github.javaparser.ast.body.*;
|
||||
import com.github.javaparser.ast.comments.BlockComment;
|
||||
import com.github.javaparser.ast.comments.JavadocComment;
|
||||
import com.github.javaparser.ast.comments.LineComment;
|
||||
import com.github.javaparser.ast.expr.*;
|
||||
import com.github.javaparser.ast.stmt.*;
|
||||
import com.github.javaparser.ast.type.*;
|
||||
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
|
||||
|
||||
/**
|
||||
* The <code>ExistenceOfParentNodeVerifier</code> verifies that each node of the compilation unit has a parent set.
|
||||
*/
|
||||
class ExistenceOfParentNodeVerifier {
|
||||
|
||||
public void verify(CompilationUnit compilationUnit) throws AssertionError {
|
||||
new Verifier().visit(compilationUnit, null);
|
||||
}
|
||||
|
||||
private static class Verifier extends VoidVisitorAdapter<Void> {
|
||||
private static void assertParentIsSet(HasParentNode<?> n) {
|
||||
assertThat(n + " has no parent set!", n.getParentNode().orElse(null), is(notNullValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AnnotationDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AnnotationMemberDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArrayAccessExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArrayCreationExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArrayInitializerExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssertStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BinaryExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BlockComment n, Void arg) {
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BlockStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BooleanLiteralExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(BreakStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CastExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CatchClause n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CharLiteralExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ClassExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterfaceDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ClassOrInterfaceType n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(CompilationUnit n, Void arg) {
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ConditionalExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ConstructorDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ContinueStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(DoubleLiteralExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EmptyStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EnclosedExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EnumConstantDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(EnumDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExplicitConstructorInvocationStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ExpressionStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FieldAccessExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(FieldDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForEachStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ForStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InitializerDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(InstanceOfExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IntegerLiteralExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(JavadocComment n, Void arg) {
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LabeledStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LineComment n, Void arg) {
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LambdaExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LongLiteralExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MarkerAnnotationExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MemberValuePair n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodCallExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(MethodReferenceExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NameExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NormalAnnotationExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NullLiteralExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ObjectCreationExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(PackageDeclaration n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Parameter n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(PrimitiveType n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(Name n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SimpleName n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArrayType n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ArrayCreationLevel n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(IntersectionType n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnionType n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ReturnStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SingleMemberAnnotationExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(StringLiteralExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SuperExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SwitchEntry n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SwitchStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(SynchronizedStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ThisExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ThrowStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TryStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalClassDeclarationStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(LocalRecordDeclarationStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypeExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(NodeList n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TypeParameter n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnaryExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(UnknownType n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(VariableDeclarationExpr n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(VariableDeclarator n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(VoidType n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WhileStmt n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(WildcardType n, Void arg) {
|
||||
assertParentIsSet(n);
|
||||
super.visit(n, arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,294 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.steps;
|
||||
|
||||
import static com.github.javaparser.StaticJavaParser.*;
|
||||
import static com.github.javaparser.ast.Modifier.Keyword.PUBLIC;
|
||||
import static com.github.javaparser.ast.Modifier.createModifierList;
|
||||
import static com.github.javaparser.ast.Modifier.staticModifier;
|
||||
import static com.github.javaparser.ast.NodeList.nodeList;
|
||||
import static com.github.javaparser.ast.type.PrimitiveType.intType;
|
||||
import static com.github.javaparser.steps.SharedSteps.getMethodByPositionAndClassPosition;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Modifier;
|
||||
import com.github.javaparser.ast.NodeList;
|
||||
import com.github.javaparser.ast.PackageDeclaration;
|
||||
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
|
||||
import com.github.javaparser.ast.body.MethodDeclaration;
|
||||
import com.github.javaparser.ast.body.Parameter;
|
||||
import com.github.javaparser.ast.body.TypeDeclaration;
|
||||
import com.github.javaparser.ast.expr.*;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.ast.stmt.Statement;
|
||||
import com.github.javaparser.ast.stmt.TryStmt;
|
||||
import com.github.javaparser.ast.type.VoidType;
|
||||
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
|
||||
import java.util.Map;
|
||||
import org.jbehave.core.annotations.Alias;
|
||||
import org.jbehave.core.annotations.Given;
|
||||
import org.jbehave.core.annotations.Then;
|
||||
import org.jbehave.core.annotations.When;
|
||||
|
||||
public class ManipulationSteps {
|
||||
|
||||
/* Fields used to maintain step state within this step class */
|
||||
private BlockStmt blockStmt;
|
||||
private Statement statement;
|
||||
private TryStmt tryStmt;
|
||||
private NodeList<Expression> variableDeclarationExprList;
|
||||
private ChangeMethodNameToUpperCaseVisitor changeMethodNameToUpperCaseVisitor;
|
||||
private AddNewIntParameterCalledValueVisitor addNewIntParameterCalledValueVisitor;
|
||||
|
||||
/* Map that maintains shares state across step classes. If manipulating the objects in the map you must update the state */
|
||||
private Map<String, Object> state;
|
||||
|
||||
public ManipulationSteps(Map<String, Object> state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Given("a BlockStmt")
|
||||
public void givenABlockStatement() {
|
||||
blockStmt = new BlockStmt();
|
||||
}
|
||||
|
||||
@Given("a Statement")
|
||||
public void givenAStatement() {
|
||||
statement = null;
|
||||
}
|
||||
|
||||
@Given("a TryStmt")
|
||||
public void givenATryStmt() {
|
||||
tryStmt = new TryStmt();
|
||||
}
|
||||
|
||||
@Given("a List of VariableDeclarations")
|
||||
public void givenAListOfVariableDeclarations() {
|
||||
variableDeclarationExprList = new NodeList<>();
|
||||
variableDeclarationExprList.add(new VariableDeclarationExpr());
|
||||
variableDeclarationExprList.add(new VariableDeclarationExpr());
|
||||
}
|
||||
|
||||
@Given("a ChangeNameToUpperCaseVisitor")
|
||||
public void givenAChangeNameToUpperCaseVisitor() {
|
||||
changeMethodNameToUpperCaseVisitor = new ChangeMethodNameToUpperCaseVisitor();
|
||||
}
|
||||
|
||||
@Given("a AddNewIntParameterCalledValueVisitor")
|
||||
public void givenAAddNewParameterCalledValueVisitor() {
|
||||
addNewIntParameterCalledValueVisitor = new AddNewIntParameterCalledValueVisitor();
|
||||
}
|
||||
|
||||
@When("is the String \"$value\" is parsed by the JavaParser using parseBlock")
|
||||
public void whenIsTheStringIsParsedByTheJavaParser(String value) {
|
||||
blockStmt = parseBlock(value);
|
||||
}
|
||||
|
||||
@When("is the String \"$value\" is parsed by the JavaParser using parseStatement")
|
||||
public void whenIsTheStringIsParsedByTheJavaParserUsingParseStatement(String value) {
|
||||
statement = parseStatement(value);
|
||||
}
|
||||
|
||||
@When("the List of VariableDeclarations are set as the resources on TryStmt")
|
||||
public void whenTheListOfVariableDeclarationsAreSetAsTheResourcesOnTryStmt() {
|
||||
tryStmt.setResources(variableDeclarationExprList);
|
||||
}
|
||||
|
||||
@When("empty list is set as the resources on TryStmt")
|
||||
public void whenNullIsSetAsTheResourcesOnTryStmt() {
|
||||
tryStmt.setResources(new NodeList<>());
|
||||
}
|
||||
|
||||
@When("the package declaration is set to \"$packageName\"")
|
||||
public void whenThePackageDeclarationIsSetTo(String packageName) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
compilationUnit.setPackageDeclaration(new PackageDeclaration(parseName(packageName)));
|
||||
state.put("cu1", compilationUnit);
|
||||
}
|
||||
|
||||
@When("a public class called \"$className\" is added to the CompilationUnit")
|
||||
public void whenAClassCalledIsAddedToTheCompilationUnit(String className) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
TypeDeclaration<?> type = new ClassOrInterfaceDeclaration(createModifierList(PUBLIC), false, "CreateClass");
|
||||
compilationUnit.setTypes(nodeList(type));
|
||||
state.put("cu1", compilationUnit);
|
||||
}
|
||||
|
||||
@When(
|
||||
"a public static method called \"$methodName\" returning void is added to class $position in the compilation unit")
|
||||
public void whenAStaticMethodCalledReturningIsAddedToClassInTheCompilationUnit(String methodName, int position) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
TypeDeclaration<?> type = compilationUnit.getType(position - 1);
|
||||
NodeList<Modifier> modifiers = createModifierList(PUBLIC);
|
||||
MethodDeclaration method = new MethodDeclaration(modifiers, new VoidType(), methodName);
|
||||
modifiers.add(staticModifier());
|
||||
method.setModifiers(modifiers);
|
||||
type.addMember(method);
|
||||
state.put("cu1", compilationUnit);
|
||||
}
|
||||
|
||||
@When("$typeName varargs called \"$parameterName\" are added to method $methodPosition in class $classPosition")
|
||||
public void whenVarargsCalledAreAddedToMethodInClass(
|
||||
String typeName, String parameterName, int methodPosition, int classPosition) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition)
|
||||
.addAndGetParameter(typeName, parameterName)
|
||||
.setVarArgs(true);
|
||||
}
|
||||
|
||||
@When("a BlockStmt is added to method $methodPosition in class $classPosition")
|
||||
public void whenABlockStmtIsAddedToMethodInClass(int methodPosition, int classPosition) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
method.setBody(new BlockStmt());
|
||||
}
|
||||
|
||||
@When(
|
||||
"$className.$fieldName.$methodName(\"$stringValue\"); is added to the body of method $methodPosition in class $classPosition")
|
||||
public void whenHelloWorldIsAddedToTheBodyOfMethodInClass(
|
||||
String className,
|
||||
String fieldName,
|
||||
String methodName,
|
||||
String stringValue,
|
||||
int methodPosition,
|
||||
int classPosition) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
NameExpr clazz = new NameExpr(className);
|
||||
FieldAccessExpr field = new FieldAccessExpr(clazz, fieldName);
|
||||
MethodCallExpr call = new MethodCallExpr(field, methodName);
|
||||
call.addArgument(new StringLiteralExpr(stringValue));
|
||||
method.getBody().get().addStatement(call);
|
||||
}
|
||||
|
||||
@When("method $methodPosition in class $classPosition has it's name converted to uppercase")
|
||||
public void whenMethodInClassHasItsNameConvertedToUppercase(int methodPosition, int classPosition) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
method.setName(method.getNameAsString().toUpperCase());
|
||||
}
|
||||
|
||||
@When("method $methodPosition in class $classPosition has an int parameter called \"$paramName\" added")
|
||||
public void whenMethodInClassHasAnIntArgumentCalledAdded(int methodPosition, int classPosition, String paramName) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
method.addParameter(intType(), paramName);
|
||||
}
|
||||
|
||||
@When("the compilation unit is cloned")
|
||||
public void whenTheCompilationUnitIsCloned() {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
state.put("cu1", compilationUnit.clone());
|
||||
}
|
||||
|
||||
@When("the ChangeNameToUpperCaseVisitor visits to compilation unit")
|
||||
public void whenTheVisitorVisitsToCompilationUnit() {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
changeMethodNameToUpperCaseVisitor.visit(compilationUnit, null);
|
||||
state.put("cu1", compilationUnit);
|
||||
}
|
||||
|
||||
@When("the AddNewIntParameterCalledValueVisitor visits to compilation unit")
|
||||
public void whenTheAddNewParameterCalledValueVisitorVisitsToCompilationUnit() {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
addNewIntParameterCalledValueVisitor.visit(compilationUnit, null);
|
||||
state.put("cu1", compilationUnit);
|
||||
}
|
||||
|
||||
@Then("is not equal to null")
|
||||
public void thenIsNotEqualToNull() {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
assertNotEquals(compilationUnit, null);
|
||||
}
|
||||
|
||||
@Then("is not equal to $value")
|
||||
public void thenIsNotEqualTo(String value) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
assertNotEquals(compilationUnit, value);
|
||||
}
|
||||
|
||||
@Then("Statement $position in BlockStmt toString is \"$expectedContent\"")
|
||||
public void thenTheBlockStmtContentIs(int position, String expectedContent) {
|
||||
Statement statementUnderTest = blockStmt.getStatement(position - 1);
|
||||
assertThat(statementUnderTest.toString(), is(expectedContent));
|
||||
}
|
||||
|
||||
@Then("Statement toString is \"$expectedContent\"")
|
||||
public void thenStatementToStringIsxXy(String expectedContent) {
|
||||
assertThat(statement.toString(), is(expectedContent));
|
||||
}
|
||||
|
||||
@Then("all the VariableDeclarations parent is the TryStmt")
|
||||
public void thenAllTheVariableDeclarationsParentIsTheTryStmt() {
|
||||
variableDeclarationExprList.forEach(
|
||||
expr -> assertThat(expr.getParentNode().get(), is(tryStmt)));
|
||||
}
|
||||
|
||||
@Then("the TryStmt has no child nodes")
|
||||
public void thenTheTryStmtHasNotChildNodes() {
|
||||
assertThat(tryStmt.getChildNodes().size(), is(0));
|
||||
}
|
||||
|
||||
@Then("method $methodPosition in class $classPosition has the name \"$expectedName\"")
|
||||
public void thenMethodInClassHasTheName(int methodPosition, int classPosition, String expectedName) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
assertThat(method.getNameAsString(), is(expectedName));
|
||||
}
|
||||
|
||||
@Then("method $methodPosition in class $classPosition has $expectedCount parameters")
|
||||
@Alias("method $methodPosition in class $classPosition has $expectedCount parameter")
|
||||
public void thenMethodInClassHasArguments(int methodPosition, int classPosition, int expectedCount) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
|
||||
assertThat(method.getParameters().size(), is(expectedCount));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"method $methodPosition in class $classPosition parameter $parameterPosition is type int called \"$expectedName\"")
|
||||
public void thenMethodInClassParameterIsTypeIntCalled(
|
||||
int methodPosition, int classPosition, int parameterPosition, String expectedName) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
Parameter parameter = method.getParameter(parameterPosition - 1);
|
||||
assertThat(parameter.getType(), is(intType()));
|
||||
assertThat(parameter.getNameAsString(), is(expectedName));
|
||||
}
|
||||
|
||||
private static class ChangeMethodNameToUpperCaseVisitor extends VoidVisitorAdapter<Void> {
|
||||
@Override
|
||||
public void visit(MethodDeclaration n, Void arg) {
|
||||
n.setName(n.getNameAsString().toUpperCase());
|
||||
}
|
||||
}
|
||||
|
||||
private static class AddNewIntParameterCalledValueVisitor extends VoidVisitorAdapter<Void> {
|
||||
@Override
|
||||
public void visit(MethodDeclaration n, Void arg) {
|
||||
n.addParameter(intType(), "value");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
|
||||
* Copyright (C) 2011, 2013-2024 The JavaParser Team.
|
||||
*
|
||||
* This file is part of JavaParser.
|
||||
*
|
||||
* JavaParser can be used either under the terms of
|
||||
* a) the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
* b) the terms of the Apache License
|
||||
*
|
||||
* You should have received a copy of both licenses in LICENCE.LGPL and
|
||||
* LICENCE.APACHE. Please refer to those files for details.
|
||||
*
|
||||
* JavaParser is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.github.javaparser.steps;
|
||||
|
||||
import static com.github.javaparser.ParseStart.COMPILATION_UNIT;
|
||||
import static com.github.javaparser.Providers.provider;
|
||||
import static com.github.javaparser.steps.SharedSteps.getMemberByTypeAndPosition;
|
||||
import static com.github.javaparser.steps.SharedSteps.getMethodByPositionAndClassPosition;
|
||||
import static java.lang.String.format;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNull.notNullValue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.github.javaparser.JavaParser;
|
||||
import com.github.javaparser.ParseResult;
|
||||
import com.github.javaparser.ast.CompilationUnit;
|
||||
import com.github.javaparser.ast.Node;
|
||||
import com.github.javaparser.ast.PackageDeclaration;
|
||||
import com.github.javaparser.ast.body.*;
|
||||
import com.github.javaparser.ast.expr.*;
|
||||
import com.github.javaparser.ast.stmt.BlockStmt;
|
||||
import com.github.javaparser.ast.stmt.ExpressionStmt;
|
||||
import com.github.javaparser.ast.stmt.ReturnStmt;
|
||||
import com.github.javaparser.ast.stmt.Statement;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.jbehave.core.annotations.Given;
|
||||
import org.jbehave.core.annotations.Then;
|
||||
import org.jbehave.core.annotations.When;
|
||||
|
||||
public class ParsingSteps {
|
||||
|
||||
private Map<String, Object> state;
|
||||
|
||||
public ParsingSteps(Map<String, Object> state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
private String sourceUnderTest;
|
||||
|
||||
/*
|
||||
* Given steps
|
||||
*/
|
||||
|
||||
@Given("the class:$classSrc")
|
||||
public void givenTheClass(String classSrc) {
|
||||
this.sourceUnderTest = classSrc.trim();
|
||||
}
|
||||
|
||||
/*
|
||||
* When steps
|
||||
*/
|
||||
|
||||
@When("I take the ArrayCreationExpr")
|
||||
public void iTakeTheArrayCreationExpr() {
|
||||
setSelectedNodeFromCompilationUnit(ArrayCreationExpr.class);
|
||||
}
|
||||
|
||||
@When("I take the PackageDeclaration")
|
||||
public void iTakeThePackageDeclaration() {
|
||||
setSelectedNodeFromCompilationUnit(PackageDeclaration.class);
|
||||
}
|
||||
|
||||
@When("I take the ObjectCreationExpr")
|
||||
public void iTakeTheObjectCreationExpr() throws ClassNotFoundException {
|
||||
setSelectedNodeFromCompilationUnit(ObjectCreationExpr.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* Then steps
|
||||
*/
|
||||
|
||||
@Then("constructor $constructorPosition in class $classPosition declaration as a String is \"$expectedString\"")
|
||||
public void thenTheConstructorDeclarationAsAStringIs(
|
||||
int constructorPosition, int classPosition, String expectedString) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
ClassOrInterfaceDeclaration clazz = (ClassOrInterfaceDeclaration) compilationUnit.getType(classPosition - 1);
|
||||
ConstructorDeclaration constructor = (ConstructorDeclaration) clazz.getMember(constructorPosition - 1);
|
||||
assertThat(constructor.getDeclarationAsString(), is(expectedString));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"constructor $constructorPosition in class $classPosition declaration short form as a String is \"$expectedString\"")
|
||||
public void thenConstructorInClassDeclarationShortFormAsAStringIs(
|
||||
int constructorPosition, int classPosition, String expectedString) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
ClassOrInterfaceDeclaration clazz = (ClassOrInterfaceDeclaration) compilationUnit.getType(classPosition - 1);
|
||||
ConstructorDeclaration constructor = (ConstructorDeclaration) clazz.getMember(constructorPosition - 1);
|
||||
assertThat(constructor.getDeclarationAsString(false, false), is(expectedString));
|
||||
}
|
||||
|
||||
@Then("method $methodPosition in class $classPosition declaration as a String is \"$expectedString\"")
|
||||
public void thenMethod1InClass1DeclarationAsAStringIs(
|
||||
int methodPosition, int classPosition, String expectedString) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
ClassOrInterfaceDeclaration clazz = (ClassOrInterfaceDeclaration) compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration method = (MethodDeclaration) clazz.getMember(methodPosition - 1);
|
||||
assertThat(method.getDeclarationAsString(), is(expectedString));
|
||||
}
|
||||
|
||||
@Then("method $methodPosition in class $classPosition declaration as a String short form is \"$expectedString\"")
|
||||
public void thenMethodInClassDeclarationAsAStringShortFormIs(
|
||||
int methodPosition, int classPosition, String expectedString) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
ClassOrInterfaceDeclaration clazz = (ClassOrInterfaceDeclaration) compilationUnit.getType(classPosition - 1);
|
||||
MethodDeclaration method = (MethodDeclaration) clazz.getMember(methodPosition - 1);
|
||||
assertThat(method.getDeclarationAsString(false, false), is(expectedString));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"field $fieldPosition in class $classPosition contains annotation $annotationPosition value is \"$expectedValue\"")
|
||||
public void thenFieldInClassContainsAnnotationValueIs(
|
||||
int fieldPosition, int classPosition, int annotationPosition, String expectedValue) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
|
||||
TypeDeclaration<?> classUnderTest = compilationUnit.getType(classPosition - 1);
|
||||
FieldDeclaration fieldUnderTest =
|
||||
getMemberByTypeAndPosition(classUnderTest, fieldPosition - 1, FieldDeclaration.class);
|
||||
AnnotationExpr annotationUnderTest = fieldUnderTest.getAnnotation(annotationPosition - 1);
|
||||
assertThat(annotationUnderTest.getChildNodes().get(1).toString(), is(expectedValue));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"lambda in statement $statementPosition in method $methodPosition in class $classPosition is called $expectedName")
|
||||
public void thenLambdaInClassIsCalled(
|
||||
int statementPosition, int methodPosition, int classPosition, String expectedName) {
|
||||
Statement statement = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
|
||||
VariableDeclarationExpr expression = (VariableDeclarationExpr) ((ExpressionStmt) statement).getExpression();
|
||||
VariableDeclarator variableDeclarator = expression.getVariable(0);
|
||||
assertThat(variableDeclarator.getNameAsString(), is(expectedName));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"lambda in statement $statementPosition in method $methodPosition in class $classPosition body is \"$expectedBody\"")
|
||||
public void thenLambdaInStatementInMethodInClassBody(
|
||||
int statementPosition, int methodPosition, int classPosition, String expectedBody) {
|
||||
LambdaExpr lambdaExpr =
|
||||
getLambdaExprInStatementInMethodInClass(statementPosition, methodPosition, classPosition);
|
||||
assertThat(lambdaExpr.getBody().toString(), is(expectedBody));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"lambda in method call in statement $statementPosition in method $methodPosition in class $classPosition body is \"$expectedBody\"")
|
||||
public void thenLambdaInMethodCallInStatementInMethodInClassBody(
|
||||
int statementPosition, int methodPosition, int classPosition, String expectedBody) {
|
||||
ExpressionStmt statement = getStatementInMethodInClass(statementPosition, methodPosition, classPosition)
|
||||
.asExpressionStmt();
|
||||
VariableDeclarationExpr variableDeclarationExpr =
|
||||
statement.getExpression().asVariableDeclarationExpr();
|
||||
VariableDeclarator variableDeclarator = variableDeclarationExpr.getVariable(0);
|
||||
MethodCallExpr methodCallExpr =
|
||||
(MethodCallExpr) variableDeclarator.getInitializer().orElse(null);
|
||||
CastExpr castExpr = methodCallExpr.getArgument(0).asCastExpr();
|
||||
LambdaExpr lambdaExpr = castExpr.getExpression().asLambdaExpr();
|
||||
assertThat(lambdaExpr.getBody().toString(), is(expectedBody));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"lambda in statement $statementPosition in method $methodPosition in class $classPosition block statement is null")
|
||||
public void thenLambdaInStatementInMethodInClassBlockStatementIsNull(
|
||||
int statementPosition, int methodPosition, int classPosition) {
|
||||
LambdaExpr lambdaExpr =
|
||||
getLambdaExprInStatementInMethodInClass(statementPosition, methodPosition, classPosition);
|
||||
BlockStmt blockStmt = lambdaExpr.getBody().asBlockStmt();
|
||||
assertEquals(true, blockStmt.getStatements().isEmpty());
|
||||
}
|
||||
|
||||
@Then(
|
||||
"lambda in statement $statementPosition in method $methodPosition in class $classPosition has parameters with non-null type")
|
||||
public void thenLambdaInStatementInMethodInClassHasParametersWithNonNullType(
|
||||
int statementPosition, int methodPosition, int classPosition) {
|
||||
LambdaExpr lambdaExpr =
|
||||
getLambdaExprInStatementInMethodInClass(statementPosition, methodPosition, classPosition);
|
||||
for (Parameter parameter : lambdaExpr.getParameters()) {
|
||||
assertThat(parameter.getType(), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Then(
|
||||
"lambda in statement $statementPosition in method $methodPosition in class $classPosition block statement is \"$expectedBody\"")
|
||||
public void thenLambdaInStatementInMethodInClassBlockStatement(
|
||||
int statementPosition, int methodPosition, int classPosition, String expectedBody) {
|
||||
LambdaExpr lambdaExpr =
|
||||
getLambdaExprInStatementInMethodInClass(statementPosition, methodPosition, classPosition);
|
||||
BlockStmt blockStmt = lambdaExpr.getBody().asBlockStmt();
|
||||
Statement lambdaStmt = blockStmt.getStatement(0);
|
||||
assertThat(lambdaStmt.toString(), is(expectedBody));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"lambda in statement $statementPosition in method $methodPosition in class $classPosition is parent of contained body")
|
||||
public void thenLambdaInStatementInMethodInClassIsParentOfContainedBody(
|
||||
int statementPosition, int methodPosition, int classPosition) {
|
||||
LambdaExpr lambdaExpr =
|
||||
getLambdaExprInStatementInMethodInClass(statementPosition, methodPosition, classPosition);
|
||||
Statement body = lambdaExpr.getBody();
|
||||
assertThat(body.getParentNode().get(), is(lambdaExpr));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"lambda in statement $statementPosition in method $methodPosition in class $classPosition is parent of contained parameter")
|
||||
public void thenLambdaInStatementInMethodInClassIsParentOfContainedParameter(
|
||||
int statementPosition, int methodPosition, int classPosition) {
|
||||
LambdaExpr lambdaExpr =
|
||||
getLambdaExprInStatementInMethodInClass(statementPosition, methodPosition, classPosition);
|
||||
Parameter parameter = lambdaExpr.getParameter(0);
|
||||
assertThat(parameter.getParentNode().get(), is(lambdaExpr));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"method reference in statement $statementPosition in method $methodPosition in class $classPosition scope is $expectedName")
|
||||
public void thenMethodReferenceInStatementInMethodInClassIsScope(
|
||||
int statementPosition, int methodPosition, int classPosition, String expectedName) {
|
||||
ExpressionStmt statementUnderTest = getStatementInMethodInClass(
|
||||
statementPosition, methodPosition, classPosition)
|
||||
.asExpressionStmt();
|
||||
assertEquals(1, statementUnderTest.findAll(MethodReferenceExpr.class).size());
|
||||
MethodReferenceExpr methodReferenceUnderTest =
|
||||
statementUnderTest.findFirst(MethodReferenceExpr.class).get();
|
||||
assertThat(methodReferenceUnderTest.getScope().toString(), is(expectedName));
|
||||
}
|
||||
|
||||
@Then(
|
||||
"method reference in statement $statementPosition in method $methodPosition in class $classPosition identifier is $expectedName")
|
||||
public void thenMethodReferenceInStatementInMethodInClassIdentifierIsCompareByAge(
|
||||
int statementPosition, int methodPosition, int classPosition, String expectedName) {
|
||||
Statement statementUnderTest = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
|
||||
assertEquals(1, statementUnderTest.findAll(MethodReferenceExpr.class).size());
|
||||
MethodReferenceExpr methodReferenceUnderTest =
|
||||
statementUnderTest.findFirst(MethodReferenceExpr.class).get();
|
||||
assertThat(methodReferenceUnderTest.getIdentifier(), is(expectedName));
|
||||
}
|
||||
|
||||
@Then("method $methodPosition class $classPosition is a default method")
|
||||
public void thenMethodClassIsADefaultMethod(int methodPosition, int classPosition) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
assertThat(methodUnderTest.isDefault(), is(true));
|
||||
}
|
||||
|
||||
@Then("method $methodPosition class $classPosition is not a default method")
|
||||
public void thenMethodClassIsNotADefaultMethod(int methodPosition, int classPosition) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration methodUnderTest =
|
||||
getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
assertThat(methodUnderTest.isDefault(), is(false));
|
||||
}
|
||||
|
||||
private Statement getStatementInMethodInClass(int statementPosition, int methodPosition, int classPosition) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
MethodDeclaration method = getMethodByPositionAndClassPosition(compilationUnit, methodPosition, classPosition);
|
||||
return method.getBody().get().getStatement(statementPosition - 1);
|
||||
}
|
||||
|
||||
private LambdaExpr getLambdaExprInStatementInMethodInClass(
|
||||
int statementPosition, int methodPosition, int classPosition) {
|
||||
Statement statement = getStatementInMethodInClass(statementPosition, methodPosition, classPosition);
|
||||
VariableDeclarationExpr expression =
|
||||
((ExpressionStmt) statement).getExpression().asVariableDeclarationExpr();
|
||||
VariableDeclarator variableDeclarator = expression.getVariable(0);
|
||||
return (LambdaExpr) variableDeclarator.getInitializer().orElse(null);
|
||||
}
|
||||
|
||||
@Then("all nodes refer to their parent")
|
||||
public void allNodesReferToTheirParent() {
|
||||
assertAllNodesOfTheCompilationUnitHaveTheirParentSet("cu1");
|
||||
}
|
||||
|
||||
@Then("all nodes of the second compilation unit refer to their parent")
|
||||
public void thenAllNodesOfTheSecondCompilationUnitReferToTheirParent() {
|
||||
assertAllNodesOfTheCompilationUnitHaveTheirParentSet("cu2");
|
||||
}
|
||||
|
||||
private void assertAllNodesOfTheCompilationUnitHaveTheirParentSet(String stateKey) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get(stateKey);
|
||||
ExistenceOfParentNodeVerifier parentVerifier = new ExistenceOfParentNodeVerifier();
|
||||
parentVerifier.verify(compilationUnit);
|
||||
}
|
||||
|
||||
@Then(
|
||||
"ThenExpr in the conditional expression of the statement $statementPosition in method $methodPosition in class $classPosition is LambdaExpr")
|
||||
public void thenLambdaInConditionalExpressionInMethodInClassIsParentOfContainedParameter(
|
||||
int statementPosition, int methodPosition, int classPosition) {
|
||||
ReturnStmt returnStmt = getStatementInMethodInClass(statementPosition, methodPosition, classPosition)
|
||||
.asReturnStmt();
|
||||
ConditionalExpr conditionalExpr =
|
||||
(ConditionalExpr) returnStmt.getExpression().orElse(null);
|
||||
assertThat(conditionalExpr.getElseExpr().getClass().getName(), is(LambdaExpr.class.getName()));
|
||||
}
|
||||
|
||||
@Then("the begin line is $line")
|
||||
public void thenTheBeginLineIs(int line) {
|
||||
Node node = (Node) state.get("selectedNode");
|
||||
assertEquals(line, node.getBegin().get().line);
|
||||
}
|
||||
|
||||
@Then("the begin column is $column")
|
||||
public void thenTheBeginColumnIs(int column) {
|
||||
Node node = (Node) state.get("selectedNode");
|
||||
assertEquals(column, node.getBegin().get().column);
|
||||
}
|
||||
|
||||
@Then("the end line is $line")
|
||||
public void thenTheEndLineIs(int line) {
|
||||
Node node = (Node) state.get("selectedNode");
|
||||
assertEquals(line, node.getEnd().get().line);
|
||||
}
|
||||
|
||||
@Then("the end column is $column")
|
||||
public void thenTheEndColumnIs(int column) {
|
||||
Node node = (Node) state.get("selectedNode");
|
||||
assertEquals(column, node.getEnd().get().column);
|
||||
}
|
||||
|
||||
@Then("no errors are reported")
|
||||
public void thenNoErrorsAreReported() {
|
||||
// this is present just for readability in the scenario specification
|
||||
// if the code is not parsed then exceptions are thrown before reaching this step
|
||||
}
|
||||
|
||||
@Then("the package name is $package")
|
||||
public void thenThePackageNameIs(String expected) {
|
||||
PackageDeclaration node = (PackageDeclaration) state.get("selectedNode");
|
||||
assertEquals(expected, node.getNameAsString());
|
||||
assertEquals(expected, node.getName().toString());
|
||||
}
|
||||
|
||||
@Then("the type's diamond operator flag should be $expectedValue")
|
||||
public void thenTheUsesDiamondOperatorShouldBeBooleanAsString(boolean expectedValue) {
|
||||
ObjectCreationExpr expr = (ObjectCreationExpr) state.get("selectedNode");
|
||||
assertEquals(expectedValue, expr.getType().isUsingDiamondOperator());
|
||||
}
|
||||
|
||||
@Then("the Java parser cannot parse it because of an error")
|
||||
public void javaParserCannotParseBecauseOfLexicalErrors() {
|
||||
ParseResult<CompilationUnit> result = new JavaParser().parse(COMPILATION_UNIT, provider(sourceUnderTest));
|
||||
if (result.isSuccessful()) {
|
||||
fail("Lexical error expected");
|
||||
}
|
||||
}
|
||||
|
||||
@Then("the assignExpr produced doesn't have a null target")
|
||||
public void thenTheAssignExprProducedDoesntHaveANullTarget() {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
ClassOrInterfaceDeclaration classDeclaration =
|
||||
compilationUnit.getType(0).asClassOrInterfaceDeclaration();
|
||||
ConstructorDeclaration ctor = classDeclaration.getMember(1).asConstructorDeclaration();
|
||||
ExpressionStmt assignStmt = ctor.getBody().getStatement(0).asExpressionStmt();
|
||||
AssignExpr assignExpr = assignStmt.getExpression().asAssignExpr();
|
||||
assertNotNull(assignExpr.getTarget());
|
||||
assertEquals(NameExpr.class, assignExpr.getTarget().getClass());
|
||||
assertEquals(assignExpr.getTarget().asNameExpr().getNameAsString(), "mString");
|
||||
}
|
||||
|
||||
private void setSelectedNodeFromCompilationUnit(Class<? extends Node> nodeType) {
|
||||
CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
|
||||
List<? extends Node> nodes = compilationUnit.findAll(nodeType);
|
||||
if (nodes.size() != 1) {
|
||||
throw new RuntimeException(format("Exactly one %s expected", nodeType.getSimpleName()));
|
||||
}
|
||||
state.put("selectedNode", nodes.get(0));
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user