Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.netbeans.modules.php.editor.parser.astnodes.ArrayAccess;
import org.netbeans.modules.php.editor.parser.astnodes.ArrayCreation;
import org.netbeans.modules.php.editor.parser.astnodes.ArrowFunctionDeclaration;
import org.netbeans.modules.php.editor.parser.astnodes.Block;
import org.netbeans.modules.php.editor.parser.astnodes.ClassInstanceCreation;
import org.netbeans.modules.php.editor.parser.astnodes.ClassName;
import org.netbeans.modules.php.editor.parser.astnodes.Expression;
Expand All @@ -48,10 +49,12 @@
import org.netbeans.modules.php.editor.parser.astnodes.ReturnStatement;
import org.netbeans.modules.php.editor.parser.astnodes.Scalar;
import org.netbeans.modules.php.editor.parser.astnodes.SingleUseStatementPart;
import org.netbeans.modules.php.editor.parser.astnodes.Statement;
import org.netbeans.modules.php.editor.parser.astnodes.StaticConstantAccess;
import org.netbeans.modules.php.editor.parser.astnodes.StaticDispatch;
import org.netbeans.modules.php.editor.parser.astnodes.StaticFieldAccess;
import org.netbeans.modules.php.editor.parser.astnodes.StaticMethodInvocation;
import org.netbeans.modules.php.editor.parser.astnodes.UseTraitStatement;
import org.netbeans.modules.php.editor.parser.astnodes.UseTraitStatementPart;
import org.netbeans.modules.php.editor.parser.astnodes.Variable;
import org.netbeans.modules.php.editor.parser.astnodes.Variadic;
Expand Down Expand Up @@ -454,8 +457,14 @@ static class UsedTraitsVisitor extends DefaultVisitor {
private final List<UseTraitStatementPart> useParts = new LinkedList<>();

@Override
public void visit(UseTraitStatementPart node) {
useParts.add(node);
public void visit(Block node) {
for (Statement statement : node.getStatements()) {
if (statement instanceof UseTraitStatement useTraitStatement) {
for (UseTraitStatementPart parts : useTraitStatement.getParts()) {
useParts.add(parts);
}
}
}
}

public Collection<QualifiedName> getUsedTraits() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.netbeans.modules.csl.api.OffsetRange;
Expand All @@ -31,8 +30,6 @@
import org.netbeans.modules.php.editor.parser.astnodes.ClassInstanceCreation;
import org.netbeans.modules.php.editor.parser.astnodes.ClassName;
import org.netbeans.modules.php.editor.parser.astnodes.Expression;
import org.netbeans.modules.php.editor.parser.astnodes.UseTraitStatementPart;
import org.netbeans.modules.php.editor.parser.astnodes.visitors.DefaultVisitor;

/**
* Info for anonymous classes.
Expand Down Expand Up @@ -106,25 +103,4 @@ public List<Attribute> getAttributes() {
return getOriginalNode().getAttributes();
}

//~ Inner classes
private static final class UsedTraitsVisitor extends DefaultVisitor {

private final List<UseTraitStatementPart> useParts = new LinkedList<>();


@Override
public void visit(UseTraitStatementPart node) {
useParts.add(node);
}

public Collection<QualifiedName> getUsedTraits() {
Collection<QualifiedName> retval = new HashSet<>();
for (UseTraitStatementPart useTraitStatementPart : useParts) {
retval.add(QualifiedName.create(useTraitStatementPart.getName()));
}
return retval;
}

}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
|-ClassScopeTestInterface [16, 48] : ESCAPED{ClassScopeTestInterface}
|-ClassScopeTestTrait [56, 84] : ESCAPED{ClassScopeTestTrait}
|-ClassScopeTest [92, 1512] : ESCAPED{ClassScopeTest}<font color="#999999">#ESCAPED{ClassScopeTestTrait}</font>
|-ClassScopeTest [92, 1512] : ESCAPED{ClassScopeTest}
|--test1 [130, 1059] : ESCAPED{test1}ESCAPED{(}ESCAPED{)}
|--test2 [1081, 1256] : ESCAPED{test2}ESCAPED{(}ESCAPED{)}
|--test3 [1278, 1510] : ESCAPED{test3}ESCAPED{(}ESCAPED{)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
|-TraitScopeTestInterface [16, 48] : ESCAPED{TraitScopeTestInterface}
|-TraitScopeTestTrait [56, 84] : ESCAPED{TraitScopeTestTrait}
|-TraitScopeClass [92, 116] : ESCAPED{TraitScopeClass}
|-TraitScopeTest [124, 1544] : ESCAPED{TraitScopeTest}<font color="#999999">#ESCAPED{TraitScopeTestTrait}</font>
|-TraitScopeTest [124, 1544] : ESCAPED{TraitScopeTest}
|--test1 [162, 1091] : ESCAPED{test1}ESCAPED{(}ESCAPED{)}
|--test2 [1113, 1288] : ESCAPED{test2}ESCAPED{(}ESCAPED{)}
|--test3 [1310, 1542] : ESCAPED{test3}ESCAPED{(}ESCAPED{)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
|-MyTrait [13, 107] : ESCAPED{MyTrait}
|--doSomething [45, 56] : ESCAPED{doSomething}ESCAPED{(}ESCAPED{)}
|--doNothing [81, 105] : ESCAPED{doNothing}ESCAPED{(}ESCAPED{)}
|-MysClass [115, 510] : ESCAPED{MysClass}
|--getObject [146, 508] : ESCAPED{getObject}ESCAPED{(}ESCAPED{)}
|-#anon#gh8527_php#2 [183, 501] : ESCAPED{{}}
|--getMyTraitAwareObject [222, 491] : ESCAPED{getMyTraitAwareObject}ESCAPED{(}ESCAPED{)}
|-#anon#gh8527_php#1 [287, 476] : ESCAPED{{}}<font color="#999999">#ESCAPED{MyTrait}</font>
|--doSomething [400, 458] : ESCAPED{doSomething}ESCAPED{(}ESCAPED{)}
33 changes: 33 additions & 0 deletions php/php.editor/test/unit/data/testfiles/structure/gh8527.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

trait MyTrait
{
abstract function doSomething();

public function doNothing()
{

}
}

class MysClass
{
public function getObject()
{
return new class() {

public function getMyTraitAwareObject()
{
return new class() {
use MyTrait;

#[\Override]
public function doSomething()
{

}
};
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

trait MyTrait
{
abstract function doSomething();

public function doNothing()
{

}
}

class MysClass
{
public function getObject()
{
return new class() {

public function getMyTraitAwareObject()
{
return new class() {
use MyTrait;

public function doSomething()
{

}
};
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

trait MyTrait
{
abstract function doSomething();

public function doNothing()
{

}
}

class MysClass
{
public function getObject()
{
return new class() {

public function getMyTraitAwareObject()
{
return new class() {
use MyTrait;
};
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
return new class() {
-----
HINT:Anonymous class is not abstract and does not override abstract method doSomething() in \MyTrait
FIX:Implement All Abstract Methods
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,8 @@ public void testFinalFieldsTrait() throws Exception {
public void testFinalFieldsAnonClass() throws Exception {
performTest("structure/php84/finalFieldsAnonClass");
}

public void testGH8527() throws Exception {
performTest("structure/gh8527");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ public void testOverrideAttributeEnum_Fix01() throws Exception {
applyHint("testOverrideAttributeEnum.php", "enum Enum^1 implements TestInterface {", "Implement All Abstract Methods", PhpVersion.PHP_83);
}

public void testGH8527() throws Exception {
checkHints("gh8527.php", PhpVersion.getDefault());
}

public void testGH8527_01() throws Exception {
checkHints("gh8527_01.php", PhpVersion.getDefault());
}

private void checkHints(String fileName, PhpVersion phpVersion) throws Exception {
checkHints(new ImplementAbstractMethodsHintErrorStub(phpVersion), fileName);
}
Expand Down
Loading