Skip to content

Commit

Permalink
[NETBEANS-5599] PHP 8.1 Support: Enumerations (Part 10)
Browse files Browse the repository at this point in the history
- https://issues.apache.org/jira/browse/NETBEANS-5599
- https://wiki.php.net/rfc/enumerations
- Add the template for enum
- Add `PhpEnum` as `PhpType`
  • Loading branch information
junichi11 committed Apr 11, 2022
1 parent 24eb936 commit 8d550aa
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 5 deletions.
2 changes: 1 addition & 1 deletion php/php.api.editor/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.php.api.editor/0
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/api/editor/resources/Bundle.properties
OpenIDE-Module-Specification-Version: 0.42
OpenIDE-Module-Specification-Version: 0.43
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* 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.
*/
package org.netbeans.modules.php.api.editor;

import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.annotations.common.NullAllowed;
import org.openide.filesystems.FileObject;

/**
* Class representing a PHP enum.
*/
public class PhpEnum extends PhpType {

public PhpEnum(String name, String fullyQualifiedName, String description) {
super(name, fullyQualifiedName, description);
}

public PhpEnum(String name, String fullyQualifiedName) {
super(name, fullyQualifiedName);
}

public PhpEnum(String name, String fullyQualifiedName, int offset) {
super(name, fullyQualifiedName, offset);
}

public PhpEnum(String name, String fullyQualifiedName, int offset, String description) {
super(name, fullyQualifiedName, offset, description);
}

@Override
public PhpEnum addField(@NonNull String name, @NullAllowed String fullyQualifiedName, int offset, @NullAllowed String description) {
super.addField(name, fullyQualifiedName, offset, description);
return this;
}

@Override
public PhpEnum addField(@NonNull String name, @NullAllowed String fullyQualifiedName, int offset) {
return addField(name, fullyQualifiedName, offset, null);
}

@Override
public PhpEnum addField(@NonNull String name, @NullAllowed String fullyQualifiedName) {
return addField(name, fullyQualifiedName, -1, null);
}

@Override
public PhpEnum addField(@NonNull String name, @NullAllowed String fullyQualifiedName, @NullAllowed String description) {
return addField(name, fullyQualifiedName, -1, description);
}

@Override
public PhpEnum addField(@NonNull String name, @NullAllowed PhpType type, @NullAllowed FileObject file, int offset) {
super.addField(name, type, file, offset);
return this;
}

@Override
public PhpEnum addMethod(@NonNull String name, @NullAllowed String fullyQualifiedName, int offset, @NullAllowed String description) {
super.addMethod(name, fullyQualifiedName, offset, description);
return this;
}

@Override
public PhpEnum addMethod(@NonNull String name, @NullAllowed String fullyQualifiedName, int offset) {
return addMethod(name, fullyQualifiedName, offset, null);
}

@Override
public PhpEnum addMethod(@NonNull String name, @NullAllowed String fullyQualifiedName) {
return addMethod(name, fullyQualifiedName, -1, null);
}

@Override
public PhpEnum addMethod(@NonNull String name, @NullAllowed String fullyQualifiedName, @NullAllowed String description) {
return addMethod(name, fullyQualifiedName, -1, description);
}

}
2 changes: 1 addition & 1 deletion php/php.editor/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ build.compiler=extJavac
nbjavac.ignore.missing.enclosing=**/CUP$ASTPHP5Parser$actions.class
javac.compilerargs=-J-Xmx512m
nbm.needs.restart=true
spec.version.base=2.12.0
spec.version.base=2.13.0
release.external/predefined_vars-1.0.zip=docs/predefined_vars.zip
sigtest.gen.fail.on.error=false

