Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# By jlerbsc (15) and others
# Via GitHub (13) and jlerbsc (1)
* upstream/master:
  Fix issues on unit tests
  Fix: Issue 3045 Unexpected exception when solving type inside an Anonymous class
  chore(deps): update dependency maven-wrapper to v3.1.1
  chore(deps): update dependency org.apache.maven.plugins:maven-surefire-plugin to v3.0.0-m8
  chore(deps): update dependency org.apache.maven.plugins:maven-deploy-plugin to v3.1.0
  Improved search for functional interfaces
  An interface is not functional, while it only declares one abstract method which is not a member of Object, if it declares two abstract methods which are not public members of Object
  Throw an unsupported operation exception when the bound type of a scope, which is a constraint type, is not a reference type
  Creating a static method to instanciate LeastUpperBoundLogic
  Fix: Issue 1883 Finding lambda return type
  Fix: unit test resources
  Fix: issue 1815 ArrayIndexOutOfBoundsException when resolving lambda parameter. This fix is offered by Blackgen
  Refactor: cleanup/refactor code after fixing javaparser#3859
  chore(deps): bump checkstyle from 10.6.0 to 10.7.0
  [maven-release-plugin] prepare for next development iteration
  [maven-release-plugin] prepare release javaparser-parent-3.25.0
  update readme
  Update changelog
  Revert checkstyle rule related to import from error to warning
  First part of the implementation of least upper bound logic

# Conflicts:
#	changelog.md
#	javaparser-core-generators/pom.xml
#	javaparser-core-metamodel-generator/pom.xml
#	javaparser-core-serialization/pom.xml
#	javaparser-core-testing-bdd/pom.xml
#	javaparser-core-testing/pom.xml
#	javaparser-core/pom.xml
#	javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java
#	javaparser-core/src/main/java/com/github/javaparser/resolution/logic/FunctionalInterfaceLogic.java
#	javaparser-core/src/main/java/com/github/javaparser/resolution/model/SymbolReference.java
#	javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java
#	javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java
#	javaparser-symbol-solver-core/pom.xml
#	javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/TypeExtractor.java
#	javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/AbstractJavaParserContext.java
#	javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/LambdaExprContext.java
#	javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/BooleanConditionalExprHandler.java
#	javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ConditionalExprResolver.java
#	javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/NumericConditionalExprHandler.java
#	javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/promotion/ReferenceConditionalExprHandler.java
#	javaparser-symbol-solver-testing/pom.xml
#	javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/resolution/ConditionalExprTest.java
#	pom.xml
#	readme.md
  • Loading branch information
