Skip to content

Commit

Permalink
Merge pull request apache#2568 from junichi11/netbeans-5062
Browse files Browse the repository at this point in the history
[NETBEANS-5062] PHPDoc static type incorrectly resolved when returned by another class
  • Loading branch information
tmysik authored Nov 29, 2020
2 parents cbadb54 + fdb5bd2 commit ad23179
Show file tree
Hide file tree
Showing 20 changed files with 630 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,24 @@ public synchronized Collection<? extends String> getReturnTypeNames() {
public Collection<? extends TypeScope> getReturnTypes(boolean resolveSemiTypes, Collection<? extends TypeScope> callerTypes) {
assert callerTypes != null;
String types = getReturnType();
Collection<? extends TypeScope> result = getReturnTypesDescriptor(types, resolveSemiTypes, callerTypes).getModifiedResult(callerTypes);
// NETBEANS-5062
Scope inScope = getInScope();
Set<TypeScope> cTypes = new HashSet<>();
List<String> typeNames = StringUtils.explode(types, Type.SEPARATOR);
if (typeNames.contains(Type.STATIC)
&& inScope instanceof TypeScope) {
TypeScope typeScope = (TypeScope) inScope;
for (TypeScope callerType : callerTypes) {
if (callerType.isSubTypeOf(typeScope)) {
cTypes.add(callerType);
} else {
cTypes.add(typeScope);
}
}
} else {
cTypes.addAll(callerTypes);
}
Collection<? extends TypeScope> result = getReturnTypesDescriptor(types, resolveSemiTypes, cTypes).getModifiedResult(cTypes);
if (!declaredReturnType) {
updateReturnTypes(types, result);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/*
* 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.
*/

class Test1
{

private function getTest2() {
return Test2::returnStatic();
}

private function getTest2ReturnType() {
return Test2::returnStaticReturnType();
}

private function getTest2PHPDoc() {
return Test2::returnStaticPHPDoc();
}

private function getTest2Self() {
return Test2::returnSelf();
}

private function getTest2SelfReturnType() {
return Test2::returnSelfReturnType();
}

private function getTest2SelfPHPDoc() {
return Test2::returnSelfPHPDoc();
}

public function testMethod() {
echo "Test1" . PHP_EOL;
}

public function test() {
$static1 = $this->getTest2();
$static1->testMethod();

$static2 = $this->getTest2ReturnType();
$static2->testMethod();

$static3 = $this->getTest2PHPDoc();
$static3->testMethod();

$self1 = $this->getTest2Self();
$self1->testMethod();

$self2 = $this->getTest2SelfReturnType();
$self2->testMethod();

$self3 = $this->getTest2SelfPHPDoc();
$self3->testMethod();
}

}

class Test2
{

public static function returnStatic() {
return new static();
}

public static function returnStaticReturnType(): static {
}

/**
* @return static
*/
public static function returnStaticPHPDoc() {
}

public static function returnSelf() {
return new self();
}

public static function returnSelfReturnType(): self {
}

/**
* @return self
*/
public static function returnSelfPHPDoc() {
}

public function testMethod() {
echo "Test2" . PHP_EOL;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code completion result for source line:
$self1->|testMethod();
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
METHOD returnSelf() [STATIC] Test2
METHOD returnSelfPHPDoc() [STATIC] Test2
METHOD returnSelfReturnType() [STATIC] Test2
METHOD returnStatic() [STATIC] Test2
METHOD returnStaticPHPDoc() [STATIC] Test2
METHOD returnStaticReturnType() [STATIC] Test2
METHOD testMethod() [PUBLIC] Test2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code completion result for source line:
$self2->|testMethod();
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
METHOD returnSelf() [STATIC] Test2
METHOD returnSelfPHPDoc() [STATIC] Test2
METHOD returnSelfReturnType() [STATIC] Test2
METHOD returnStatic() [STATIC] Test2
METHOD returnStaticPHPDoc() [STATIC] Test2
METHOD returnStaticReturnType() [STATIC] Test2
METHOD testMethod() [PUBLIC] Test2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code completion result for source line:
$self3->|testMethod();
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
METHOD returnSelf() [STATIC] Test2
METHOD returnSelfPHPDoc() [STATIC] Test2
METHOD returnSelfReturnType() [STATIC] Test2
METHOD returnStatic() [STATIC] Test2
METHOD returnStaticPHPDoc() [STATIC] Test2
METHOD returnStaticReturnType() [STATIC] Test2
METHOD testMethod() [PUBLIC] Test2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code completion result for source line:
$static1->|testMethod();
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
METHOD returnSelf() [STATIC] Test2
METHOD returnSelfPHPDoc() [STATIC] Test2
METHOD returnSelfReturnType() [STATIC] Test2
METHOD returnStatic() [STATIC] Test2
METHOD returnStaticPHPDoc() [STATIC] Test2
METHOD returnStaticReturnType() [STATIC] Test2
METHOD testMethod() [PUBLIC] Test2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code completion result for source line:
$static2->|testMethod();
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
METHOD returnSelf() [STATIC] Test2
METHOD returnSelfPHPDoc() [STATIC] Test2
METHOD returnSelfReturnType() [STATIC] Test2
METHOD returnStatic() [STATIC] Test2
METHOD returnStaticPHPDoc() [STATIC] Test2
METHOD returnStaticReturnType() [STATIC] Test2
METHOD testMethod() [PUBLIC] Test2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Code completion result for source line:
$static3->|testMethod();
(QueryType=COMPLETION, prefixSearch=true, caseSensitive=true)
METHOD returnSelf() [STATIC] Test2
METHOD returnSelfPHPDoc() [STATIC] Test2
METHOD returnSelfReturnType() [STATIC] Test2
METHOD returnStatic() [STATIC] Test2
METHOD returnStaticPHPDoc() [STATIC] Test2
METHOD returnStaticReturnType() [STATIC] Test2
METHOD testMethod() [PUBLIC] Test2
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/*
* 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.
*/

class Test1
{

private function getTest2() {
return Test2::returnStatic();
}

private function getTest2ReturnType() {
return Test2::returnStaticReturnType();
}

private function getTest2PHPDoc() {
return Test2::returnStaticPHPDoc();
}

private function getTest2Self() {
return Test2::returnSelf();
}

private function getTest2SelfReturnType() {
return Test2::returnSelfReturnType();
}

private function getTest2SelfPHPDoc() {
return Test2::returnSelfPHPDoc();
}

public function testMethod() {
echo "Test1" . PHP_EOL;
}

public function test() {
$static1 = $this->getTest2();
$static1->testMethod();

$static2 = $this->getTest2ReturnType();
$static2->testMethod();

$static3 = $this->getTest2PHPDoc();
$static3->testMethod();

$self1 = $this->getTest2Self();
$self1->testMethod();

$self2 = $this->getTest2SelfReturnType();
$self2->testMethod();

$self3 = $this->getTest2SelfPHPDoc();
$self3->testMethod();
}

}

class Test2
{

public static function returnStatic() {
return new static();
}

public static function returnStaticReturnType(): static {
}

/**
* @return static
*/
public static function returnStaticPHPDoc() {
}

public static function returnSelf() {
return new self();
}

public static function returnSelfReturnType(): self {
}

/**
* @return self
*/
public static function returnSelfPHPDoc() {
}

public function testMethod() { // Test2
echo "Test2" . PHP_EOL;
}

}
Loading

0 comments on commit ad23179

Please sign in to comment.