Expand Down
4 changes: 2 additions & 2 deletions php/php.editor/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
<compile-dependency/>
<run-dependency>
<release-version>0</release-version>
<specification-version>0.28</specification-version>
<specification-version>0.43</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand All @@ -321,7 +321,7 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>2.112</specification-version>
<specification-version>2.157</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.netbeans.modules.php.api.editor.EditorSupport;
import org.netbeans.modules.php.api.editor.PhpBaseElement;
import org.netbeans.modules.php.api.editor.PhpClass;
import org.netbeans.modules.php.api.editor.PhpEnum;
import org.netbeans.modules.php.api.editor.PhpFunction;
import org.netbeans.modules.php.api.editor.PhpInterface;
import org.netbeans.modules.php.api.editor.PhpTrait;
Expand All @@ -44,6 +45,7 @@
import org.netbeans.modules.php.editor.api.QuerySupportFactory;
import org.netbeans.modules.php.editor.api.elements.ClassElement;
import org.netbeans.modules.php.editor.model.ClassScope;
import org.netbeans.modules.php.editor.model.EnumScope;
import org.netbeans.modules.php.editor.model.FieldElement;
import org.netbeans.modules.php.editor.model.FileScope;
import org.netbeans.modules.php.editor.model.FunctionScope;
Expand Down Expand Up @@ -226,6 +228,17 @@ private PhpType getPhpType(TypeScope typeScope) {
phpTrait.addMethod(methodScope.getName(), methodScope.getName(), methodScope.getOffset());
}
phpType = phpTrait;
} else if (typeScope instanceof EnumScope) {
EnumScope enumScope = (EnumScope) typeScope;
PhpEnum phpEnum = new PhpEnum(
enumScope.getName(),
enumScope.getNamespaceName().append(enumScope.getName()).toFullyQualified().toString(),
enumScope.getOffset()
);
for (MethodScope methodScope : enumScope.getDeclaredMethods()) {
phpEnum.addMethod(methodScope.getName(), methodScope.getName(), methodScope.getOffset());
}
phpType = phpEnum;
}
return phpType;
}
Expand Down
2 changes: 1 addition & 1 deletion php/php.project/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
AutoUpdate-Show-In-Client: false
OpenIDE-Module-Specification-Version: 2.156
OpenIDE-Module-Specification-Version: 2.157
OpenIDE-Module: org.netbeans.modules.php.project
OpenIDE-Module-Layer: org/netbeans/modules/php/project/resources/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/project/resources/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@
<attr name="templateCategory" stringvalue="PHP"/>
<attr name="position" intvalue="400"/>
</file>
<file name="PHPEnum.php" url="nbresloc:/org/netbeans/modules/php/project/ui/resources/emptyEnumPHP.php">
<attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>
<attr name="displayName" bundlevalue="org.netbeans.modules.php.project.ui.wizards.Bundle#Templates/Scripting/PHPEnum"/>
<attr name="instantiatingIterator" methodvalue="org.netbeans.modules.php.project.ui.wizards.NewFileWizardIteratorWithNamespace.create"/>
<attr name="template" boolvalue="true"/>
<attr name="templateWizardURL" urlvalue="nbresloc:/org/netbeans/modules/php/project/ui/resources/emptyPHPEnumDescription.html"/>
<attr name="templateCategory" stringvalue="PHP"/>
<attr name="position" intvalue="410"/>
</file>
</folder>
</folder>
<folder name="PHP">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<#--

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.

-->
<?php
<#assign licenseFirst = "/* ">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "${project.licensePath}">

<#if namespace?? && namespace?length &gt; 0>
namespace ${namespace};
</#if>

/**
*
* @author ${user}
*/
enum ${name} {
//put your code here
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
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.
-->

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
Creates empty PHP Enum. You can edit the file in the IDE's Source Editor.
To change this template, choose Tools | Template Manager
and open the template in the editor.
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Templates/Scripting/EmptyPHPWebPage=PHP Web Page
Templates/Scripting/PHPClass=PHP Class
Templates/Scripting/PHPInterface=PHP Interface
Templates/Scripting/PHPTrait=PHP Trait
Templates/Scripting/PHPEnum=PHP Enum
Templates/Scripting/Tests=Tests

# PHP project wizards
Expand Down

0 comments on commit 8d550aa

Please sign in to comment.