wadoon committed Feb 11, 2023
2 parents 62fcbc5 + 736401f commit decdac0
Show file tree
Hide file tree
Showing 61 changed files with 1,901 additions and 399 deletions.
Binary file modified .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
8 changes: 4 additions & 4 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
# 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
#
#
# https://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.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
108 changes: 106 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Next Release (Version 3.24.11)
Next Release (Version 3.25.1)
------------------
[issues resolved](https://github.com/javaparser/javaparser/milestone/195?closed=1)
[issues resolved](https://github.com/javaparser/javaparser/milestone/197?closed=1)

### Added

Expand All @@ -14,6 +14,110 @@ Next Release (Version 3.24.11)

### Security

Version 3.25.0
--------------

[issues resolved](https://github.com/javaparser/javaparser/milestone/196?closed=1)

### Added

* First part of the implementation of least upper bound logic (
PR [#3880](https://github.com/javaparser/javaparser/pull/3880) by [@jlerbsc](https://github.com/jlerbsc))
* feat: Improved support for calculating the type of an object creation… (
PR [#3877](https://github.com/javaparser/javaparser/pull/3877) by [@jlerbsc](https://github.com/jlerbsc))
* feat: Implement addRecord & getRecordByName for CompilationUnit (
PR [#3836](https://github.com/javaparser/javaparser/pull/3836) by [@marcluque](https://github.com/marcluque))
* Support Jigsaw requires static (PR [#3826](https://github.com/javaparser/javaparser/pull/3826)
by [@jlerbsc](https://github.com/jlerbsc))
* Add toDescriptor to ResolvedMethodDeclaration (PR [#3819](https://github.com/javaparser/javaparser/pull/3819)
by [@vanHekthor](https://github.com/vanHekthor))
* Refactoring context (WIP) (PR [#3792](https://github.com/javaparser/javaparser/pull/3792)
by [@jlerbsc](https://github.com/jlerbsc))
* Refactoring context (WIP) (PR [#3782](https://github.com/javaparser/javaparser/pull/3782)
by [@jlerbsc](https://github.com/jlerbsc))
* Refactoring convert to usage (PR [#3774](https://github.com/javaparser/javaparser/pull/3774)
by [@jlerbsc](https://github.com/jlerbsc))
* Simplified usage of class AssociableToAST (PR [#3063](https://github.com/javaparser/javaparser/pull/3063)
by [@4everTheOne](https://github.com/4everTheOne))

### Changed

* Revert import related checkstyle rule from error to warning (
PR [#3881](https://github.com/javaparser/javaparser/pull/3881) by [@jlerbsc](https://github.com/jlerbsc))
* Minor refactoring for example to get all parameter types (
PR [#3879](https://github.com/javaparser/javaparser/pull/3879) by [@jlerbsc](https://github.com/jlerbsc))
* Add header and footer methods in comments instead of using literal st… (
PR [#3876](https://github.com/javaparser/javaparser/pull/3876) by [@jlerbsc](https://github.com/jlerbsc))
* In the context of lexical preservation, the CSM token must be added m… (
PR [#3874](https://github.com/javaparser/javaparser/pull/3874) by [@jlerbsc](https://github.com/jlerbsc))
* Refactoring: remove useless code that is already implemented (
PR [#3869](https://github.com/javaparser/javaparser/pull/3869) by [@jlerbsc](https://github.com/jlerbsc))
* Memory usage improvement when printing a node from the LexicalPreserv… (
PR [#3858](https://github.com/javaparser/javaparser/pull/3858) by [@jlerbsc](https://github.com/jlerbsc))
* chore(deps-dev): bump assertj-core from 3.24.1 to 3.24.2 (
PR [#3852](https://github.com/javaparser/javaparser/pull/3852)
by [@dependabot[bot]](https://github.com/apps/dependabot))
* chore(deps): bump maven-checkstyle-plugin from 3.2.0 to 3.2.1 (
PR [#3846](https://github.com/javaparser/javaparser/pull/3846)
by [@dependabot[bot]](https://github.com/apps/dependabot))
* chore(deps): bump maven-dependency-plugin from 3.4.0 to 3.5.0 (
PR [#3845](https://github.com/javaparser/javaparser/pull/3845)
by [@dependabot[bot]](https://github.com/apps/dependabot))
* chore(deps): update junit5 monorepo to v5.9.2 (PR [#3840](https://github.com/javaparser/javaparser/pull/3840)
by [@renovate[bot]](https://github.com/apps/renovate))
* Minor refactoring on Difference class (PR [#3839](https://github.com/javaparser/javaparser/pull/3839)
by [@jlerbsc](https://github.com/jlerbsc))
* chore(deps-dev): bump assertj-core from 3.23.1 to 3.24.1 (
PR [#3837](https://github.com/javaparser/javaparser/pull/3837)
by [@dependabot[bot]](https://github.com/apps/dependabot))
* chore(deps): bump actions/checkout from 3.2.0 to 3.3.0 (PR [#3834](https://github.com/javaparser/javaparser/pull/3834)
by [@dependabot[bot]](https://github.com/apps/dependabot))
* chore(deps): bump checkstyle from 10.5.0 to 10.6.0 (PR [#3829](https://github.com/javaparser/javaparser/pull/3829)
by [@dependabot[bot]](https://github.com/apps/dependabot))

### Fixed

* Fix: Method hasScope must return true on NodeWithOptionalScope and No… (
PR [#3875](https://github.com/javaparser/javaparser/pull/3875) by [@jlerbsc](https://github.com/jlerbsc))
* fix #3859 UnsupportedOperationException when trying to resolve a type… (
PR [#3873](https://github.com/javaparser/javaparser/pull/3873) by [@abego](https://github.com/abego))
* Fix: issue 3866 Symbol solver is unable to resolve inner classes of ancestors when they are prefixed with a subclass (
PR [#3868](https://github.com/javaparser/javaparser/pull/3868) by [@jlerbsc](https://github.com/jlerbsc))
* Fix: issue 3703 Allow removing empty parentheses after removing all pairs from an annotation (
PR [#3865](https://github.com/javaparser/javaparser/pull/3865) by [@jlerbsc](https://github.com/jlerbsc))
* Fix: One must be able to know if any resolved type is a boxed primiti… (
PR [#3864](https://github.com/javaparser/javaparser/pull/3864) by [@jlerbsc](https://github.com/jlerbsc))
* Fix: Issue 2374 Comments of added Nodes are ignored in LexicalPreserv… (
PR [#3856](https://github.com/javaparser/javaparser/pull/3856) by [@jlerbsc](https://github.com/jlerbsc))
* Checkstyle for unused import (PR [#3841](https://github.com/javaparser/javaparser/pull/3841)
by [@4everTheOne](https://github.com/4everTheOne))
* Update bnd file (PR [#3783](https://github.com/javaparser/javaparser/pull/3783)
by [@jlerbsc](https://github.com/jlerbsc))

### Developer Changes

* Update javaparser copyright headers (PR [#3862](https://github.com/javaparser/javaparser/pull/3862)
by [@jlerbsc](https://github.com/jlerbsc))

### Uncategorised

* Add test case to verify range calculation on ArrayType (PR [#3828](https://github.com/javaparser/javaparser/pull/3828)
by [@jlerbsc](https://github.com/jlerbsc))
* Add test case to verify that LexicalPreservation supports TextBlock (
PR [#3827](https://github.com/javaparser/javaparser/pull/3827) by [@jlerbsc](https://github.com/jlerbsc))
* Refactoring: Removing useless method convertToUsage in JavaParserFacade (
PR [#3780](https://github.com/javaparser/javaparser/pull/3780) by [@jlerbsc](https://github.com/jlerbsc))

### :heart: Contributors

Thank You to all contributors who worked on this release!

* [@vanHekthor](https://github.com/vanHekthor)
* [@abego](https://github.com/abego)
* [@jlerbsc](https://github.com/jlerbsc)
* [@marcluque](https://github.com/marcluque)
* [@4everTheOne](https://github.com/4everTheOne)

Version 3.24.10
---------------
[issues resolved](https://github.com/javaparser/javaparser/milestone/194?closed=1)
Expand Down
1 change: 1 addition & 0 deletions dev-files/JavaParser-CheckStyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<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 -->
Expand Down
2 changes: 1 addition & 1 deletion javaparser-core-generators/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>jmlparser-parent</artifactId>
<groupId>io.github.jmltoolkit</groupId>
<version>3.24.11-SNAPSHOT</version>
<version>3.25.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion javaparser-core-metamodel-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<artifactId>jmlparser-parent</artifactId>
<groupId>io.github.jmltoolkit</groupId>
<version>3.24.11-SNAPSHOT</version>
<version>3.25.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion javaparser-core-serialization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>jmlparser-parent</artifactId>
<groupId>io.github.jmltoolkit</groupId>
<version>3.24.11-SNAPSHOT</version>
<version>3.25.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion javaparser-core-testing-bdd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>jmlparser-parent</artifactId>
<groupId>io.github.jmltoolkit</groupId>
<version>3.24.11-SNAPSHOT</version>
<version>3.25.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion javaparser-core-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>jmlparser-parent</artifactId>
<groupId>io.github.jmltoolkit</groupId>
<version>3.24.11-SNAPSHOT</version>
<version>3.25.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2007-2010 Júlio Vilmar Gesser.
* Copyright (C) 2011, 2013-2023 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.ast.nodeTypes;

import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest;
import org.junit.jupiter.api.Test;

import static com.github.javaparser.ast.expr.Expression.EXCLUDE_ENCLOSED_EXPR;
import static org.junit.jupiter.api.Assertions.assertEquals;

class NodeWithArgumentsTest extends AbstractLexicalPreservingTest {

@Test
void testGetArgumentPosition() {
considerCode("" +
"class Foo {\n" +
" Map<Integer,String> map = new HashMap<>();\n" +
" public String bar(int i) {\n" +
" return map.put(((i)),((\"baz\")));\n" +
" } \n" +
"}");
MethodCallExpr mce = cu.findFirst(MethodCallExpr.class).get();
Expression arg0 = mce.getArgument(0);
Expression arg1 = mce.getArgument(1);
Expression innerExpr0 = arg0.asEnclosedExpr().getInner()
.asEnclosedExpr().getInner();
Expression innerExpr1 = arg1.asEnclosedExpr().getInner()
.asEnclosedExpr().getInner();

assertEquals(0, mce.getArgumentPosition(arg0)); // with no conversion
assertEquals(0, mce.getArgumentPosition(innerExpr0, EXCLUDE_ENCLOSED_EXPR)); // with a conversion skipping EnclosedExprs
assertEquals(1, mce.getArgumentPosition(arg1)); // with no conversion
assertEquals(1, mce.getArgumentPosition(innerExpr1, EXCLUDE_ENCLOSED_EXPR)); // with a conversion skipping EnclosedExprs
}
}
2 changes: 1 addition & 1 deletion javaparser-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<artifactId>jmlparser-parent</artifactId>
<groupId>io.github.jmltoolkit</groupId>
<version>3.24.11-SNAPSHOT</version>
<version>3.25.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

import static com.github.javaparser.utils.CodeGenerationUtils.f;

Expand All @@ -44,6 +46,26 @@
*/
public abstract class Expression extends Node {

/**
* Returns {@code true} when the Node to be tested is not an
* {@link EnclosedExpr}, {@code false} otherwise.
*/
public static final Predicate<Node> IS_NOT_ENCLOSED_EXPR = n -> !(n instanceof EnclosedExpr);


/**
* A {@link Function} that returns its argument (an {@link Expression}) when
* the argument is not an {@link EnclosedExpr}, otherwise the first
* {@link Expression} down the argument's 'inner' path that is not an
* {@link EnclosedExpr}.
*/
public static final Function<Expression, Expression> EXCLUDE_ENCLOSED_EXPR = expr -> {
while (expr.isEnclosedExpr()) {
expr = expr.asEnclosedExpr().getInner();
}
return expr;
};

@AllFieldsConstructor
public Expression() {
this(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.github.javaparser.ast.NodeList;
import com.github.javaparser.ast.expr.Expression;

import java.util.function.Function;

import static com.github.javaparser.StaticJavaParser.parseExpression;

/**
Expand Down Expand Up @@ -55,4 +57,28 @@ default N setArgument(int i, Expression arg) {
getArguments().set(i, arg);
return (N) this;
}

/*
* Returns the position of the argument in the object's argument list.
*/
default int getArgumentPosition(Expression argument) {
return getArgumentPosition(argument, expr -> expr);
}

/*
* Returns the position of the {@code argument} in the object's argument
* list, after converting the argument using the given {@code converter}
* function.
*/
default int getArgumentPosition(Expression argument, Function<Expression, Expression> converter) {
if (argument == null) {
throw new IllegalStateException();
}
for (int i = 0; i < getArguments().size(); i++) {
Expression expression = getArguments().get(i);
expression = converter.apply(expression);
if (expression == argument) return i;
}
throw new IllegalStateException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,63 @@ public String getSignature() {
return sb.toString();
}

/**
* The erased signature of the method.
*/
public String getErasedSignature() {
StringBuilder sb = new StringBuilder();
sb.append(getName());
sb.append("(");
for (int i = 0; i < getNoParams(); i++) {
if (i != 0) {
sb.append(", ");
}
ResolvedType type = getParamType(i).erasure();
if (type.isArray() && getDeclaration().getParam(i).isVariadic()) {
sb.append(type.asArrayType().getComponentType().describe()).append("...");
} else {
sb.append(type.describe());
}
}
sb.append(")");
return sb.toString();
}

public List<ResolvedType> exceptionTypes() {
return exceptionTypes;
}

/*
* Two methods or constructors, M and N, have the same signature if they have
* the same name, the same type parameters (if any) (§8.4.4), and, after
* adapting the formal parameter types of N to the the type parameters of M, the
* same formal parameter types.
* https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html
* This method returns an approximation of this rule.
*/
public boolean isSameSignature(MethodUsage otherMethodUsage) {
return getSignature().equals(otherMethodUsage.getSignature());
}

/*
* The signature of a method m1 is a subsignature of the signature of a method m2 if either:
* m2 has the same signature as m1, or
* the signature of m1 is the same as the erasure (§4.6) of the signature of m2.
*/
public boolean isSubSignature(MethodUsage otherMethodUsage) {
return getErasedSignature().equals(otherMethodUsage.getErasedSignature());
}

/*
* A method declaration d1 with return type R1 is return-type-substitutable for another method d2 with return type R2 iff any of the following is true:
* If R1 is void then R2 is void.
* If R1 is a primitive type then R2 is identical to R1.
* If R1 is a reference type then one of the following is true:
* R1, adapted to the type parameters of d2 (§8.4.4), is a subtype of R2.
* R1 can be converted to a subtype of R2 by unchecked conversion (§5.1.9).
* d1 does not have the same signature as d2 (§8.4.2), and R1 = |R2|.
*/
public boolean isReturnTypeSubstituable(MethodUsage otherMethodUsage) {
return getDeclaration().isReturnTypeSubstituable(otherMethodUsage.getDeclaration().getReturnType());
}
}
Loading

0 comments on commit decdac0

Please sign in to comment.