Skip to content

Commit

Permalink
Merge pull request #7425 from junichi11/php-gh-7170-code-template-npe
Browse files Browse the repository at this point in the history
Prevent NPE #7170
  • Loading branch information
junichi11 authored Jun 4, 2024
2 parents f6adf61 + 68b4950 commit fb457ad
Showing 1 changed file with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,37 +531,38 @@ private ClassElementAttribute getCurrentClassElement() {
public void visit(StaticConstantAccess node) {
String clsName = CodeUtils.extractUnqualifiedClassName(node);
ClassElementAttribute c = getCurrentClassElement();
switch (clsName) {
case "self": //NOI18N
if (c != null) {
clsName = c.getName();
}
break;
case "parent": //NOI18N
if (c != null) {
c = c.getSuperClass();
if (clsName != null) {
switch (clsName) {
case "self": //NOI18N
if (c != null) {
clsName = c.getName();
}
}
break;
default:
//no-op
}
Collection<AttributedElement> nn = getNamedGlobalElements(Kind.CLASS, clsName); //NOI18N
if (!nn.isEmpty()) {
for (AttributedElement ell : nn) {
ClassElementAttribute ce = (ClassElementAttribute) ell;
if (ce != null && ce.getName().equals(clsName)) {
String name = CodeUtils.extractUnqualifiedClassName(node);
AttributedElement thisEl = ce.lookup(name, Kind.CONST);
node2Element.put(node.getDispatcher(), ce);
node2Element.put(node, thisEl);
node2Element.put(node.getConstant(), thisEl);
break;
case "parent": //NOI18N
if (c != null) {
c = c.getSuperClass();
if (c != null) {
clsName = c.getName();
}
}
break;
default:
//no-op
}
Collection<AttributedElement> nn = getNamedGlobalElements(Kind.CLASS, clsName); //NOI18N
if (!nn.isEmpty()) {
for (AttributedElement ell : nn) {
ClassElementAttribute ce = (ClassElementAttribute) ell;
if (ce != null && ce.getName().equals(clsName)) {
String name = CodeUtils.extractUnqualifiedClassName(node);
AttributedElement thisEl = ce.lookup(name, Kind.CONST);
node2Element.put(node.getDispatcher(), ce);
node2Element.put(node, thisEl);
node2Element.put(node.getConstant(), thisEl);
break;
}
}
}

}
super.visit(node);
}
Expand Down

0 comments on commit fb457ad

Please sign in to comment.