Headers sent<\/p>Expires: (sometime in the future, according session.cache_expire) Cache-Control: public, max-age=(sometime in the future, according to session.cache_expire) Last-Modified: (the timestamp of when the session was last saved)",
5 | "category": ""
6 | },
7 | {
8 | "name": "private_no_expire",
9 | "description": "
Headers sent<\/p>Cache-Control: private, max-age=(session.cache_expire in the future), pre-check=(session.cache_expire in the future) Last-Modified: (the timestamp of when the session was last saved)",
10 | "category": ""
11 | },
12 | {
13 | "name": "private",
14 | "description": "
Headers sent<\/p>Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: private, max-age=(session.cache_expire in the future), pre-check=(session.cache_expire in the future) Last-Modified: (the timestamp of when the session was last saved)",
15 | "category": ""
16 | },
17 | {
18 | "name": "nocache",
19 | "description": "
Headers sent<\/p>Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache",
20 | "category": ""
21 | }
22 | ]
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/ParameterFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.editor.completion;
17 |
18 | /**
19 | *
20 | * @author junichi11
21 | */
22 | public interface ParameterFilter {
23 |
24 | public boolean accept(Parameter parameter, String filterText, String inputText);
25 | public static final ParameterFilter DEFAULT_FILTER = new DefaultParameterFilter();
26 |
27 | public static class DefaultParameterFilter implements ParameterFilter {
28 |
29 | @Override
30 | public boolean accept(Parameter parameter, String filterText, String inputText) {
31 | return parameter.getName().toLowerCase().contains(filterText.toLowerCase());
32 | }
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/Parameter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.editor.completion;
17 |
18 | /**
19 | *
20 | * @author junichi11
21 | */
22 | public final class Parameter {
23 |
24 | private final String name;
25 | private final String description;
26 | private final String category;
27 |
28 | public Parameter(String name, String description, String category) {
29 | this.name = name;
30 | this.description = description;
31 | this.category = category;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 |
38 | public String getDescription() {
39 | return description;
40 | }
41 |
42 | public String getCategory() {
43 | return category;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/http_cache_control_directives.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "no-cache",
4 | "description": "",
5 | "category": "REQ/RES"
6 | },
7 | {
8 | "name": "no-store",
9 | "description": "",
10 | "category": "REQ/RES"
11 | },
12 | {
13 | "name": "max-age",
14 | "description": "",
15 | "category": "REQ/RES"
16 | },
17 | {
18 | "name": "max-stale",
19 | "description": "",
20 | "category": "REQ"
21 | },
22 | {
23 | "name": "min-fresh",
24 | "description": "",
25 | "category": "REQ"
26 | },
27 | {
28 | "name": "no-transform",
29 | "description": "",
30 | "category": "REQ/RES"
31 | },
32 | {
33 | "name": "only-if-cached",
34 | "description": "",
35 | "category": "REQ"
36 | },
37 | {
38 | "name": "public",
39 | "description": "",
40 | "category": "RES"
41 | },
42 | {
43 | "name": "private",
44 | "description": "",
45 | "category": "RES"
46 | },
47 | {
48 | "name": "must-revalidate",
49 | "description": "",
50 | "category": "RES"
51 | },
52 | {
53 | "name": "proxy-revalidate",
54 | "description": "",
55 | "category": "RES"
56 | },
57 | {
58 | "name": "s-maxage",
59 | "description": "",
60 | "category": "RES"
61 | }
62 | ]
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/Installer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements;
17 |
18 | import com.junichi11.netbeans.php.enhancements.options.PHPEnhancementsOptions;
19 | import java.util.prefs.Preferences;
20 | import org.openide.modules.ModuleInstall;
21 | import org.openide.util.NbPreferences;
22 |
23 | public class Installer extends ModuleInstall {
24 |
25 | @Override
26 | public void restored() {
27 | Preferences preferences = NbPreferences.forModule(PHPEnhancementsOptions.class);
28 | preferences.addPreferenceChangeListener(evt -> {
29 | if (evt.getKey() == null) {
30 | return;
31 | }
32 | if (PHPEnhancementsOptions.isPHPEnhancementsOptions(evt.getKey())) {
33 | PHPEnhancementsOptions.getInstance().initialize(evt.getKey());
34 | }
35 | });
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/ConvertToStringAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import org.openide.awt.ActionID;
19 | import org.openide.awt.ActionReference;
20 | import org.openide.awt.ActionReferences;
21 | import org.openide.awt.ActionRegistration;
22 | import org.openide.cookies.EditorCookie;
23 | import org.openide.util.NbBundle;
24 |
25 | /**
26 | *
27 | * @author junichi11
28 | */
29 | @ActionID(
30 | category = "Edit",
31 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.HtmlEntitiesToStringAction"
32 | )
33 | @ActionRegistration(
34 | iconBase = "com/junichi11/netbeans/php/enhancements/resources/entities2string16.png",
35 | displayName = "#CTL_HtmlEntitiesToStringAction"
36 | )
37 | @ActionReferences({
38 | @ActionReference(path = "Menu/Edit", position = 3500),
39 | @ActionReference(path = "Editors/text/html/Popup", position = 4400),
40 | @ActionReference(path = "Editors/Toolbars/Default", position = 250010)
41 | })
42 | @NbBundle.Messages("CTL_HtmlEntitiesToStringAction=Html Entities to String")
43 | public class ConvertToStringAction extends ConvertToAction {
44 |
45 | public ConvertToStringAction(EditorCookie context) {
46 | super(context);
47 | }
48 |
49 | @Override
50 | public TYPE getType() {
51 | return TYPE.NAME_ENTITIES_2_STRING;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/envs.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "AUTH_TYPE",
4 | "description": "",
5 | "category": ""
6 | },
7 | {
8 | "name": "CONTENT_LENGTH",
9 | "description": "",
10 | "category": ""
11 | },
12 | {
13 | "name": "CONTENT_TYPE",
14 | "description": "",
15 | "category": ""
16 | },
17 | {
18 | "name": "GATEWAY_INTERFACE",
19 | "description": "",
20 | "category": ""
21 | },
22 | {
23 | "name": "PATH_INFO",
24 | "description": "",
25 | "category": ""
26 | },
27 | {
28 | "name": "PATH_TRANSLATED",
29 | "description": "",
30 | "category": ""
31 | },
32 | {
33 | "name": "QUERY_STRING",
34 | "description": "",
35 | "category": ""
36 | },
37 | {
38 | "name": "REMOTE_ADDR",
39 | "description": "",
40 | "category": ""
41 | },
42 | {
43 | "name": "REMOTE_HOST",
44 | "description": "",
45 | "category": ""
46 | },
47 | {
48 | "name": "REMOTE_IDENT",
49 | "description": "",
50 | "category": ""
51 | },
52 | {
53 | "name": "REMOTE_USER",
54 | "description": "",
55 | "category": ""
56 | },
57 | {
58 | "name": "REQUEST_METHOD",
59 | "description": "",
60 | "category": ""
61 | },
62 | {
63 | "name": "SCRIPT_NAME",
64 | "description": "",
65 | "category": ""
66 | },
67 | {
68 | "name": "SERVER_NAME",
69 | "description": "",
70 | "category": ""
71 | },
72 | {
73 | "name": "SERVER_PORT",
74 | "description": "",
75 | "category": ""
76 | },
77 | {
78 | "name": "SERVER_PROTOCOL",
79 | "description": "",
80 | "category": ""
81 | },
82 | {
83 | "name": "SERVER_SOFTWARE",
84 | "description": "",
85 | "category": ""
86 | }
87 | ]
88 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/ConvertToHtmlEntitiesAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import org.openide.awt.ActionID;
19 | import org.openide.awt.ActionReference;
20 | import org.openide.awt.ActionReferences;
21 | import org.openide.awt.ActionRegistration;
22 | import org.openide.cookies.EditorCookie;
23 | import org.openide.util.NbBundle;
24 |
25 | /**
26 | *
27 | * @author junichi11
28 | */
29 | @ActionID(
30 | category = "Edit",
31 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.ConvertToHtmlEntitiesAction"
32 | )
33 | @ActionRegistration(
34 | iconBase = "com/junichi11/netbeans/php/enhancements/resources/convert2htmlentities16.png",
35 | displayName = "#CTL_ConvertToHtmlEntitiesAction"
36 | )
37 | @ActionReferences({
38 | @ActionReference(path = "Menu/Edit", position = 3400),
39 | @ActionReference(path = "Editors/text/html/Popup", position = 4300),
40 | @ActionReference(path = "Editors/Toolbars/Default", position = 250000)
41 | })
42 | @NbBundle.Messages("CTL_ConvertToHtmlEntitiesAction=Convert to HTML Entities (name)")
43 | public class ConvertToHtmlEntitiesAction extends ConvertToAction {
44 |
45 | public ConvertToHtmlEntitiesAction(EditorCookie context) {
46 | super(context);
47 | }
48 |
49 | @Override
50 | public TYPE getType() {
51 | return TYPE.STRING_2_NAME_ENTITIES;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/nbproject/build-impl.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/SuperGlobalArray.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.editor.completion;
17 |
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import org.netbeans.api.annotations.common.CheckForNull;
21 |
22 | /**
23 | *
24 | * @author junichi11
25 | */
26 | public enum SuperGlobalArray {
27 |
28 | ENV {
29 | @Override
30 | List get(String filter) {
31 | return Parameters.ENVS;
32 | }
33 | };
34 |
35 | private static final HashMap STRING_TO_ENUM = new HashMap<>();
36 |
37 | static {
38 | for (SuperGlobalArray array : values()) {
39 | STRING_TO_ENUM.put(array.toString(), array);
40 | }
41 | }
42 |
43 | /**
44 | * Get candidate list for code completion.
45 | *
46 | * @param paramIndex index of parameter
47 | * @return candidate list for code completion
48 | */
49 | abstract List get(String filter);
50 |
51 | /**
52 | * Get SuperGlobal from string.
53 | *
54 | * @param name super global variable name
55 | * @return {@code SuperGlobalArray} if name exists, {@code null} otherwise.
56 | */
57 | @CheckForNull
58 | public static SuperGlobalArray fromString(String name) {
59 | return STRING_TO_ENUM.get(name);
60 | }
61 |
62 | public String getProperFilter(String filter) {
63 | return filter;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | return String.format("$_%s", this.name()); // NOI18N
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/utils/Utils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.utils;
17 |
18 | import javax.swing.text.AbstractDocument;
19 | import javax.swing.text.Document;
20 | import javax.swing.text.JTextComponent;
21 | import org.netbeans.api.lexer.TokenSequence;
22 | import org.netbeans.modules.editor.NbEditorUtilities;
23 | import org.netbeans.modules.php.editor.lexer.LexUtilities;
24 | import org.netbeans.modules.php.editor.lexer.PHPTokenId;
25 |
26 | /**
27 | *
28 | * @author junichi11
29 | */
30 | public final class Utils {
31 |
32 | public static final String PHP_MIME_TYPE = "text/x-php5"; // NOI18N
33 | public static final String HTML_MIME_TYPE = "text/html"; // NOI18N
34 |
35 | private Utils() {
36 | }
37 |
38 | public static boolean isPHP(JTextComponent editor) {
39 | String mimeType = NbEditorUtilities.getMimeType(editor);
40 | if (mimeType == null || mimeType.isEmpty()) {
41 | return false;
42 | }
43 | return PHP_MIME_TYPE.equals(mimeType);
44 | }
45 |
46 | public static boolean isPHP(Document document) {
47 | return NbEditorUtilities.getMimeType(document).equals(PHP_MIME_TYPE);
48 | }
49 |
50 | public static boolean isHtml(JTextComponent editor) {
51 | String mimeType = NbEditorUtilities.getMimeType(editor);
52 | if (mimeType == null || mimeType.isEmpty()) {
53 | return false;
54 | }
55 | return HTML_MIME_TYPE.equals(mimeType);
56 | }
57 |
58 | public static TokenSequence getTokenSequence(Document document, int offset) {
59 | TokenSequence ts = null;
60 | AbstractDocument ad = (AbstractDocument) document;
61 | ad.readLock();
62 | try {
63 | ts = LexUtilities.getPHPTokenSequence(document, offset);
64 | } finally {
65 | ad.readUnlock();
66 | }
67 | return ts;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/mb_kana_conversions.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "r",
4 | "description": "Convert \"zen-kaku\" alphabets to \"han-kaku\"",
5 | "category": "A->A"
6 | },
7 | {
8 | "name": "R",
9 | "description": "Convert \"han-kaku\" alphabets to \"zen-kaku\"",
10 | "category": "A->A"
11 | },
12 | {
13 | "name": "n",
14 | "description": "Convert \"zen-kaku\" numbers to \"han-kaku\"",
15 | "category": "0->0"
16 | },
17 | {
18 | "name": "N",
19 | "description": "Convert \"han-kaku\" numbers to \"zen-kaku\"",
20 | "category": "0->0"
21 | },
22 | {
23 | "name": "a",
24 | "description": "Convert \"zen-kaku\" alphabets and numbers to \"han-kaku\"",
25 | "category": "A0->A0"
26 | },
27 | {
28 | "name": "A",
29 | "description": "Convert \"han-kaku\" alphabets and numbers to \"zen-kaku\" (Characters included in \"a\", \"A\" options are U+0021 - U+007E excluding U+0022, U+0027, U+005C, U+007E)",
30 | "category": "A0->A0"
31 | },
32 | {
33 | "name": "s",
34 | "description": "Convert \"zen-kaku\" space to \"han-kaku\" (U+3000 -> U+0020)",
35 | "category": "U+3000( )->U+0020( )"
36 | },
37 | {
38 | "name": "S",
39 | "description": "Convert \"han-kaku\" space to \"zen-kaku\" (U+0020 -> U+3000)",
40 | "category": "U+0020( )->U+3000( )"
41 | },
42 | {
43 | "name": "k",
44 | "description": "Convert \"zen-kaku kata-kana\" to \"han-kaku kata-kana\"",
45 | "category": "ア->ア"
46 | },
47 | {
48 | "name": "K",
49 | "description": "Convert \"han-kaku kata-kana\" to \"zen-kaku kata-kana\"",
50 | "category": "ア->ア"
51 | },
52 | {
53 | "name": "h",
54 | "description": "Convert \"zen-kaku hira-gana\" to \"han-kaku kata-kana\"",
55 | "category": "あ->ア"
56 | },
57 | {
58 | "name": "H",
59 | "description": "Convert \"han-kaku kata-kana\" to \"zen-kaku hira-gana\"",
60 | "category": "ア->あ"
61 | },
62 | {
63 | "name": "c",
64 | "description": "Convert \"zen-kaku kata-kana\" to \"zen-kaku hira-gana\"",
65 | "category": "ア->あ"
66 | },
67 | {
68 | "name": "C",
69 | "description": "Convert \"zen-kaku hira-gana\" to \"zen-kaku kata-kana\"",
70 | "category": "あ->ア"
71 | },
72 | {
73 | "name": "V",
74 | "description": "Collapse voiced sound notation and convert them into a character. Use with \"K\",\"H\"",
75 | "category": "ガ->ガ,が"
76 | },
77 | {
78 | "name": "KVC",
79 | "description": "",
80 | "category": ""
81 | },
82 | {
83 | "name": "KVa",
84 | "description": "",
85 | "category": ""
86 | },
87 | {
88 | "name": "HV",
89 | "description": "",
90 | "category": ""
91 | }
92 | ]
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # NetBeans PHP Enhancements Plugin
2 |
3 | Support for some small features.
4 |
5 | ## Features
6 |
7 | - Smart delete (Ctrl + Shift + BACK_SPACE)
8 | - Generate dummy text (Alt + Insert > Dummy Text)
9 | - Generate dummy image
10 | - Convert to PHP short array syntax
11 | - Typing hooks
12 | - Code completion
13 | - Convert String to Html entities (name entities)
14 | - Convert Html eltities to String
15 |
16 | ### Smart delete
17 |
18 | This feature delete string between "" or '', variable name.
19 |
20 | #### delete string
21 |
22 | e.g.
23 |
24 | ```php
25 | ->
26 | ```
27 |
28 | #### delete variable name
29 |
30 | e.g.
31 |
32 | ```php
33 | ->
34 | ```
35 |
36 | ### Generate dummy text
37 |
38 | We can use this feature on PHP and Html editors.
39 | Please set base text on the Dialog. It will be looped with option.
40 |
41 | #### options
42 |
43 | - loop count
44 | - text length
45 |
46 | ### Generate dummy image
47 |
48 | We can generate a dummy image with this feature to specific folder.
49 | Please right-click a folder > `Generate dummy image`
50 |
51 | ### Convert to PHP short array syntax
52 |
53 | Convert array() to [].
54 | Right-click (file|directory) > Convert to php short array syntax
55 |
56 | ### Typing hooks
57 |
58 | If you want to enable this feature, Please check Options(Tools > Options > PHP > Enhancements).
59 |
60 | This is avaible with the following operators:
61 |
62 | - Object operator ->
63 | - Double arrow operator =>
64 |
65 | e.g. type `$this-` => `$this->`, type `array('key' =)` => `array('key' =>)`
66 |
67 | ```php
68 | $this->property;
69 | $array = array('key' => 'value');
70 | $a = ["foo" => "bar"];
71 | $f = fn() => "arrow function";
72 | $result = match ($condition) {
73 | 1, 2 => foo(),
74 | default => bar(),
75 | };
76 | ```
77 |
78 | #### Note:
79 |
80 | - If you want to type `==`, please type `=` after `=>`.
81 | - If you want to type `=`, please delete `>`. (It's difficult to handle all cases correctly...)
82 |
83 | ### Code completion
84 |
85 | #### Constant
86 |
87 | Please check `Tools > Options > PHP > Enhancements`
88 |
89 | - Change name for `define`, `defined` and `const` to uppercase name
90 |
91 | #### Function and method parameter
92 |
93 | - multibyte functions (e.g. mb_convert_encoding())
94 | - header
95 | - ini_set, ini_get, ini_alter, ini_restore
96 | - date_default_timezone_set
97 | - date, date_format
98 | - Datetime::format, DateTimeImmutable::format
99 | - htmlentities, htmlspecialchars
100 | - session_cache_limiter
101 |
102 | Please run code completion (Ctrl + Space) inside quotes.
103 |
104 | e.g.
105 | ```php
106 | {
74 | try {
75 | document.remove(selectionStartPosition, selectedText.length());
76 | document.insertString(selectionStartPosition, convertedString, null);
77 | } catch (BadLocationException ex) {
78 | Exceptions.printStackTrace(ex);
79 | }
80 | });
81 | } catch (IOException ex) {
82 | Exceptions.printStackTrace(ex);
83 | }
84 | }
85 |
86 | private String convert(String selectedText) throws AssertionError {
87 | String convertedString;
88 | switch (getType()) {
89 | case STRING_2_NAME_ENTITIES:
90 | // escape (name entities)
91 | convertedString = StringEscapeUtils.escapeHtml(selectedText);
92 | break;
93 | case NAME_ENTITIES_2_STRING:
94 | convertedString = StringEscapeUtils.unescapeHtml(selectedText);
95 | break;
96 | default:
97 | throw new AssertionError();
98 | }
99 | return convertedString;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/UppercaseCompletionItem.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.editor.completion;
17 |
18 | import java.awt.Color;
19 | import java.awt.Font;
20 | import java.awt.Graphics;
21 | import java.awt.event.KeyEvent;
22 | import javax.swing.ImageIcon;
23 | import javax.swing.text.BadLocationException;
24 | import javax.swing.text.JTextComponent;
25 | import javax.swing.text.StyledDocument;
26 | import org.netbeans.api.editor.completion.Completion;
27 | import org.netbeans.spi.editor.completion.CompletionItem;
28 | import org.netbeans.spi.editor.completion.CompletionTask;
29 | import org.netbeans.spi.editor.completion.support.CompletionUtilities;
30 | import org.openide.text.NbDocument;
31 | import org.openide.util.Exceptions;
32 | import org.openide.util.ImageUtilities;
33 |
34 | /**
35 | *
36 | * @author junichi11
37 | */
38 | public class UppercaseCompletionItem implements CompletionItem {
39 |
40 | private final String text;
41 | private final int offset;
42 | private static final Color fieldColor = Color.decode("0x000000"); // NOI18N
43 | private final ImageIcon icon = ImageUtilities.loadImageIcon("com/junichi11/netbeans/php/enhancements/resources/uppercase16.png", false);
44 |
45 | public UppercaseCompletionItem(String text, int offset) {
46 | this.text = text;
47 | this.offset = offset;
48 | }
49 |
50 | @Override
51 | public void defaultAction(JTextComponent component) {
52 | final StyledDocument document = (StyledDocument) component.getDocument();
53 | NbDocument.runAtomic(document, new Runnable() {
54 |
55 | @Override
56 | public void run() {
57 | try {
58 | document.remove(offset, text.length());
59 | document.insertString(offset, text, null);
60 | Completion.get().hideAll();
61 | } catch (BadLocationException ex) {
62 | Exceptions.printStackTrace(ex);
63 | }
64 | }
65 | });
66 | }
67 |
68 | @Override
69 | public void processKeyEvent(KeyEvent evt) {
70 | }
71 |
72 | @Override
73 | public int getPreferredWidth(Graphics graphics, Font font) {
74 | return CompletionUtilities.getPreferredWidth(text, null, graphics, font);
75 | }
76 |
77 | @Override
78 | public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) {
79 | CompletionUtilities.renderHtml(icon, text, null, g, defaultFont, (selected ? Color.white : fieldColor), width, height, selected);
80 | }
81 |
82 | @Override
83 | public CompletionTask createDocumentationTask() {
84 | return null;
85 | }
86 |
87 | @Override
88 | public CompletionTask createToolTipTask() {
89 | return null;
90 | }
91 |
92 | @Override
93 | public boolean instantSubstitution(JTextComponent component) {
94 | return false;
95 | }
96 |
97 | @Override
98 | public int getSortPriority() {
99 | return 0;
100 | }
101 |
102 | @Override
103 | public CharSequence getSortText() {
104 | return text;
105 | }
106 |
107 | @Override
108 | public CharSequence getInsertPrefix() {
109 | return text;
110 | }
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | com.junichi11.netbeans.modules
5 | netbeans-php-enhancements
6 |
7 | 1.3.2
8 | nbm
9 | NetBeans PHP Enhancements
10 | https://github.com/junichi11/
11 | Support for some small features for PHP.
12 |
13 |
14 | junichi11
15 | Junichi Yamamoto
16 | https://github.com/junichi11
17 |
18 |
19 |
20 | scm:git:https://github.com/junichi11/netbeans-php-enhancements.git
21 | scm:git:https://github.com/junichi11/netbeans-php-enhancements.git
22 | https://github.com/junichi11/netbeans-php-enhancements
23 | HEAD
24 |
25 |
26 |
27 | Apache License, Version 2.0
28 | https://www.apache.org/licenses/LICENSE-2.0
29 |
30 |
31 |
32 |
33 | ossrh
34 | https://oss.sonatype.org/content/repositories/snapshots
35 |
36 |
37 | ossrh
38 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
39 |
40 |
41 |
42 |
43 |
44 | org.apache.maven.plugins
45 | maven-deploy-plugin
46 | 3.0.0-M1
47 |
48 |
49 | org.sonatype.plugins
50 | nexus-staging-maven-plugin
51 | 1.6.7
52 | true
53 |
54 | ossrh
55 | https://oss.sonatype.org/
56 | true
57 |
58 |
59 |
60 | org.apache.maven.plugins
61 | maven-compiler-plugin
62 | 3.8.1
63 |
64 | 1.8
65 | 1.8
66 |
67 |
68 |
69 | org.apache.maven.plugins
70 | maven-jar-plugin
71 | 3.1.2
72 |
73 |
74 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF
75 |
76 |
77 |
78 |
79 | org.apache.maven.plugins
80 | maven-gpg-plugin
81 | 1.6
82 |
83 |
84 | sign-artifacts
85 | verify
86 |
87 | sign
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/generator/DummyTextGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.editor.generator;
17 |
18 | import com.junichi11.netbeans.php.enhancements.editor.generator.ui.DummyTextPanel;
19 | import java.awt.Dialog;
20 | import java.util.Collections;
21 | import java.util.List;
22 | import javax.swing.text.Document;
23 | import javax.swing.text.JTextComponent;
24 | import org.netbeans.api.editor.mimelookup.MimeRegistration;
25 | import org.netbeans.api.editor.mimelookup.MimeRegistrations;
26 | import org.netbeans.lib.editor.codetemplates.api.CodeTemplate;
27 | import org.netbeans.lib.editor.codetemplates.api.CodeTemplateManager;
28 | import org.netbeans.spi.editor.codegen.CodeGenerator;
29 | import org.netbeans.spi.editor.codegen.CodeGeneratorContextProvider;
30 | import org.openide.DialogDescriptor;
31 | import org.openide.DialogDisplayer;
32 | import org.openide.util.Lookup;
33 | import org.openide.util.NbBundle;
34 |
35 | public class DummyTextGenerator implements CodeGenerator {
36 |
37 | JTextComponent textComp;
38 |
39 | /**
40 | *
41 | * @param context containing JTextComponent and possibly other items
42 | * registered by {@link CodeGeneratorContextProvider}
43 | */
44 | private DummyTextGenerator(Lookup context) { // Good practice is not to save Lookup outside ctor
45 | textComp = context.lookup(JTextComponent.class);
46 | }
47 |
48 | @MimeRegistrations({
49 | @MimeRegistration(mimeType = "text/x-php5", service = CodeGenerator.Factory.class),
50 | @MimeRegistration(mimeType = "text/html", service = CodeGenerator.Factory.class)
51 | })
52 | public static class Factory implements CodeGenerator.Factory {
53 |
54 | @Override
55 | public List extends CodeGenerator> create(Lookup context) {
56 | JTextComponent jtc = context.lookup(JTextComponent.class);
57 | if (jtc == null) {
58 | return Collections.emptyList();
59 | }
60 | return Collections.singletonList(new DummyTextGenerator(context));
61 | }
62 | }
63 |
64 | /**
65 | * The name which will be inserted inside Insert Code dialog
66 | */
67 | @NbBundle.Messages("DummyTextGenerator.DisplayName=Dummy Text")
68 | @Override
69 | public String getDisplayName() {
70 | return Bundle.DummyTextGenerator_DisplayName();
71 | }
72 |
73 | /**
74 | * This will be invoked when user chooses this Generator from Insert Code
75 | * dialog
76 | */
77 | @Override
78 | public void invoke() {
79 | Document document = textComp.getDocument();
80 | if (document == null) {
81 | return;
82 | }
83 |
84 | // create dialog
85 | DummyTextPanel dummyTextPanel = DummyTextPanel.getDefault();
86 | DialogDescriptor descriptor = new DialogDescriptor(dummyTextPanel, Bundle.DummyTextGenerator_DisplayName());
87 | Dialog dialog = DialogDisplayer.getDefault().createDialog(descriptor);
88 | dialog.setVisible(true);
89 | dialog.dispose();
90 |
91 | if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
92 | // text for inserting
93 | String text = dummyTextPanel.getInsertText();
94 | if (text == null || text.isEmpty()) {
95 | return;
96 | }
97 |
98 | // insert code with CodeTemplateManager
99 | CodeTemplateManager templateManager = CodeTemplateManager.get(document);
100 | CodeTemplate codeTemplate = templateManager.createTemporary(text);
101 | codeTemplate.insert(textComp);
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/test/unit/src/com/junichi11/netbeans/php/enhancements/ui/actions/ConvertToPhpShortArraySyntaxActionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import java.io.File;
19 | import java.io.IOException;
20 | import javax.swing.text.BadLocationException;
21 | import javax.swing.text.DefaultStyledDocument;
22 | import org.junit.After;
23 | import org.junit.AfterClass;
24 | import org.junit.Before;
25 | import org.junit.BeforeClass;
26 | import org.junit.Test;
27 | import org.netbeans.api.lexer.Language;
28 | import org.netbeans.junit.NbTestCase;
29 | import org.netbeans.modules.php.editor.lexer.PHPTokenId;
30 | import org.openide.filesystems.FileObject;
31 | import org.openide.filesystems.FileUtil;
32 |
33 | /**
34 | *
35 | * @author junichi11
36 | */
37 | public class ConvertToPhpShortArraySyntaxActionTest extends NbTestCase {
38 |
39 | private FileObject testFile;
40 | private final StringBuilder expected = new StringBuilder();
41 | private final StringBuilder target = new StringBuilder();
42 |
43 | public ConvertToPhpShortArraySyntaxActionTest(String name) {
44 | super(name);
45 | }
46 |
47 | @BeforeClass
48 | public static void setUpClass() {
49 | }
50 |
51 | @AfterClass
52 | public static void tearDownClass() {
53 | }
54 |
55 | @Before
56 | @Override
57 | public void setUp() {
58 | }
59 |
60 | @After
61 | @Override
62 | public void tearDown() {
63 | target.setLength(0);
64 | expected.setLength(0);
65 | testFile = null;
66 | }
67 |
68 | /**
69 | * Test of convert method, of class ConvertToPhpShortArraySyntaxAction.
70 | *
71 | * @throws javax.swing.text.BadLocationException
72 | * @throws java.io.IOException
73 | */
74 | @Test
75 | public void testConvert() throws BadLocationException, IOException {
76 | testFile("ArraySyntaxTest.php");
77 | }
78 |
79 | /**
80 | * Test of convert method, of class ConvertToPhpShortArraySyntaxAction.
81 | *
82 | * @throws javax.swing.text.BadLocationException
83 | * @throws java.io.IOException
84 | */
85 | @Test
86 | public void testConvertArrayCast() throws BadLocationException, IOException {
87 | testFile("ArraySyntaxCastTest.php");
88 | }
89 |
90 | /**
91 | * Test of convert method, of class ConvertToPhpShortArraySyntaxAction.
92 | *
93 | * @throws javax.swing.text.BadLocationException
94 | * @throws java.io.IOException
95 | */
96 | @Test
97 | public void testConvertArrayType() throws BadLocationException, IOException {
98 | testFile("ArraySyntaxTypeTest.php");
99 | }
100 |
101 | /**
102 | * Test of convert method, of class ConvertToPhpShortArraySyntaxAction.
103 | *
104 | * @throws javax.swing.text.BadLocationException
105 | * @throws java.io.IOException
106 | * @see https://github.com/junichi11/netbeans-php-enhancements/issues/4
107 | */
108 | @Test
109 | public void testIssue4() throws BadLocationException, IOException {
110 | testFile("ArraySyntaxIssue4Test.php");
111 | }
112 |
113 | private void testFile(String fileName) throws IOException, BadLocationException {
114 | File dataDir = getDataDir();
115 | testFile = FileUtil.toFileObject(new File(dataDir, fileName));
116 | boolean isExpected = false;
117 | for (String line : testFile.asLines("UTF-8")) {
118 | if (line.isEmpty()) {
119 | continue;
120 | }
121 | if (line.startsWith("// expected")) {
122 | isExpected = true;
123 | continue;
124 | }
125 | if (isExpected) {
126 | expected.append(line).append("\n");
127 | } else {
128 | target.append(line).append("\n");
129 | }
130 | }
131 |
132 | DefaultStyledDocument document = new DefaultStyledDocument();
133 | document.putProperty(Language.class, PHPTokenId.language());
134 | document.insertString(0, target.toString(), null);
135 | ConvertToPhpShortArraySyntaxAction instance = new ConvertToPhpShortArraySyntaxAction(null);
136 | instance.convert(document);
137 | assertEquals(expected.toString(), document.getText(0, document.getLength()));
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/charsets.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "ISO-8859-1",
4 | "description": "Western European, Latin-1.",
5 | "category": ""
6 | },
7 | {
8 | "name": "ISO8859-1",
9 | "description": "Western European, Latin-1.",
10 | "category": "Alias"
11 | },
12 | {
13 | "name": "ISO-8859-5",
14 | "description": "Little used cyrillic charset (Latin/Cyrillic).",
15 | "category": ""
16 | },
17 | {
18 | "name": "ISO8859-5",
19 | "description": "Little used cyrillic charset (Latin/Cyrillic).",
20 | "category": "Alias"
21 | },
22 | {
23 | "name": "ISO-8859-15",
24 | "description": "Western European, Latin-9. Adds the Euro sign, French and Finnish letters missing in Latin-1 (ISO-8859-1).",
25 | "category": ""
26 | },
27 | {
28 | "name": "ISO8859-15",
29 | "description": "Western European, Latin-9. Adds the Euro sign, French and Finnish letters missing in Latin-1 (ISO-8859-1).",
30 | "category": "Alias"
31 | },
32 | {
33 | "name": "UTF-8",
34 | "description": "ASCII compatible multi-byte 8-bit Unicode.",
35 | "category": ""
36 | },
37 | {
38 | "name": "cp866",
39 | "description": "DOS-specific Cyrillic charset.",
40 | "category": ""
41 | },
42 | {
43 | "name": "ibm866",
44 | "description": "DOS-specific Cyrillic charset.",
45 | "category": "Alias"
46 | },
47 | {
48 | "name": "866",
49 | "description": "DOS-specific Cyrillic charset.",
50 | "category": "Alias"
51 | },
52 | {
53 | "name": "cp1251",
54 | "description": "Windows-specific Cyrillic charset.",
55 | "category": ""
56 | },
57 | {
58 | "name": "Windows-1251",
59 | "description": "Windows-specific Cyrillic charset.",
60 | "category": "Alias"
61 | },
62 | {
63 | "name": "win-1251",
64 | "description": "Windows-specific Cyrillic charset.",
65 | "category": "Alias"
66 | },
67 | {
68 | "name": "1251",
69 | "description": "Windows-specific Cyrillic charset.",
70 | "category": "Alias"
71 | },
72 | {
73 | "name": "cp1252",
74 | "description": "Windows specific charset for Western European.",
75 | "category": ""
76 | },
77 | {
78 | "name": "Windows-1252",
79 | "description": "Windows specific charset for Western European.",
80 | "category": "Alias"
81 | },
82 | {
83 | "name": "1252",
84 | "description": "Windows specific charset for Western European.",
85 | "category": "Alias"
86 | },
87 | {
88 | "name": "KOI8-R",
89 | "description": "Russian.",
90 | "category": ""
91 | },
92 | {
93 | "name": "koi8-ru",
94 | "description": "Russian.",
95 | "category": "Alias"
96 | },
97 | {
98 | "name": "koi8r",
99 | "description": "Russian.",
100 | "category": "Alias"
101 | },
102 | {
103 | "name": "BIG5",
104 | "description": "Traditional Chinese, mainly used in Taiwan.",
105 | "category": ""
106 | },
107 | {
108 | "name": "950",
109 | "description": "Traditional Chinese, mainly used in Taiwan.",
110 | "category": "Alias"
111 | },
112 | {
113 | "name": "GB2312",
114 | "description": "Simplified Chinese, national standard character set.",
115 | "category": ""
116 | },
117 | {
118 | "name": "936",
119 | "description": "Simplified Chinese, national standard character set.",
120 | "category": "Alias"
121 | },
122 | {
123 | "name": "BIG5-HKSCS",
124 | "description": "Big5 with Hong Kong extensions, Traditional Chinese.",
125 | "category": ""
126 | },
127 | {
128 | "name": "Shift_JIS",
129 | "description": "Japanese",
130 | "category": ""
131 | },
132 | {
133 | "name": "SJIS",
134 | "description": "Japanese",
135 | "category": "Alias"
136 | },
137 | {
138 | "name": "SJIS-win",
139 | "description": "Japanese",
140 | "category": "Alias"
141 | },
142 | {
143 | "name": "cp932",
144 | "description": "Japanese",
145 | "category": "Alias"
146 | },
147 | {
148 | "name": "932",
149 | "description": "Japanese",
150 | "category": "Alias"
151 | },
152 | {
153 | "name": "EUC-JP",
154 | "description": "Japanese",
155 | "category": ""
156 | },
157 | {
158 | "name": "EUCJP",
159 | "description": "Japanese",
160 | "category": "Alias"
161 | },
162 | {
163 | "name": "eucJP-win",
164 | "description": "Japanese",
165 | "category": "Alias"
166 | },
167 | {
168 | "name": "MacRoman",
169 | "description": "Charset that was used by Mac OS.",
170 | "category": ""
171 | }
172 | ]
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/http_status_codes.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "100 Continue",
4 | "description": "",
5 | "category": "HTTP STATUS CODE"
6 | },
7 | {
8 | "name": "101 Switching Protocols",
9 | "description": "",
10 | "category": "HTTP STATUS CODE"
11 | },
12 | {
13 | "name": "200 OK",
14 | "description": "",
15 | "category": "HTTP STATUS CODE"
16 | },
17 | {
18 | "name": "201 Created",
19 | "description": "",
20 | "category": "HTTP STATUS CODE"
21 | },
22 | {
23 | "name": "202 Accepted",
24 | "description": "",
25 | "category": "HTTP STATUS CODE"
26 | },
27 | {
28 | "name": "203 Non-Authoritative Information",
29 | "description": "",
30 | "category": "HTTP STATUS CODE"
31 | },
32 | {
33 | "name": "204 No Content",
34 | "description": "",
35 | "category": "HTTP STATUS CODE"
36 | },
37 | {
38 | "name": "205 Reset Content",
39 | "description": "",
40 | "category": "HTTP STATUS CODE"
41 | },
42 | {
43 | "name": "206 Partial Content",
44 | "description": "",
45 | "category": "HTTP STATUS CODE"
46 | },
47 | {
48 | "name": "300 Multiple Choices",
49 | "description": "",
50 | "category": "HTTP STATUS CODE"
51 | },
52 | {
53 | "name": "301 Moved Permanently",
54 | "description": "",
55 | "category": "HTTP STATUS CODE"
56 | },
57 | {
58 | "name": "302 Found",
59 | "description": "",
60 | "category": "HTTP STATUS CODE"
61 | },
62 | {
63 | "name": "303 See Other",
64 | "description": "",
65 | "category": "HTTP STATUS CODE"
66 | },
67 | {
68 | "name": "304 Not Modified",
69 | "description": "",
70 | "category": "HTTP STATUS CODE"
71 | },
72 | {
73 | "name": "305 Use Proxy",
74 | "description": "",
75 | "category": "HTTP STATUS CODE"
76 | },
77 | {
78 | "name": "307 Temporary Redirect",
79 | "description": "",
80 | "category": "HTTP STATUS CODE"
81 | },
82 | {
83 | "name": "400 Bad Request",
84 | "description": "",
85 | "category": "HTTP STATUS CODE"
86 | },
87 | {
88 | "name": "401 Unauthorized",
89 | "description": "",
90 | "category": "HTTP STATUS CODE"
91 | },
92 | {
93 | "name": "402 Payment Required",
94 | "description": "",
95 | "category": "HTTP STATUS CODE"
96 | },
97 | {
98 | "name": "403 Forbidden",
99 | "description": "",
100 | "category": "HTTP STATUS CODE"
101 | },
102 | {
103 | "name": "404 Not Found",
104 | "description": "",
105 | "category": "HTTP STATUS CODE"
106 | },
107 | {
108 | "name": "405 Method Not Allowed",
109 | "description": "",
110 | "category": "HTTP STATUS CODE"
111 | },
112 | {
113 | "name": "406 Not Acceptable",
114 | "description": "",
115 | "category": "HTTP STATUS CODE"
116 | },
117 | {
118 | "name": "407 Proxy Authentication Required",
119 | "description": "",
120 | "category": "HTTP STATUS CODE"
121 | },
122 | {
123 | "name": "408 Request Timeout",
124 | "description": "",
125 | "category": "HTTP STATUS CODE"
126 | },
127 | {
128 | "name": "409 Conflict",
129 | "description": "",
130 | "category": "HTTP STATUS CODE"
131 | },
132 | {
133 | "name": "410 Gone",
134 | "description": "",
135 | "category": "HTTP STATUS CODE"
136 | },
137 | {
138 | "name": "411 Length Required",
139 | "description": "",
140 | "category": "HTTP STATUS CODE"
141 | },
142 | {
143 | "name": "412 Precondition Failed",
144 | "description": "",
145 | "category": "HTTP STATUS CODE"
146 | },
147 | {
148 | "name": "413 Request Entity Too Large",
149 | "description": "",
150 | "category": "HTTP STATUS CODE"
151 | },
152 | {
153 | "name": "414 Request-URI Too Long",
154 | "description": "",
155 | "category": "HTTP STATUS CODE"
156 | },
157 | {
158 | "name": "415 Unsupported Media Type",
159 | "description": "",
160 | "category": "HTTP STATUS CODE"
161 | },
162 | {
163 | "name": "416 Requested Range Not Satisfiable",
164 | "description": "",
165 | "category": "HTTP STATUS CODE"
166 | },
167 | {
168 | "name": "417 Expectation Failed",
169 | "description": "",
170 | "category": "HTTP STATUS CODE"
171 | },
172 | {
173 | "name": "500 Internal Server Error",
174 | "description": "",
175 | "category": "HTTP STATUS CODE"
176 | },
177 | {
178 | "name": "501 Not Implemented",
179 | "description": "",
180 | "category": "HTTP STATUS CODE"
181 | },
182 | {
183 | "name": "502 Bad Gateway",
184 | "description": "",
185 | "category": "HTTP STATUS CODE"
186 | },
187 | {
188 | "name": "503 Service Unavailable",
189 | "description": "",
190 | "category": "HTTP STATUS CODE"
191 | },
192 | {
193 | "name": "504 Gateway Timeout",
194 | "description": "",
195 | "category": "HTTP STATUS CODE"
196 | },
197 | {
198 | "name": "505 HTTP Version Not Supported",
199 | "description": "",
200 | "category": "HTTP STATUS CODE"
201 | }
202 | ]
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/http_header_responses.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "Access-Control-Allow-Origin: ",
4 | "description": "",
5 | "category": ""
6 | },
7 | {
8 | "name": "Accept-Ranges: ",
9 | "description": "",
10 | "category": ""
11 | },
12 | {
13 | "name": "Age: ",
14 | "description": "",
15 | "category": ""
16 | },
17 | {
18 | "name": "Allow: ",
19 | "description": "",
20 | "category": ""
21 | },
22 | {
23 | "name": "Cache-Control: ",
24 | "description": "",
25 | "category": ""
26 | },
27 | {
28 | "name": "Connection: ",
29 | "description": "",
30 | "category": ""
31 | },
32 | {
33 | "name": "Content-Encoding: ",
34 | "description": "",
35 | "category": ""
36 | },
37 | {
38 | "name": "Content-Language: ",
39 | "description": "",
40 | "category": ""
41 | },
42 | {
43 | "name": "Content-Length: ",
44 | "description": "",
45 | "category": ""
46 | },
47 | {
48 | "name": "Content-Location: ",
49 | "description": "",
50 | "category": ""
51 | },
52 | {
53 | "name": "Content-MD5: ",
54 | "description": "",
55 | "category": ""
56 | },
57 | {
58 | "name": "Content-Disposition: ",
59 | "description": "",
60 | "category": ""
61 | },
62 | {
63 | "name": "Content-Range: ",
64 | "description": "",
65 | "category": ""
66 | },
67 | {
68 | "name": "Content-Type: ",
69 | "description": "",
70 | "category": ""
71 | },
72 | {
73 | "name": "Date: ",
74 | "description": "",
75 | "category": ""
76 | },
77 | {
78 | "name": "ETag: ",
79 | "description": "",
80 | "category": ""
81 | },
82 | {
83 | "name": "Expires: ",
84 | "description": "",
85 | "category": ""
86 | },
87 | {
88 | "name": "Last-Modified: ",
89 | "description": "",
90 | "category": ""
91 | },
92 | {
93 | "name": "Link: ",
94 | "description": "",
95 | "category": ""
96 | },
97 | {
98 | "name": "Location: ",
99 | "description": "",
100 | "category": ""
101 | },
102 | {
103 | "name": "P3P: ",
104 | "description": "",
105 | "category": ""
106 | },
107 | {
108 | "name": "Pragma: ",
109 | "description": "",
110 | "category": ""
111 | },
112 | {
113 | "name": "Proxy-Authenticate: ",
114 | "description": "",
115 | "category": ""
116 | },
117 | {
118 | "name": "Refresh: ",
119 | "description": "",
120 | "category": ""
121 | },
122 | {
123 | "name": "Retry-After: ",
124 | "description": "",
125 | "category": ""
126 | },
127 | {
128 | "name": "Server: ",
129 | "description": "",
130 | "category": ""
131 | },
132 | {
133 | "name": "Set-Cookie: ",
134 | "description": "",
135 | "category": ""
136 | },
137 | {
138 | "name": "Status: ",
139 | "description": "",
140 | "category": ""
141 | },
142 | {
143 | "name": "Strict-Transport-Security: ",
144 | "description": "",
145 | "category": ""
146 | },
147 | {
148 | "name": "Trailer: ",
149 | "description": "",
150 | "category": ""
151 | },
152 | {
153 | "name": "Transfer-Encoding: ",
154 | "description": "",
155 | "category": ""
156 | },
157 | {
158 | "name": "Upgrade: ",
159 | "description": "",
160 | "category": ""
161 | },
162 | {
163 | "name": "Vary: ",
164 | "description": "",
165 | "category": ""
166 | },
167 | {
168 | "name": "Via",
169 | "description": "",
170 | "category": ""
171 | },
172 | {
173 | "name": "Warning: ",
174 | "description": "",
175 | "category": ""
176 | },
177 | {
178 | "name": "WWW-Authenticate: ",
179 | "description": "",
180 | "category": ""
181 | },
182 | {
183 | "name": "X-Frame-Options: ",
184 | "description": "",
185 | "category": ""
186 | },
187 | {
188 | "name": "X-XSS-Protection: ",
189 | "description": "",
190 | "category": ""
191 | },
192 | {
193 | "name": "Content-Security-Policy: ",
194 | "description": "",
195 | "category": ""
196 | },
197 | {
198 | "name": "X-Content-Security-Policy: ",
199 | "description": "",
200 | "category": ""
201 | },
202 | {
203 | "name": "X-WebKit-CSP: ",
204 | "description": "",
205 | "category": ""
206 | },
207 | {
208 | "name": "X-Content-Type-Options: ",
209 | "description": "",
210 | "category": ""
211 | },
212 | {
213 | "name": "X-Powered-By: ",
214 | "description": "",
215 | "category": ""
216 | },
217 | {
218 | "name": "X-UA-Compatible: ",
219 | "description": "",
220 | "category": ""
221 | },
222 | {
223 | "name": "HTTP/1.0",
224 | "description": "",
225 | "category": ""
226 | },
227 | {
228 | "name": "HTTP/1.1",
229 | "description": "",
230 | "category": ""
231 | }
232 | ]
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/UppercaseCompletionProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.editor.completion;
17 |
18 | import com.junichi11.netbeans.php.enhancements.options.PHPEnhancementsOptions;
19 | import com.junichi11.netbeans.php.enhancements.utils.Utils;
20 | import java.util.Arrays;
21 | import java.util.List;
22 | import javax.swing.text.Document;
23 | import javax.swing.text.JTextComponent;
24 | import org.netbeans.api.editor.mimelookup.MimeRegistration;
25 | import org.netbeans.api.lexer.Token;
26 | import org.netbeans.api.lexer.TokenSequence;
27 | import org.netbeans.modules.php.editor.lexer.LexUtilities;
28 | import org.netbeans.modules.php.editor.lexer.PHPTokenId;
29 | import org.netbeans.spi.editor.completion.CompletionProvider;
30 | import org.netbeans.spi.editor.completion.CompletionResultSet;
31 | import org.netbeans.spi.editor.completion.CompletionTask;
32 | import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery;
33 | import org.netbeans.spi.editor.completion.support.AsyncCompletionTask;
34 |
35 | /**
36 | *
37 | * @author junichi11
38 | */
39 | @MimeRegistration(mimeType = Utils.PHP_MIME_TYPE, service = CompletionProvider.class)
40 | public class UppercaseCompletionProvider implements CompletionProvider {
41 |
42 | public UppercaseCompletionProvider() {
43 | }
44 |
45 | @Override
46 | public CompletionTask createTask(int queryType, JTextComponent component) {
47 | if (queryType != CompletionProvider.COMPLETION_QUERY_TYPE) {
48 | return null;
49 | }
50 | return new AsyncCompletionTask(new AsyncCompletionQueryImpl(), component);
51 | }
52 |
53 | @Override
54 | public int getAutoQueryTypes(JTextComponent component, String typedText) {
55 | return 0;
56 | }
57 |
58 | static class AsyncCompletionQueryImpl extends AsyncCompletionQuery {
59 |
60 | private static final List CONST_IGNORE_LIST = Arrays.asList(PHPTokenId.WHITESPACE, PHPTokenId.PHP_STRING);
61 | private static final List DEFINE_IGNORE_LIST = Arrays.asList(PHPTokenId.WHITESPACE, PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING, PHPTokenId.PHP_TOKEN);
62 |
63 | public AsyncCompletionQueryImpl() {
64 | }
65 |
66 | @Override
67 | protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
68 | try {
69 | PHPEnhancementsOptions options = PHPEnhancementsOptions.getInstance();
70 | if (options.isToUppercaseConst()) {
71 | if (checkConst(resultSet, doc, caretOffset)) {
72 | return;
73 | }
74 | }
75 |
76 | if (options.isToUppercaseDefine()) {
77 | checkDefine(resultSet, doc, caretOffset);
78 | }
79 | } finally {
80 | resultSet.finish();
81 | }
82 | }
83 |
84 | private boolean checkConst(CompletionResultSet resultSet, Document doc, int caretOffset) {
85 | TokenSequence ts = Utils.getTokenSequence(doc, caretOffset);
86 | ts.move(caretOffset);
87 | ts.movePrevious();
88 | Token caretToken = ts.token();
89 | if (caretToken == null) {
90 | return false;
91 | }
92 | String caretText = caretToken.text().toString();
93 | int startPosition = ts.offset();
94 | if (caretText.equals("const") || caretText.equals(caretText.toUpperCase())) { // NOI18N
95 | return false;
96 | }
97 | Token extends PHPTokenId> findPreviousToken = LexUtilities.findPrevious(ts, CONST_IGNORE_LIST);
98 | if (findPreviousToken == null || findPreviousToken.id() != PHPTokenId.PHP_CONST) {
99 | return false;
100 | }
101 | resultSet.addItem(new UppercaseCompletionItem(caretText.toUpperCase(), startPosition));
102 | return true;
103 | }
104 |
105 | private boolean checkDefine(CompletionResultSet resultSet, Document doc, int caretOffset) {
106 | TokenSequence ts = Utils.getTokenSequence(doc, caretOffset);
107 | ts.move(caretOffset);
108 | ts.moveNext();
109 | Token caretToken = ts.token();
110 | if (caretToken == null) {
111 | return false;
112 | }
113 | String caretText = caretToken.text().toString();
114 | int startPosition = ts.offset();
115 | if (caretText.equals(caretText.toUpperCase()) || caretToken.id() != PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING) {
116 | return false;
117 | }
118 | Token extends PHPTokenId> findPreviousToken = LexUtilities.findPrevious(ts, DEFINE_IGNORE_LIST);
119 | if (findPreviousToken == null || findPreviousToken.id() != PHPTokenId.PHP_STRING) {
120 | return false;
121 | }
122 | String tokenText = findPreviousToken.text().toString();
123 | if (!tokenText.equals("define") && !tokenText.equals("defined")) { // NOI18N
124 | return false;
125 | }
126 | resultSet.addItem(new UppercaseCompletionItem(caretText.toUpperCase(), startPosition));
127 | return true;
128 | }
129 |
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/PHPEnhancementsOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.options;
17 |
18 | import java.util.prefs.Preferences;
19 | import org.openide.util.NbPreferences;
20 |
21 | /**
22 | *
23 | * @author junichi11
24 | */
25 | public final class PHPEnhancementsOptions {
26 |
27 | private static final PHPEnhancementsOptions INSTANCE = new PHPEnhancementsOptions();
28 | private static final String OBJECT_OPERATOR_TYPINGHOOK = "object.operator.typinghook"; // NOI18N
29 | private static final String DOUBLE_ARROW_TYPINGHOOK = "double.arrow.operator.typinghook"; // NOI18N
30 | private static final String TO_UPPERCASE_CONST = "uppercase.const"; // NOI18N
31 | private static final String TO_UPPERCASE_DEFINE = "uppercase.define"; // NOI18N
32 | private static final String PARAMETERS_CODE_COMPLETION = "parameters.code.completion"; // NOI18N
33 |
34 | // cache
35 | private static volatile boolean isObjectOperator;
36 | private static volatile boolean isDoubleArrowOperator;
37 | private static volatile boolean isToUppercaseConst;
38 | private static volatile boolean isToUppercaseDefine;
39 | private static volatile boolean isParametersCodeCompletion;
40 |
41 | static {
42 | INSTANCE.initialize(OBJECT_OPERATOR_TYPINGHOOK);
43 | INSTANCE.initialize(DOUBLE_ARROW_TYPINGHOOK);
44 | INSTANCE.initialize(TO_UPPERCASE_CONST);
45 | INSTANCE.initialize(TO_UPPERCASE_DEFINE);
46 | INSTANCE.initialize(PARAMETERS_CODE_COMPLETION);
47 | }
48 |
49 | public static PHPEnhancementsOptions getInstance() {
50 | return INSTANCE;
51 | }
52 |
53 | private PHPEnhancementsOptions() {
54 | }
55 |
56 | public static boolean isPHPEnhancementsOptions(String key) {
57 | return OBJECT_OPERATOR_TYPINGHOOK.equals(key)
58 | || DOUBLE_ARROW_TYPINGHOOK.equals(key)
59 | || TO_UPPERCASE_CONST.equals(key)
60 | || TO_UPPERCASE_DEFINE.equals(key)
61 | || PARAMETERS_CODE_COMPLETION.equals(key);
62 | }
63 |
64 | public void initialize(String key) {
65 | switch (key) {
66 | case OBJECT_OPERATOR_TYPINGHOOK:
67 | isObjectOperator = isObjectOperator(true);
68 | break;
69 | case DOUBLE_ARROW_TYPINGHOOK:
70 | isDoubleArrowOperator = isDoubleArrowOperator(true);
71 | break;
72 | case TO_UPPERCASE_CONST:
73 | isToUppercaseConst = isToUppercaseConst(true);
74 | break;
75 | case TO_UPPERCASE_DEFINE:
76 | isToUppercaseDefine = isToUppercaseDefine(true);
77 | break;
78 | case PARAMETERS_CODE_COMPLETION:
79 | isParametersCodeCompletion = isParametersCodeCompletion(true);
80 | break;
81 | default:
82 | break;
83 | }
84 | }
85 |
86 | public boolean isObjectOperator(boolean force) {
87 | if (force) {
88 | return getPreferences().getBoolean(OBJECT_OPERATOR_TYPINGHOOK, false);
89 | }
90 | return isObjectOperator;
91 | }
92 |
93 | public boolean isObjectOperator() {
94 | return isObjectOperator(false);
95 | }
96 |
97 | public void setObjectOperator(boolean isObjectOperator) {
98 | getPreferences().putBoolean(OBJECT_OPERATOR_TYPINGHOOK, isObjectOperator);
99 | }
100 |
101 | public boolean isDoubleArrowOperator(boolean force) {
102 | if (force) {
103 | return getPreferences().getBoolean(DOUBLE_ARROW_TYPINGHOOK, false);
104 | }
105 | return isDoubleArrowOperator;
106 | }
107 |
108 | public boolean isDoubleArrowOperator() {
109 | return isDoubleArrowOperator(false);
110 | }
111 |
112 | public void setDoubleArrowOperator(boolean isDoubleArrowOperator) {
113 | getPreferences().putBoolean(DOUBLE_ARROW_TYPINGHOOK, isDoubleArrowOperator);
114 | }
115 |
116 | public boolean isToUppercaseConst(boolean force) {
117 | if (force) {
118 | return getPreferences().getBoolean(TO_UPPERCASE_CONST, false);
119 | }
120 | return isToUppercaseConst;
121 | }
122 |
123 | public boolean isToUppercaseConst() {
124 | return isToUppercaseConst(false);
125 | }
126 |
127 | public void setToUppercaseConst(boolean isToUppercaseConst) {
128 | getPreferences().putBoolean(TO_UPPERCASE_CONST, isToUppercaseConst);
129 | }
130 |
131 | public boolean isToUppercaseDefine(boolean force) {
132 | if (force) {
133 | return getPreferences().getBoolean(TO_UPPERCASE_DEFINE, false);
134 | }
135 | return isToUppercaseDefine;
136 | }
137 |
138 | public boolean isToUppercaseDefine() {
139 | return isToUppercaseDefine(false);
140 | }
141 |
142 | public void setToUppercaseDefine(boolean isToUppercaseDefine) {
143 | getPreferences().putBoolean(TO_UPPERCASE_DEFINE, isToUppercaseDefine);
144 | }
145 |
146 | public boolean isParametersCodeCompletion(boolean force) {
147 | if (force) {
148 | return getPreferences().getBoolean(PARAMETERS_CODE_COMPLETION, true);
149 | }
150 | return isParametersCodeCompletion;
151 | }
152 |
153 | public boolean isParametersCodeCompletion() {
154 | return isParametersCodeCompletion(false);
155 | }
156 |
157 | public void setParametersCodeCompletion(boolean isParameters) {
158 | getPreferences().putBoolean(PARAMETERS_CODE_COMPLETION, isParameters);
159 | }
160 |
161 | private Preferences getPreferences() {
162 | return NbPreferences.forModule(PHPEnhancementsOptions.class);
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/GenerateDummyImageAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import java.awt.Color;
19 | import java.awt.Font;
20 | import java.awt.Graphics2D;
21 | import java.awt.RenderingHints;
22 | import java.awt.event.ActionEvent;
23 | import java.awt.event.ActionListener;
24 | import java.awt.geom.Rectangle2D;
25 | import java.awt.image.BufferedImage;
26 | import java.io.IOException;
27 | import java.util.logging.Level;
28 | import java.util.logging.Logger;
29 | import javax.imageio.ImageIO;
30 | import org.openide.DialogDescriptor;
31 | import org.openide.DialogDisplayer;
32 | import org.openide.NotifyDescriptor;
33 | import org.openide.loaders.DataObject;
34 | import org.openide.awt.ActionID;
35 | import org.openide.awt.ActionReference;
36 | import org.openide.awt.ActionRegistration;
37 | import org.openide.filesystems.FileObject;
38 | import org.openide.filesystems.FileUtil;
39 | import org.openide.util.Exceptions;
40 | import org.openide.util.NbBundle;
41 | import org.openide.util.NbBundle.Messages;
42 |
43 | @ActionID(
44 | category = "Images",
45 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.GenerateDummyImageAction")
46 | @ActionRegistration(
47 | displayName = "#CTL_GenerateDummyImageAction")
48 | @ActionReference(path = "Loaders/folder/any/Actions", position = 1800)
49 | @Messages("CTL_GenerateDummyImageAction=Generate Dummy Image")
50 | public final class GenerateDummyImageAction implements ActionListener {
51 |
52 | private static final Logger LOGGER = Logger.getLogger(GenerateDummyImageAction.class.getName());
53 | private final DataObject context;
54 |
55 | public GenerateDummyImageAction(DataObject context) {
56 | this.context = context;
57 | }
58 | @NbBundle.Messages({
59 | "# {0} - file name",
60 | "GenerateDummyImageAction.File.Exists.Warning=File({0}) already exisits.",
61 | "GenerateDummyImageAction.File.Exists.Title=Warning"
62 | })
63 | @Override
64 | public void actionPerformed(ActionEvent ev) {
65 | FileObject directory = context.getPrimaryFile();
66 | if (directory == null) {
67 | return;
68 | }
69 |
70 | // panel
71 | DummyImagePanel panel = DummyImagePanel.getDefault();
72 | DialogDescriptor descriptor = panel.showDialog();
73 |
74 | if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
75 | int width = panel.getImageWidth();
76 | int height = panel.getImageHeight();
77 |
78 | BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
79 |
80 | // color
81 | Color color = panel.getColor();
82 | int alpha = (int) (255 * panel.getOpacity() * 0.01);
83 | color = new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha);
84 | Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
85 |
86 | // draw rectangular
87 | graphics.setColor(color);
88 | graphics.fillRect(0, 0, width, height);
89 |
90 | // draw size
91 | graphics.setColor(Color.decode("0xffffff")); // NOI18N
92 | graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
93 | Font font = new Font(Font.SANS_SERIF, Font.BOLD, getDrawStringFontSize(height));
94 | graphics.setFont(font);
95 | drawSize(width, height, font, graphics);
96 |
97 | graphics.dispose();
98 |
99 | // get file
100 | String fileNameWithExt = panel.getFileNameWithExt();
101 | FileObject fileObject = directory.getFileObject(fileNameWithExt);
102 |
103 | if (fileObject != null && !panel.isOverwrite()) {
104 | // show dialog
105 | showWarningDialog(fileNameWithExt);
106 | LOGGER.log(Level.WARNING, Bundle.GenerateDummyImageAction_File_Exists_Warning(fileNameWithExt));
107 | return;
108 | }
109 |
110 | try {
111 | // write
112 | FileObject createData = FileUtil.createData(directory, fileNameWithExt);
113 | ImageIO.write(bufferedImage, panel.getFormat(), FileUtil.toFile(createData));
114 | } catch (IOException ex) {
115 | Exceptions.printStackTrace(ex);
116 | }
117 | }
118 | }
119 |
120 | private int getDrawStringFontSize(int height) {
121 | int size = 15;
122 | if (height >= 600) {
123 | size = 30;
124 | } else if (height >= 300) {
125 | size = 20;
126 | }
127 | return size;
128 | }
129 |
130 | private void drawSize(int width, int height, Font font, Graphics2D graphics) {
131 | String drawString = width + " x " + height; // NOI18N
132 |
133 | Rectangle2D rectangle = font.getStringBounds(drawString, graphics.getFontRenderContext());
134 | int drawStringWidth = (int) rectangle.getWidth();
135 | int drawStringHeight = (int) rectangle.getHeight();
136 | if (width > drawStringWidth && height > drawStringHeight) {
137 | int prefferedWidth = (width - drawStringWidth) / 2;
138 | int prefferedHeight = height / 2;
139 | graphics.drawString(drawString, prefferedWidth, prefferedHeight);
140 | }
141 | }
142 |
143 | private void showWarningDialog(String fileNameWithExt) {
144 | NotifyDescriptor.Message message = new NotifyDescriptor.Message(
145 | Bundle.GenerateDummyImageAction_File_Exists_Warning(fileNameWithExt),
146 | NotifyDescriptor.WARNING_MESSAGE);
147 | Object response = DialogDisplayer.getDefault().notify(message);
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/SmartDeleteAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import com.junichi11.netbeans.php.enhancements.utils.DocUtils;
19 | import java.awt.event.ActionEvent;
20 | import java.awt.event.ActionListener;
21 | import java.util.Arrays;
22 | import java.util.HashSet;
23 | import java.util.Set;
24 | import javax.swing.text.AbstractDocument;
25 | import javax.swing.text.BadLocationException;
26 | import javax.swing.text.Document;
27 | import javax.swing.text.JTextComponent;
28 | import org.netbeans.api.annotations.common.CheckForNull;
29 | import org.netbeans.api.editor.EditorRegistry;
30 | import org.netbeans.api.html.lexer.HTMLTokenId;
31 | import org.netbeans.api.lexer.Token;
32 | import org.netbeans.api.lexer.TokenHierarchy;
33 | import org.netbeans.api.lexer.TokenId;
34 | import org.netbeans.api.lexer.TokenSequence;
35 | import org.netbeans.modules.php.editor.lexer.PHPTokenId;
36 | import org.openide.awt.ActionID;
37 | import org.openide.awt.ActionReference;
38 | import org.openide.awt.ActionRegistration;
39 | import org.openide.cookies.EditorCookie;
40 | import org.openide.util.Exceptions;
41 | import org.openide.util.NbBundle.Messages;
42 |
43 | @ActionID(
44 | category = "PHP",
45 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.SmartDeleteAction")
46 | @ActionRegistration(
47 | displayName = "#CTL_SmartDeleteAction")
48 | @ActionReference(path = "Shortcuts", name = "DS-BACK_SPACE")
49 | @Messages("CTL_SmartDeleteAction=Smart Delete")
50 | public final class SmartDeleteAction implements ActionListener {
51 |
52 | private final EditorCookie context;
53 | private static final Set extends TokenId> AVAILABLEIDS = new HashSet<>(Arrays.asList(
54 | PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING,
55 | PHPTokenId.PHP_VARIABLE,
56 | PHPTokenId.PHP_STRING,
57 | HTMLTokenId.VALUE));
58 |
59 | public SmartDeleteAction(EditorCookie context) {
60 | this.context = context;
61 | }
62 |
63 | @Override
64 | public void actionPerformed(ActionEvent ev) {
65 | JTextComponent editor = EditorRegistry.lastFocusedComponent();
66 | if (editor == null) {
67 | return;
68 | }
69 |
70 | Document document = editor.getDocument();
71 | if (document == null) {
72 | return;
73 | }
74 |
75 | // caret position is end of token
76 | // i.e. if it is start of next token, string is not removed.
77 | // so, caret position - 1
78 | // e.g. $something[caret is here]
79 | int offset = editor.getCaretPosition() - 1;
80 | if (offset < 0) {
81 | offset = 0;
82 | }
83 | // get token sequence
84 | TokenSequence extends TokenId> ts = getTokenSequence(document, offset);
85 | if (ts == null) {
86 | return;
87 | }
88 |
89 | Token extends TokenId> token = ts.token();
90 | TokenId id = token.id();
91 | String primaryCategory = id.primaryCategory();
92 | boolean isString = primaryCategory.equals("string"); // NOI18N
93 | if (!AVAILABLEIDS.contains(id) && !isString) {
94 | return;
95 | }
96 | String text = token.text().toString();
97 | int startOffset = ts.offset() + 1;
98 | int removeLength = 0;
99 | int textLength = text.length();
100 | // string
101 | // "something" or 'something' -> "" or ''
102 | if (isString || id == HTMLTokenId.VALUE) {
103 | if (wrapWith(text, "\"") || wrapWith(text, "'")) { // NOI18N
104 | if (textLength <= 2) {
105 | // "" or ''
106 | removeLength = textLength;
107 | startOffset = ts.offset();
108 | } else {
109 | removeLength = textLength - 2;
110 | }
111 | } else {
112 | removeLength = textLength;
113 | startOffset = ts.offset();
114 | }
115 | }
116 |
117 | // variable
118 | // $something -> $
119 | if (id == PHPTokenId.PHP_VARIABLE) {
120 | removeLength = textLength - 1;
121 | }
122 |
123 | // php string
124 | // e.g. DEFINE
125 | if (id == PHPTokenId.PHP_STRING) {
126 | startOffset = ts.offset();
127 | removeLength = textLength;
128 | }
129 |
130 | try {
131 | // remove string
132 | DocUtils.remove(startOffset, removeLength, document);
133 | } catch (BadLocationException ex) {
134 | Exceptions.printStackTrace(ex);
135 | }
136 | }
137 |
138 | private boolean wrapWith(String target, String wrapString) {
139 | return target.startsWith(wrapString) && target.endsWith(wrapString);
140 | }
141 |
142 | @CheckForNull
143 | private TokenSequence extends TokenId> getTokenSequence(Document document, int offset) {
144 | AbstractDocument ad = (AbstractDocument) document;
145 | ad.readLock();
146 | TokenSequence extends TokenId> tokenSequence;
147 | try {
148 | TokenHierarchy th = TokenHierarchy.get(document);
149 | if (th == null) {
150 | return null;
151 | }
152 | tokenSequence = th.tokenSequence();
153 | } finally {
154 | ad.readUnlock();
155 | }
156 | if (tokenSequence == null) {
157 | return null;
158 | }
159 | tokenSequence.move(offset);
160 | tokenSequence.moveNext();
161 |
162 | while (tokenSequence.embedded() != null) {
163 | tokenSequence = tokenSequence.embedded();
164 | tokenSequence.move(offset);
165 | tokenSequence.moveNext();
166 | }
167 | return tokenSequence;
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/Parameters.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.editor.completion;
17 |
18 | import com.google.gson.Gson;
19 | import com.google.gson.reflect.TypeToken;
20 | import com.google.gson.stream.JsonReader;
21 | import com.junichi11.netbeans.php.enhancements.options.PHPEnhancementsOptions;
22 | import java.io.BufferedReader;
23 | import java.io.IOException;
24 | import java.io.InputStream;
25 | import java.io.InputStreamReader;
26 | import java.lang.reflect.Type;
27 | import java.net.URL;
28 | import java.util.ArrayList;
29 | import java.util.HashMap;
30 | import java.util.List;
31 | import java.util.Locale;
32 | import java.util.Map;
33 | import java.util.logging.Level;
34 | import java.util.logging.Logger;
35 |
36 | /**
37 | *
38 | * @author junichi11
39 | */
40 | public final class Parameters {
41 |
42 | private static final Logger LOGGER = Logger.getLogger(Parameters.class.getName());
43 |
44 | public static final Map> PARAMETER_MAP = new HashMap<>();
45 | public static final List DATE_FORMATS = new ArrayList<>();
46 | public static final List TIMEZONES = new ArrayList<>();
47 | public static final List PHPINI_DIRECTIVES = new ArrayList<>();
48 | public static final List HTTP_HEADER_RESPONSES = new ArrayList<>();
49 | public static final List HTTP_STATUS_CODES = new ArrayList<>();
50 | public static final List HTTP_CHARSETS = new ArrayList<>();
51 | public static final List HTTP_METHODS = new ArrayList<>();
52 | public static final List HTTP_CACHE_CONTROL_DIRECTIVES = new ArrayList<>();
53 | public static final List HTTP_LANGUAGES = new ArrayList<>();
54 | public static final List ENCODINGS = new ArrayList<>();
55 | public static final List CHARSETS = new ArrayList<>();
56 | public static final List SUBSTCHARS = new ArrayList<>();
57 | public static final List MB_LANGUAGES = new ArrayList<>();
58 | public static final List MB_KANA_CONVERSIONS = new ArrayList<>();
59 | public static final List MB_GET_INFO_TYPES = new ArrayList<>();
60 | public static final List MB_HTTP_INPUT_TYPES = new ArrayList<>();
61 | public static final List SESSION_CACHE_LIMITERS = new ArrayList<>();
62 | public static final List MEDIA_TYPES = new ArrayList<>();
63 | public static final List ENVS = new ArrayList<>();
64 |
65 | private Parameters() {
66 | }
67 |
68 | static {
69 | if (PHPEnhancementsOptions.getInstance().isParametersCodeCompletion()) {
70 | load();
71 | }
72 | }
73 |
74 | private static void load() {
75 | PARAMETER_MAP.clear();
76 | buildParameterMap();
77 | buildParameters();
78 | for (String lang : Locale.getISOLanguages()) {
79 | HTTP_LANGUAGES.add(new Parameter(lang, "", "")); // NOI18N
80 | }
81 | PARAMETER_MAP.clear();
82 | }
83 |
84 | public static void reload() {
85 | clear();
86 | load();
87 | }
88 |
89 | public static void clear() {
90 | PARAMETER_MAP.clear();
91 | buildParameterMap();
92 | for (Map.Entry> entry : PARAMETER_MAP.entrySet()) {
93 | List list = entry.getValue();
94 | list.clear();
95 | }
96 | PARAMETER_MAP.clear();
97 | }
98 |
99 | private static void buildParameterMap() {
100 | // function
101 | PARAMETER_MAP.put("date_formats", DATE_FORMATS); // NOI18N
102 | PARAMETER_MAP.put("timezones", TIMEZONES); // NOI18N
103 | PARAMETER_MAP.put("phpini_directives", PHPINI_DIRECTIVES); // NOI18N
104 | PARAMETER_MAP.put("http_status_codes", HTTP_STATUS_CODES); // NOI18N
105 | PARAMETER_MAP.put("http_header_responses", HTTP_HEADER_RESPONSES); // NOI18N
106 | PARAMETER_MAP.put("http_charsets", HTTP_CHARSETS); // NOI18N
107 | PARAMETER_MAP.put("http_methods", HTTP_METHODS); // NOI18N
108 | PARAMETER_MAP.put("http_cache_control_directives", HTTP_CACHE_CONTROL_DIRECTIVES); // NOI18N
109 | PARAMETER_MAP.put("encodings", ENCODINGS); // NOI18N
110 | PARAMETER_MAP.put("charsets", CHARSETS); // NOI18N
111 | PARAMETER_MAP.put("substchars", SUBSTCHARS); // NOI18N
112 | PARAMETER_MAP.put("mb_languages", MB_LANGUAGES); // NOI18N
113 | PARAMETER_MAP.put("mb_kana_conversions", MB_KANA_CONVERSIONS); // NOI18N
114 | PARAMETER_MAP.put("mb_get_info_types", MB_GET_INFO_TYPES); // NOI18N
115 | PARAMETER_MAP.put("mb_http_input_types", MB_HTTP_INPUT_TYPES); // NOI18N
116 | PARAMETER_MAP.put("session_cache_limiters", SESSION_CACHE_LIMITERS); // NOI18N
117 | PARAMETER_MAP.put("media_types", MEDIA_TYPES); // NOI18N
118 |
119 | // array
120 | PARAMETER_MAP.put("envs", ENVS); // NOI18N
121 | }
122 |
123 | private static void buildParameters() {
124 | Gson gson = new Gson();
125 | for (Map.Entry> entry : PARAMETER_MAP.entrySet()) {
126 | String target = entry.getKey();
127 | List list = entry.getValue();
128 | list.clear();
129 | String filePath = String.format("resources/%s.json", target); // NOI18N
130 | URL resource = Function.class.getResource(filePath);
131 | if (resource == null) {
132 | continue;
133 | }
134 | try {
135 | InputStream inputStream = resource.openStream();
136 | JsonReader jsonReader = new JsonReader(new BufferedReader(new InputStreamReader(inputStream, "UTF-8"))); // NOI18N
137 | try {
138 | Type type = new TypeToken>() {
139 | }.getType();
140 | ArrayList parameters = gson.fromJson(jsonReader, type);
141 | list.addAll(parameters);
142 | } finally {
143 | inputStream.close();
144 | jsonReader.close();
145 | }
146 | } catch (IOException ex) {
147 | LOGGER.log(Level.WARNING, ex.getMessage());
148 | }
149 | }
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/PHPEnhancementsPanel.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
113 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/date_formats.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "d",
4 | "description": "Day of the month, 2 digits with leading zeros",
5 | "category": "01 to 31"
6 | },
7 | {
8 | "name": "D",
9 | "description": "A textual representation of a day, three letters",
10 | "category": "Mon through Sun"
11 | },
12 | {
13 | "name": "j",
14 | "description": "Day of the month without leading zeros",
15 | "category": "1 to 31"
16 | },
17 | {
18 | "name": "l",
19 | "description": "A full textual representation of the day of the week",
20 | "category": "Sunday through Saturday"
21 | },
22 | {
23 | "name": "N",
24 | "description": "ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)",
25 | "category": "1 (for Monday) through 7 (for Sunday)"
26 | },
27 | {
28 | "name": "S",
29 | "description": "English ordinal suffix for the day of the month, 2 characters",
30 | "category": " st, nd, rd or th. Works well with j "
31 | },
32 | {
33 | "name": "w",
34 | "description": "Numeric representation of the day of the week",
35 | "category": "0 (for Sunday) through 6 (for Saturday)"
36 | },
37 | {
38 | "name": "z",
39 | "description": "The day of the year (starting from 0)",
40 | "category": "0 through 365"
41 | },
42 | {
43 | "name": "W",
44 | "description": "ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)",
45 | "category": "Example: 42 (the 42nd week in the year)"
46 | },
47 | {
48 | "name": "F",
49 | "description": "A full textual representation of a month, such as January or March",
50 | "category": "January through December"
51 | },
52 | {
53 | "name": "m",
54 | "description": "Numeric representation of a month, with leading zeros",
55 | "category": "01 through 12"
56 | },
57 | {
58 | "name": "M",
59 | "description": "A short textual representation of a month, three letters",
60 | "category": "Jan through Dec"
61 | },
62 | {
63 | "name": "n",
64 | "description": "Numeric representation of a month, without leading zeros",
65 | "category": "1 through 12"
66 | },
67 | {
68 | "name": "t",
69 | "description": "Number of days in the given month",
70 | "category": "28 through 31"
71 | },
72 | {
73 | "name": "L",
74 | "description": "Whether it's a leap year",
75 | "category": "1 if it is a leap year, 0 otherwise."
76 | },
77 | {
78 | "name": "o",
79 | "description": "ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead. (added in PHP 5.1.0)",
80 | "category": "Examples: 1999 or 2003"
81 | },
82 | {
83 | "name": "Y",
84 | "description": "A full numeric representation of a year, 4 digits",
85 | "category": "Examples: 1999 or 2003"
86 | },
87 | {
88 | "name": "y",
89 | "description": "A two digit representation of a year",
90 | "category": "Examples: 99 or 03"
91 | },
92 | {
93 | "name": "a",
94 | "description": "Lowercase Ante meridiem and Post meridiem",
95 | "category": "am or pm"
96 | },
97 | {
98 | "name": "A",
99 | "description": "Uppercase Ante meridiem and Post meridiem",
100 | "category": "AM or PM"
101 | },
102 | {
103 | "name": "B",
104 | "description": "Swatch Internet time",
105 | "category": "000 through 999"
106 | },
107 | {
108 | "name": "g",
109 | "description": "12-hour format of an hour without leading zeros",
110 | "category": "1 through 12"
111 | },
112 | {
113 | "name": "G",
114 | "description": "24-hour format of an hour without leading zeros",
115 | "category": "0 through 23"
116 | },
117 | {
118 | "name": "h",
119 | "description": "12-hour format of an hour with leading zeros",
120 | "category": "01 through 12"
121 | },
122 | {
123 | "name": "H",
124 | "description": "24-hour format of an hour with leading zeros",
125 | "category": "00 through 23"
126 | },
127 | {
128 | "name": "i",
129 | "description": "Minutes with leading zeros",
130 | "category": "00 to 59"
131 | },
132 | {
133 | "name": "s",
134 | "description": "Seconds, with leading zeros",
135 | "category": "00 through 59"
136 | },
137 | {
138 | "name": "u",
139 | "description": " Microseconds (added in PHP 5.2.2). Note that date() will always generate 000000 since it takes an integer parameter, whereas DateTime::format() does support microseconds. ",
140 | "category": "Example: 654321"
141 | },
142 | {
143 | "name": "e",
144 | "description": "Timezone identifier (added in PHP 5.1.0)",
145 | "category": "Examples: UTC, GMT, Atlantic\/Azores"
146 | },
147 | {
148 | "name": "I",
149 | "description": "Whether or not the date is in daylight saving time",
150 | "category": "1 if Daylight Saving Time, 0 otherwise."
151 | },
152 | {
153 | "name": "O",
154 | "description": "Difference to Greenwich time (GMT) in hours",
155 | "category": "Example: +0200"
156 | },
157 | {
158 | "name": "P",
159 | "description": "Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)",
160 | "category": "Example: +02:00"
161 | },
162 | {
163 | "name": "T",
164 | "description": "Timezone abbreviation",
165 | "category": "Examples: EST, MDT ..."
166 | },
167 | {
168 | "name": "Z",
169 | "description": "Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.",
170 | "category": "-43200 through 50400"
171 | },
172 | {
173 | "name": "c",
174 | "description": "ISO 8601 date (added in PHP 5)",
175 | "category": "2004-02-12T15:19:21+00:00"
176 | },
177 | {
178 | "name": "r",
179 | "description": "",
180 | "category": "Example: Thu, 21 Dec 2000 16:01:07 +0200"
181 | },
182 | {
183 | "name": "U",
184 | "description": "Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)",
185 | "category": "See also time()"
186 | },
187 | {
188 | "name": "Y-m-d",
189 | "description": "",
190 | "category": "2014-03-29"
191 | },
192 | {
193 | "name": "Y-m-d H:i:s",
194 | "description": "",
195 | "category": "2014-03-29 23:01:30"
196 | },
197 | {
198 | "name": "Y/m/d",
199 | "description": "",
200 | "category": "2014/03/29"
201 | },
202 | {
203 | "name": "Y.m.d",
204 | "description": "",
205 | "category": "2014.03.29"
206 | },
207 | {
208 | "name": "Y m d",
209 | "description": "",
210 | "category": "2014 03 29"
211 | },
212 | {
213 | "name": "d-m-Y",
214 | "description": "",
215 | "category": "29-03-2014"
216 | },
217 | {
218 | "name": "d/m/Y",
219 | "description": "",
220 | "category": "29/03/2014"
221 | },
222 | {
223 | "name": "d.m.Y",
224 | "description": "",
225 | "category": "29.03.2014"
226 | },
227 | {
228 | "name": "H:i:s",
229 | "description": "",
230 | "category": "23:01:30"
231 | },
232 | {
233 | "name": "h:i:s",
234 | "description": "",
235 | "category": "11:01:30"
236 | }
237 | ]
238 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/options/PHPEnhancementsPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.options;
17 |
18 | import com.junichi11.netbeans.php.enhancements.editor.completion.Parameters;
19 |
20 | final class PHPEnhancementsPanel extends javax.swing.JPanel {
21 |
22 | private static final long serialVersionUID = -4525362573123684731L;
23 |
24 | private final PHPEnhancementsOptionsPanelController controller;
25 |
26 | PHPEnhancementsPanel(PHPEnhancementsOptionsPanelController controller) {
27 | this.controller = controller;
28 | initComponents();
29 | // TODO listen to changes in form fields and call controller.changed()
30 | }
31 |
32 | /**
33 | * This method is called from within the constructor to initialize the form.
34 | * WARNING: Do NOT modify this code. The content of this method is always
35 | * regenerated by the Form Editor.
36 | */
37 | // //GEN-BEGIN:initComponents
38 | private void initComponents() {
39 |
40 | typingHooksLabel = new javax.swing.JLabel();
41 | objectOperatorCheckBox = new javax.swing.JCheckBox();
42 | doubleArrowOperatorCheckBox = new javax.swing.JCheckBox();
43 | codeCompletionLabel = new javax.swing.JLabel();
44 | toUppercaseConstCheckBox = new javax.swing.JCheckBox();
45 | toUppercaseDefineCheckBox = new javax.swing.JCheckBox();
46 | parametersCodeCompletionCheckBox = new javax.swing.JCheckBox();
47 |
48 | org.openide.awt.Mnemonics.setLocalizedText(typingHooksLabel, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.typingHooksLabel.text")); // NOI18N
49 |
50 | org.openide.awt.Mnemonics.setLocalizedText(objectOperatorCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.objectOperatorCheckBox.text")); // NOI18N
51 |
52 | org.openide.awt.Mnemonics.setLocalizedText(doubleArrowOperatorCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.doubleArrowOperatorCheckBox.text")); // NOI18N
53 |
54 | org.openide.awt.Mnemonics.setLocalizedText(codeCompletionLabel, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.codeCompletionLabel.text")); // NOI18N
55 |
56 | org.openide.awt.Mnemonics.setLocalizedText(toUppercaseConstCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.toUppercaseConstCheckBox.text")); // NOI18N
57 |
58 | org.openide.awt.Mnemonics.setLocalizedText(toUppercaseDefineCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.toUppercaseDefineCheckBox.text")); // NOI18N
59 |
60 | org.openide.awt.Mnemonics.setLocalizedText(parametersCodeCompletionCheckBox, org.openide.util.NbBundle.getMessage(PHPEnhancementsPanel.class, "PHPEnhancementsPanel.parametersCodeCompletionCheckBox.text")); // NOI18N
61 |
62 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
63 | this.setLayout(layout);
64 | layout.setHorizontalGroup(
65 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
66 | .addGroup(layout.createSequentialGroup()
67 | .addContainerGap()
68 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
69 | .addComponent(typingHooksLabel)
70 | .addComponent(codeCompletionLabel)
71 | .addGroup(layout.createSequentialGroup()
72 | .addGap(12, 12, 12)
73 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
74 | .addComponent(doubleArrowOperatorCheckBox)
75 | .addComponent(objectOperatorCheckBox)
76 | .addComponent(toUppercaseConstCheckBox)
77 | .addComponent(toUppercaseDefineCheckBox)
78 | .addComponent(parametersCodeCompletionCheckBox))))
79 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
80 | );
81 | layout.setVerticalGroup(
82 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
83 | .addGroup(layout.createSequentialGroup()
84 | .addContainerGap()
85 | .addComponent(typingHooksLabel)
86 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
87 | .addComponent(objectOperatorCheckBox)
88 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
89 | .addComponent(doubleArrowOperatorCheckBox)
90 | .addGap(18, 18, 18)
91 | .addComponent(codeCompletionLabel)
92 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
93 | .addComponent(toUppercaseConstCheckBox)
94 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
95 | .addComponent(toUppercaseDefineCheckBox)
96 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
97 | .addComponent(parametersCodeCompletionCheckBox)
98 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
99 | );
100 | }// //GEN-END:initComponents
101 |
102 | void load() {
103 | PHPEnhancementsOptions options = PHPEnhancementsOptions.getInstance();
104 | objectOperatorCheckBox.setSelected(options.isObjectOperator());
105 | doubleArrowOperatorCheckBox.setSelected(options.isDoubleArrowOperator());
106 | toUppercaseConstCheckBox.setSelected(options.isToUppercaseConst());
107 | toUppercaseDefineCheckBox.setSelected(options.isToUppercaseDefine());
108 | parametersCodeCompletionCheckBox.setSelected(options.isParametersCodeCompletion());
109 | }
110 |
111 | void store() {
112 | PHPEnhancementsOptions options = PHPEnhancementsOptions.getInstance();
113 | options.setObjectOperator(objectOperatorCheckBox.isSelected());
114 | options.setDoubleArrowOperator(doubleArrowOperatorCheckBox.isSelected());
115 | options.setToUppercaseConst(toUppercaseConstCheckBox.isSelected());
116 | options.setToUppercaseDefine(toUppercaseDefineCheckBox.isSelected());
117 | options.setParametersCodeCompletion(parametersCodeCompletionCheckBox.isSelected());
118 | if (parametersCodeCompletionCheckBox.isSelected()) {
119 | Parameters.reload();
120 | } else {
121 | Parameters.clear();
122 | }
123 | }
124 |
125 | boolean valid() {
126 | // TODO check whether form is consistent and complete
127 | return true;
128 | }
129 |
130 | // Variables declaration - do not modify//GEN-BEGIN:variables
131 | private javax.swing.JLabel codeCompletionLabel;
132 | private javax.swing.JCheckBox doubleArrowOperatorCheckBox;
133 | private javax.swing.JCheckBox objectOperatorCheckBox;
134 | private javax.swing.JCheckBox parametersCodeCompletionCheckBox;
135 | private javax.swing.JCheckBox toUppercaseConstCheckBox;
136 | private javax.swing.JCheckBox toUppercaseDefineCheckBox;
137 | private javax.swing.JLabel typingHooksLabel;
138 | // End of variables declaration//GEN-END:variables
139 | }
140 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/completion/resources/encodings.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "UCS-4",
4 | "description": "",
5 | "category": ""
6 | },
7 | {
8 | "name": "UCS-4BE",
9 | "description": "",
10 | "category": ""
11 | },
12 | {
13 | "name": "UCS-4LE",
14 | "description": "",
15 | "category": ""
16 | },
17 | {
18 | "name": "UCS-2",
19 | "description": "",
20 | "category": ""
21 | },
22 | {
23 | "name": "UCS-2BE",
24 | "description": "",
25 | "category": ""
26 | },
27 | {
28 | "name": "UCS-2LE",
29 | "description": "",
30 | "category": ""
31 | },
32 | {
33 | "name": "UTF-32",
34 | "description": "",
35 | "category": ""
36 | },
37 | {
38 | "name": "UTF-32BE",
39 | "description": "",
40 | "category": ""
41 | },
42 | {
43 | "name": "UTF-32LE",
44 | "description": "",
45 | "category": ""
46 | },
47 | {
48 | "name": "UTF-16",
49 | "description": "",
50 | "category": ""
51 | },
52 | {
53 | "name": "UTF-16BE",
54 | "description": "",
55 | "category": ""
56 | },
57 | {
58 | "name": "UTF-16LE",
59 | "description": "",
60 | "category": ""
61 | },
62 | {
63 | "name": "UTF-7",
64 | "description": "",
65 | "category": ""
66 | },
67 | {
68 | "name": "UTF7-IMAP",
69 | "description": "",
70 | "category": ""
71 | },
72 | {
73 | "name": "UTF-8",
74 | "description": "",
75 | "category": ""
76 | },
77 | {
78 | "name": "ASCII",
79 | "description": "",
80 | "category": ""
81 | },
82 | {
83 | "name": "EUC-JP",
84 | "description": "",
85 | "category": ""
86 | },
87 | {
88 | "name": "SJIS",
89 | "description": "",
90 | "category": ""
91 | },
92 | {
93 | "name": "eucJP-win",
94 | "description": "",
95 | "category": ""
96 | },
97 | {
98 | "name": "SJIS-win",
99 | "description": "",
100 | "category": ""
101 | },
102 | {
103 | "name": "ISO-2022-JP",
104 | "description": "",
105 | "category": ""
106 | },
107 | {
108 | "name": "ISO-2022-JP-MS",
109 | "description": "",
110 | "category": ""
111 | },
112 | {
113 | "name": "CP932",
114 | "description": "",
115 | "category": ""
116 | },
117 | {
118 | "name": "CP51932",
119 | "description": "",
120 | "category": ""
121 | },
122 | {
123 | "name": "SJIS-mac",
124 | "description": "",
125 | "category": ""
126 | },
127 | {
128 | "name": "MacJapanese",
129 | "description": "",
130 | "category": "Alias"
131 | },
132 | {
133 | "name": "SJIS-Mobile#DOCOMO",
134 | "description": "",
135 | "category": ""
136 | },
137 | {
138 | "name": "SJIS-DOCOMO",
139 | "description": "",
140 | "category": "Alias"
141 | },
142 | {
143 | "name": "SJIS-Mobile#KDDI",
144 | "description": "",
145 | "category": ""
146 | },
147 | {
148 | "name": "SJIS-KDDI",
149 | "description": "",
150 | "category": "Alias"
151 | },
152 | {
153 | "name": "SJIS-Mobile#SOFTBANK",
154 | "description": "",
155 | "category": ""
156 | },
157 | {
158 | "name": "SJIS-SOFTBANK",
159 | "description": "",
160 | "category": "Alias"
161 | },
162 | {
163 | "name": "UTF-8-Mobile#DOCOMO",
164 | "description": "",
165 | "category": ""
166 | },
167 | {
168 | "name": "UTF-8-DOCOMO",
169 | "description": "",
170 | "category": "Alias"
171 | },
172 | {
173 | "name": "UTF-8-Mobile#KDDI-A",
174 | "description": "",
175 | "category": ""
176 | },
177 | {
178 | "name": "UTF-8-Mobile#KDDI-B",
179 | "description": "",
180 | "category": ""
181 | },
182 | {
183 | "name": "UTF-8-KDDI",
184 | "description": "",
185 | "category": "Alias"
186 | },
187 | {
188 | "name": "UTF-8-Mobile#SOFTBANK",
189 | "description": "",
190 | "category": ""
191 | },
192 | {
193 | "name": "UTF-8-SOFTBANK",
194 | "description": "",
195 | "category": "Alias"
196 | },
197 | {
198 | "name": "ISO-2022-JP-MOBILE#KDDI",
199 | "description": "",
200 | "category": ""
201 | },
202 | {
203 | "name": "ISO-2022-JP-KDDI",
204 | "description": "",
205 | "category": "Alias"
206 | },
207 | {
208 | "name": "JIS",
209 | "description": "",
210 | "category": ""
211 | },
212 | {
213 | "name": "JIS-ms",
214 | "description": "",
215 | "category": ""
216 | },
217 | {
218 | "name": "CP50220",
219 | "description": "",
220 | "category": ""
221 | },
222 | {
223 | "name": "CP50220raw",
224 | "description": "",
225 | "category": ""
226 | },
227 | {
228 | "name": "CP50221",
229 | "description": "",
230 | "category": ""
231 | },
232 | {
233 | "name": "CP50222",
234 | "description": "",
235 | "category": ""
236 | },
237 | {
238 | "name": "ISO-8859-1",
239 | "description": "",
240 | "category": ""
241 | },
242 | {
243 | "name": "ISO-8859-2",
244 | "description": "",
245 | "category": ""
246 | },
247 | {
248 | "name": "ISO-8859-3",
249 | "description": "",
250 | "category": ""
251 | },
252 | {
253 | "name": "ISO-8859-4",
254 | "description": "",
255 | "category": ""
256 | },
257 | {
258 | "name": "ISO-8859-5",
259 | "description": "",
260 | "category": ""
261 | },
262 | {
263 | "name": "ISO-8859-6",
264 | "description": "",
265 | "category": ""
266 | },
267 | {
268 | "name": "ISO-8859-7",
269 | "description": "",
270 | "category": ""
271 | },
272 | {
273 | "name": "ISO-8859-8",
274 | "description": "",
275 | "category": ""
276 | },
277 | {
278 | "name": "ISO-8859-9",
279 | "description": "",
280 | "category": ""
281 | },
282 | {
283 | "name": "ISO-8859-10",
284 | "description": "",
285 | "category": ""
286 | },
287 | {
288 | "name": "ISO-8859-13",
289 | "description": "",
290 | "category": ""
291 | },
292 | {
293 | "name": "ISO-8859-14",
294 | "description": "",
295 | "category": ""
296 | },
297 | {
298 | "name": "ISO-8859-15",
299 | "description": "",
300 | "category": ""
301 | },
302 | {
303 | "name": "byte2be",
304 | "description": "",
305 | "category": ""
306 | },
307 | {
308 | "name": "byte2le",
309 | "description": "",
310 | "category": ""
311 | },
312 | {
313 | "name": "byte4be",
314 | "description": "",
315 | "category": ""
316 | },
317 | {
318 | "name": "byte4le",
319 | "description": "",
320 | "category": ""
321 | },
322 | {
323 | "name": "BASE64",
324 | "description": "",
325 | "category": ""
326 | },
327 | {
328 | "name": "HTML-ENTITIES",
329 | "description": "",
330 | "category": ""
331 | },
332 | {
333 | "name": "7bit",
334 | "description": "",
335 | "category": ""
336 | },
337 | {
338 | "name": "8bit",
339 | "description": "",
340 | "category": ""
341 | },
342 | {
343 | "name": "EUC-CN",
344 | "description": "",
345 | "category": ""
346 | },
347 | {
348 | "name": "CP936",
349 | "description": "",
350 | "category": ""
351 | },
352 | {
353 | "name": "GB18030",
354 | "description": "",
355 | "category": ""
356 | },
357 | {
358 | "name": "HZ",
359 | "description": "",
360 | "category": ""
361 | },
362 | {
363 | "name": "EUC-TW",
364 | "description": "",
365 | "category": ""
366 | },
367 | {
368 | "name": "CP950",
369 | "description": "",
370 | "category": ""
371 | },
372 | {
373 | "name": "BIG-5",
374 | "description": "",
375 | "category": ""
376 | },
377 | {
378 | "name": "EUC-KR",
379 | "description": "",
380 | "category": ""
381 | },
382 | {
383 | "name": "UHC (CP949)",
384 | "description": "",
385 | "category": ""
386 | },
387 | {
388 | "name": "ISO-2022-KR",
389 | "description": "",
390 | "category": ""
391 | },
392 | {
393 | "name": "Windows-1251",
394 | "description": "",
395 | "category": "CP1251"
396 | },
397 | {
398 | "name": "Windows-1252",
399 | "description": "",
400 | "category": "CP1252"
401 | },
402 | {
403 | "name": "CP866",
404 | "description": "",
405 | "category": "IBM866"
406 | },
407 | {
408 | "name": "KOI8-R",
409 | "description": "",
410 | "category": ""
411 | }
412 | ]
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/ui/actions/ConvertToPhpShortArraySyntaxAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.ui.actions;
17 |
18 | import com.junichi11.netbeans.php.enhancements.utils.Utils;
19 | import java.awt.event.ActionEvent;
20 | import java.awt.event.ActionListener;
21 | import java.io.IOException;
22 | import java.util.Arrays;
23 | import java.util.LinkedList;
24 | import java.util.List;
25 | import javax.swing.text.BadLocationException;
26 | import javax.swing.text.StyledDocument;
27 | import org.netbeans.api.lexer.Token;
28 | import org.netbeans.api.lexer.TokenSequence;
29 | import org.netbeans.api.progress.ProgressHandle;
30 | import org.netbeans.modules.php.editor.lexer.LexUtilities;
31 | import org.netbeans.modules.php.editor.lexer.PHPTokenId;
32 | import org.openide.DialogDisplayer;
33 | import org.openide.NotifyDescriptor;
34 | import org.openide.awt.ActionID;
35 | import org.openide.awt.ActionReference;
36 | import org.openide.awt.ActionReferences;
37 | import org.openide.awt.ActionRegistration;
38 | import org.openide.cookies.EditorCookie;
39 | import org.openide.filesystems.FileObject;
40 | import org.openide.loaders.DataObject;
41 | import org.openide.loaders.DataObjectNotFoundException;
42 | import org.openide.text.NbDocument;
43 | import org.openide.util.Exceptions;
44 | import org.openide.util.NbBundle;
45 | import org.openide.util.NbBundle.Messages;
46 | import org.openide.util.RequestProcessor;
47 |
48 | @ActionID(
49 | category = "Refactoring",
50 | id = "com.junichi11.netbeans.php.enhancements.ui.actions.ConvertToPhpShortArraySyntaxAction"
51 | )
52 | @ActionRegistration(
53 | displayName = "#CTL_ConvertToPhpShortArraySyntaxAction"
54 | )
55 | @ActionReferences({
56 | @ActionReference(path = "Menu/Edit", position = 3300),
57 | @ActionReference(path = "Projects/org-netbeans-modules-php-project/Actions", position = 1800),
58 | @ActionReference(path = "Loaders/text/x-php5/Actions", position = 1800),
59 | @ActionReference(path = "Loaders/folder/any/Actions", position = 1800),})
60 | @Messages("CTL_ConvertToPhpShortArraySyntaxAction=Convert to short array syntax")
61 | public final class ConvertToPhpShortArraySyntaxAction implements ActionListener {
62 |
63 | private final List context;
64 | private final StringBuilder sb = new StringBuilder();
65 | private final List balanceStack = new LinkedList<>();
66 | private boolean isArraySyntax = false;
67 | private boolean isChanged = false;
68 | private int arrayCount = 0;
69 | private int balance = 0;
70 | private TokenSequence ts;
71 |
72 | public ConvertToPhpShortArraySyntaxAction(List context) {
73 | this.context = context;
74 | }
75 |
76 | @NbBundle.Messages({
77 | "ConvertToPhpShortArraySyntaxAction.action.confirmation=If you select folders, run for all files within them recursively. Recommend to backup folders or to use version management system. Do you really want to run this action?",
78 | "ConvertToPhpShortArraySyntaxAction.action.complete=Convert to PHP short array syntax: complete",
79 | "ConvertToPhpShortArraySyntaxAction.perform.progress=Converting to short array syntax",})
80 | @Override
81 | public void actionPerformed(ActionEvent ev) {
82 | // confirmation if directories are selected
83 | for (DataObject dataObject : context) {
84 | FileObject fileObject = dataObject.getPrimaryFile();
85 | if (fileObject.isFolder()) {
86 | NotifyDescriptor.Confirmation confirmation = new NotifyDescriptor.Confirmation(
87 | Bundle.ConvertToPhpShortArraySyntaxAction_action_confirmation(),
88 | NotifyDescriptor.OK_CANCEL_OPTION
89 | );
90 | if (DialogDisplayer.getDefault().notify(confirmation) != NotifyDescriptor.OK_OPTION) {
91 | return;
92 | }
93 | break;
94 | }
95 | }
96 |
97 | // show progress bar
98 | RequestProcessor.getDefault().post(() -> {
99 | ProgressHandle handle = ProgressHandle.createHandle(Bundle.ConvertToPhpShortArraySyntaxAction_perform_progress());
100 | try {
101 | handle.start();
102 | context.forEach((dataObject) -> {
103 | actionPerformed(dataObject);
104 | });
105 | } finally {
106 | handle.finish();
107 | }
108 |
109 | // show complete dialog
110 | NotifyDescriptor.Message message = new NotifyDescriptor.Message(
111 | Bundle.ConvertToPhpShortArraySyntaxAction_action_complete(),
112 | NotifyDescriptor.INFORMATION_MESSAGE
113 | );
114 | DialogDisplayer.getDefault().notify(message);
115 | });
116 | }
117 |
118 | public void actionPerformed(DataObject dataObject) {
119 | // recursive
120 | FileObject fileObject = dataObject.getPrimaryFile();
121 | if (fileObject.isFolder()) {
122 | for (FileObject child : fileObject.getChildren()) {
123 | try {
124 | actionPerformed(DataObject.find(child));
125 | } catch (DataObjectNotFoundException ex) {
126 | Exceptions.printStackTrace(ex);
127 | }
128 | }
129 | }
130 |
131 | // get EditorCookie
132 | EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
133 | if (ec == null) {
134 | return;
135 | }
136 |
137 | try {
138 | // get document
139 | StyledDocument sdoc = getDocument(ec);
140 | if (!Utils.isPHP(sdoc)) {
141 | return;
142 | }
143 | convert(sdoc);
144 |
145 | // save
146 | if (isChanged) {
147 | ec.saveDocument();
148 | }
149 | } catch (IOException ex) {
150 | Exceptions.printStackTrace(ex);
151 | }
152 | }
153 |
154 | /**
155 | * Convert to short array syntax.
156 | *
157 | * @param sdoc
158 | */
159 | public void convert(final StyledDocument sdoc) {
160 | ts = Utils.getTokenSequence(sdoc, 0);
161 | if (ts == null) {
162 | return;
163 | }
164 | ts.move(0);
165 |
166 | NbDocument.runAtomic(sdoc, () -> {
167 | init();
168 |
169 | while (ts.moveNext()) {
170 | Token token = ts.token();
171 | handleToken(token);
172 | }
173 | if (!isChanged) {
174 | return;
175 | }
176 |
177 | try {
178 | // XXX line feed is added to last token when document is devided to tokens
179 | int length = sb.length();
180 | if (length > 0) {
181 | // delete last position
182 | sb.deleteCharAt(length - 1);
183 | }
184 | sdoc.remove(0, sdoc.getLength());
185 | sdoc.insertString(0, sb.toString(), null);
186 | } catch (BadLocationException ex) {
187 | Exceptions.printStackTrace(ex);
188 | }
189 | });
190 | }
191 |
192 | private void init() {
193 | isArraySyntax = false;
194 | isChanged = false;
195 | balance = 0;
196 | arrayCount = 0;
197 | balanceStack.clear();
198 | sb.setLength(0);
199 | }
200 |
201 | private StyledDocument getDocument(EditorCookie ec) throws IOException {
202 | StyledDocument document = ec.getDocument();
203 | if (document == null) {
204 | document = ec.openDocument();
205 | }
206 | return document;
207 | }
208 |
209 | private void handleToken(Token token) {
210 | // array
211 | PHPTokenId id = token.id();
212 | if (id == PHPTokenId.PHP_ARRAY) {
213 | handleArray();
214 | return;
215 | }
216 | CharSequence text = token.text();
217 | // #4 check TokenId
218 | if (arrayCount > 0 && id == PHPTokenId.PHP_TOKEN) {
219 | // open
220 | if (LexUtilities.textEquals(text, '(')) { // NOI18N
221 | handleOpen();
222 | return;
223 | }
224 |
225 | // close
226 | if (LexUtilities.textEquals(text, ')')) { // NOI18N
227 | handleClose();
228 | return;
229 | }
230 | }
231 |
232 | // default
233 | sb.append(text);
234 | }
235 |
236 | private void handleArray() {
237 | /*
238 | * case 1: function parameter type e.g. public function something(array $param){}
239 | * case 2: cast e.g. (array) $something
240 | * case 3: array('something');
241 | */
242 | Token extends PHPTokenId> nextToken = LexUtilities.findNext(ts, Arrays.asList(PHPTokenId.WHITESPACE, PHPTokenId.PHP_ARRAY));
243 | if (LexUtilities.textEquals(nextToken.text(), '(')) { // NOI18N
244 | isArraySyntax = true;
245 | arrayCount++;
246 | } else {
247 | sb.append("array"); // NOI18N
248 | }
249 | LexUtilities.findPreviousToken(ts, Arrays.asList(PHPTokenId.PHP_ARRAY));
250 | }
251 |
252 | private void handleOpen() {
253 | if (isArraySyntax) {
254 | isChanged = true;
255 | isArraySyntax = false;
256 | balanceStack.add(0, balance);
257 | balance = 0;
258 | sb.append('['); // NOI18N
259 | return;
260 | }
261 | sb.append('('); // NOI18N
262 | balance++;
263 | }
264 |
265 | private void handleClose() {
266 | if (balance == 0) {
267 | sb.append(']'); // NOI18N
268 | arrayCount--;
269 | if (!balanceStack.isEmpty()) {
270 | balance = balanceStack.get(0);
271 | balanceStack.remove(0);
272 | }
273 | return;
274 | }
275 | sb.append(')'); // NOI18N
276 | balance--;
277 | }
278 |
279 | }
280 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/generator/ui/DummyTextPanel.form:
--------------------------------------------------------------------------------
1 |
2 |
3 |
182 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/release/modules/ext/LICENSE:
--------------------------------------------------------------------------------
1 | Google Gson
2 |
3 | Apache License
4 | Version 2.0, January 2004
5 | http://www.apache.org/licenses/
6 |
7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8 |
9 | 1. Definitions.
10 |
11 | "License" shall mean the terms and conditions for use, reproduction,
12 | and distribution as defined by Sections 1 through 9 of this document.
13 |
14 | "Licensor" shall mean the copyright owner or entity authorized by
15 | the copyright owner that is granting the License.
16 |
17 | "Legal Entity" shall mean the union of the acting entity and all
18 | other entities that control, are controlled by, or are under common
19 | control with that entity. For the purposes of this definition,
20 | "control" means (i) the power, direct or indirect, to cause the
21 | direction or management of such entity, whether by contract or
22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
23 | outstanding shares, or (iii) beneficial ownership of such entity.
24 |
25 | "You" (or "Your") shall mean an individual or Legal Entity
26 | exercising permissions granted by this License.
27 |
28 | "Source" form shall mean the preferred form for making modifications,
29 | including but not limited to software source code, documentation
30 | source, and configuration files.
31 |
32 | "Object" form shall mean any form resulting from mechanical
33 | transformation or translation of a Source form, including but
34 | not limited to compiled object code, generated documentation,
35 | and conversions to other media types.
36 |
37 | "Work" shall mean the work of authorship, whether in Source or
38 | Object form, made available under the License, as indicated by a
39 | copyright notice that is included in or attached to the work
40 | (an example is provided in the Appendix below).
41 |
42 | "Derivative Works" shall mean any work, whether in Source or Object
43 | form, that is based on (or derived from) the Work and for which the
44 | editorial revisions, annotations, elaborations, or other modifications
45 | represent, as a whole, an original work of authorship. For the purposes
46 | of this License, Derivative Works shall not include works that remain
47 | separable from, or merely link (or bind by name) to the interfaces of,
48 | the Work and Derivative Works thereof.
49 |
50 | "Contribution" shall mean any work of authorship, including
51 | the original version of the Work and any modifications or additions
52 | to that Work or Derivative Works thereof, that is intentionally
53 | submitted to Licensor for inclusion in the Work by the copyright owner
54 | or by an individual or Legal Entity authorized to submit on behalf of
55 | the copyright owner. For the purposes of this definition, "submitted"
56 | means any form of electronic, verbal, or written communication sent
57 | to the Licensor or its representatives, including but not limited to
58 | communication on electronic mailing lists, source code control systems,
59 | and issue tracking systems that are managed by, or on behalf of, the
60 | Licensor for the purpose of discussing and improving the Work, but
61 | excluding communication that is conspicuously marked or otherwise
62 | designated in writing by the copyright owner as "Not a Contribution."
63 |
64 | "Contributor" shall mean Licensor and any individual or Legal Entity
65 | on behalf of whom a Contribution has been received by Licensor and
66 | subsequently incorporated within the Work.
67 |
68 | 2. Grant of Copyright License. Subject to the terms and conditions of
69 | this License, each Contributor hereby grants to You a perpetual,
70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71 | copyright license to reproduce, prepare Derivative Works of,
72 | publicly display, publicly perform, sublicense, and distribute the
73 | Work and such Derivative Works in Source or Object form.
74 |
75 | 3. Grant of Patent License. Subject to the terms and conditions of
76 | this License, each Contributor hereby grants to You a perpetual,
77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78 | (except as stated in this section) patent license to make, have made,
79 | use, offer to sell, sell, import, and otherwise transfer the Work,
80 | where such license applies only to those patent claims licensable
81 | by such Contributor that are necessarily infringed by their
82 | Contribution(s) alone or by combination of their Contribution(s)
83 | with the Work to which such Contribution(s) was submitted. If You
84 | institute patent litigation against any entity (including a
85 | cross-claim or counterclaim in a lawsuit) alleging that the Work
86 | or a Contribution incorporated within the Work constitutes direct
87 | or contributory patent infringement, then any patent licenses
88 | granted to You under this License for that Work shall terminate
89 | as of the date such litigation is filed.
90 |
91 | 4. Redistribution. You may reproduce and distribute copies of the
92 | Work or Derivative Works thereof in any medium, with or without
93 | modifications, and in Source or Object form, provided that You
94 | meet the following conditions:
95 |
96 | (a) You must give any other recipients of the Work or
97 | Derivative Works a copy of this License; and
98 |
99 | (b) You must cause any modified files to carry prominent notices
100 | stating that You changed the files; and
101 |
102 | (c) You must retain, in the Source form of any Derivative Works
103 | that You distribute, all copyright, patent, trademark, and
104 | attribution notices from the Source form of the Work,
105 | excluding those notices that do not pertain to any part of
106 | the Derivative Works; and
107 |
108 | (d) If the Work includes a "NOTICE" text file as part of its
109 | distribution, then any Derivative Works that You distribute must
110 | include a readable copy of the attribution notices contained
111 | within such NOTICE file, excluding those notices that do not
112 | pertain to any part of the Derivative Works, in at least one
113 | of the following places: within a NOTICE text file distributed
114 | as part of the Derivative Works; within the Source form or
115 | documentation, if provided along with the Derivative Works; or,
116 | within a display generated by the Derivative Works, if and
117 | wherever such third-party notices normally appear. The contents
118 | of the NOTICE file are for informational purposes only and
119 | do not modify the License. You may add Your own attribution
120 | notices within Derivative Works that You distribute, alongside
121 | or as an addendum to the NOTICE text from the Work, provided
122 | that such additional attribution notices cannot be construed
123 | as modifying the License.
124 |
125 | You may add Your own copyright statement to Your modifications and
126 | may provide additional or different license terms and conditions
127 | for use, reproduction, or distribution of Your modifications, or
128 | for any such Derivative Works as a whole, provided Your use,
129 | reproduction, and distribution of the Work otherwise complies with
130 | the conditions stated in this License.
131 |
132 | 5. Submission of Contributions. Unless You explicitly state otherwise,
133 | any Contribution intentionally submitted for inclusion in the Work
134 | by You to the Licensor shall be under the terms and conditions of
135 | this License, without any additional terms or conditions.
136 | Notwithstanding the above, nothing herein shall supersede or modify
137 | the terms of any separate license agreement you may have executed
138 | with Licensor regarding such Contributions.
139 |
140 | 6. Trademarks. This License does not grant permission to use the trade
141 | names, trademarks, service marks, or product names of the Licensor,
142 | except as required for reasonable and customary use in describing the
143 | origin of the Work and reproducing the content of the NOTICE file.
144 |
145 | 7. Disclaimer of Warranty. Unless required by applicable law or
146 | agreed to in writing, Licensor provides the Work (and each
147 | Contributor provides its Contributions) on an "AS IS" BASIS,
148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149 | implied, including, without limitation, any warranties or conditions
150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151 | PARTICULAR PURPOSE. You are solely responsible for determining the
152 | appropriateness of using or redistributing the Work and assume any
153 | risks associated with Your exercise of permissions under this License.
154 |
155 | 8. Limitation of Liability. In no event and under no legal theory,
156 | whether in tort (including negligence), contract, or otherwise,
157 | unless required by applicable law (such as deliberate and grossly
158 | negligent acts) or agreed to in writing, shall any Contributor be
159 | liable to You for damages, including any direct, indirect, special,
160 | incidental, or consequential damages of any character arising as a
161 | result of this License or out of the use or inability to use the
162 | Work (including but not limited to damages for loss of goodwill,
163 | work stoppage, computer failure or malfunction, or any and all
164 | other commercial damages or losses), even if such Contributor
165 | has been advised of the possibility of such damages.
166 |
167 | 9. Accepting Warranty or Additional Liability. While redistributing
168 | the Work or Derivative Works thereof, You may choose to offer,
169 | and charge a fee for, acceptance of support, warranty, indemnity,
170 | or other liability obligations and/or rights consistent with this
171 | License. However, in accepting such obligations, You may act only
172 | on Your own behalf and on Your sole responsibility, not on behalf
173 | of any other Contributor, and only if You agree to indemnify,
174 | defend, and hold each Contributor harmless for any liability
175 | incurred by, or claims asserted against, such Contributor by reason
176 | of your accepting any such warranty or additional liability.
177 |
178 | END OF TERMS AND CONDITIONS
179 |
180 | APPENDIX: How to apply the Apache License to your work.
181 |
182 | To apply the Apache License to your work, attach the following
183 | boilerplate notice, with the fields enclosed by brackets "[]"
184 | replaced with your own identifying information. (Don't include
185 | the brackets!) The text should be enclosed in the appropriate
186 | comment syntax for the file format. We also recommend that a
187 | file or class name and description of purpose be included on the
188 | same "printed page" as the copyright notice for easier
189 | identification within third-party archives.
190 |
191 | Copyright 2008-2011 Google Inc.
192 |
193 | Licensed under the Apache License, Version 2.0 (the "License");
194 | you may not use this file except in compliance with the License.
195 | You may obtain a copy of the License at
196 |
197 | http://www.apache.org/licenses/LICENSE-2.0
198 |
199 | Unless required by applicable law or agreed to in writing, software
200 | distributed under the License is distributed on an "AS IS" BASIS,
201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202 | See the License for the specific language governing permissions and
203 | limitations under the License.
204 |
--------------------------------------------------------------------------------
/nbproject/project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.netbeans.modules.apisupport.project
4 |
5 |
6 | com.junichi11.netbeans.php.enhancements
7 |
8 |
9 |
10 | org.apache.commons.lang
11 |
12 |
13 |
14 | 2.4.0
15 |
16 |
17 |
18 | org.netbeans.api.annotations.common
19 |
20 |
21 |
22 | 1
23 | 1.23.1
24 |
25 |
26 |
27 | org.netbeans.api.progress
28 |
29 |
30 |
31 | 1
32 | 1.46.1
33 |
34 |
35 |
36 | org.netbeans.api.templates
37 |
38 |
39 |
40 | 1.6.1
41 |
42 |
43 |
44 | org.netbeans.modules.csl.api
45 |
46 |
47 |
48 | 2
49 | 2.46.1.2.1.1.8
50 |
51 |
52 |
53 | org.netbeans.modules.csl.types
54 |
55 |
56 |
57 | 1
58 | 1.0.1
59 |
60 |
61 |
62 | org.netbeans.modules.editor
63 |
64 |
65 |
66 | 3
67 | 1.71.2.5.21.40
68 |
69 |
70 |
71 | org.netbeans.modules.editor.codetemplates
72 |
73 |
74 |
75 | 1
76 | 1.30.1.1
77 |
78 |
79 |
80 | org.netbeans.modules.editor.completion
81 |
82 |
83 |
84 | 1
85 | 1.36.1.2
86 |
87 |
88 |
89 | org.netbeans.modules.editor.document
90 |
91 |
92 |
93 | 1.5.1.1
94 |
95 |
96 |
97 | org.netbeans.modules.editor.lib
98 |
99 |
100 |
101 | 3
102 | 3.46.1.22.43
103 |
104 |
105 |
106 | org.netbeans.modules.editor.lib2
107 |
108 |
109 |
110 | 1
111 | 2.4.1.44.1
112 |
113 |
114 |
115 | org.netbeans.modules.editor.mimelookup
116 |
117 |
118 |
119 | 1
120 | 1.29.1
121 |
122 |
123 |
124 | org.netbeans.modules.html.lexer
125 |
126 |
127 |
128 | 1
129 | 1.22.1
130 |
131 |
132 |
133 | org.netbeans.modules.lexer
134 |
135 |
136 |
137 | 2
138 | 1.53.1.1
139 |
140 |
141 |
142 | org.netbeans.modules.options.api
143 |
144 |
145 |
146 | 1
147 | 1.36.1
148 |
149 |
150 |
151 | org.netbeans.modules.parsing.api
152 |
153 |
154 |
155 | 1
156 | 9.5.1.8
157 |
158 |
159 |
160 | org.netbeans.modules.php.editor
161 |
162 |
163 |
164 | 2
165 |
166 |
167 |
168 |
169 | org.openide.awt
170 |
171 |
172 |
173 | 7.55.1
174 |
175 |
176 |
177 | org.openide.dialogs
178 |
179 |
180 |
181 | 7.28.1
182 |
183 |
184 |
185 | org.openide.filesystems
186 |
187 |
188 |
189 | 9.8.1
190 |
191 |
192 |
193 | org.openide.loaders
194 |
195 |
196 |
197 | 7.44.3
198 |
199 |
200 |
201 | org.openide.modules
202 |
203 |
204 |
205 | 7.63
206 |
207 |
208 |
209 | org.openide.nodes
210 |
211 |
212 |
213 | 7.33.2
214 |
215 |
216 |
217 | org.openide.text
218 |
219 |
220 |
221 | 6.54.2
222 |
223 |
224 |
225 | org.openide.util
226 |
227 |
228 |
229 | 8.29.3
230 |
231 |
232 |
233 | org.openide.util.lookup
234 |
235 |
236 |
237 | 8.19.1
238 |
239 |
240 |
241 | org.openide.util.ui
242 |
243 |
244 |
245 | 9.4.1
246 |
247 |
248 |
249 |
250 |
251 | unit
252 |
253 | org.netbeans.insane
254 |
255 |
256 |
257 | org.netbeans.libs.junit4
258 |
259 |
260 |
261 | org.netbeans.modules.nbjunit
262 |
263 |
264 |
265 |
266 |
267 |
268 | ext/gson-2.2.4-for-php-enhancements.jar
269 | release/modules/ext/gson-2.2.4-for-php-enhancements.jar
270 |
271 |
272 |
273 |
274 |
--------------------------------------------------------------------------------
/src/com/junichi11/netbeans/php/enhancements/editor/generator/ui/DummyTextPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 junichi11.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.junichi11.netbeans.php.enhancements.editor.generator.ui;
17 |
18 | import com.junichi11.netbeans.php.enhancements.options.DummyTextOptions;
19 | import javax.swing.JPanel;
20 | import javax.swing.JSpinner;
21 | import javax.swing.JTextField;
22 |
23 | /**
24 | *
25 | * @author junichi11
26 | */
27 | public class DummyTextPanel extends JPanel {
28 |
29 | private static final long serialVersionUID = 5438353469413806727L;
30 | private static final DummyTextPanel INSTANCE = new DummyTextPanel();
31 |
32 | /**
33 | * Creates new form DummyTextPanel
34 | */
35 | public DummyTextPanel() {
36 | initComponents();
37 |
38 | init();
39 | }
40 |
41 | public static DummyTextPanel getDefault() {
42 | return INSTANCE;
43 | }
44 |
45 | private void init() {
46 | load();
47 |
48 | // right alignment
49 | JSpinner.DefaultEditor textLengthSpinnerEditor = (JSpinner.DefaultEditor) textLengthSpinner.getEditor();
50 | textLengthSpinnerEditor.getTextField().setHorizontalAlignment(JTextField.RIGHT);
51 | JSpinner.DefaultEditor loopCountSpinnerEditor = (JSpinner.DefaultEditor) loopCountSpinner.getEditor();
52 | loopCountSpinnerEditor.getTextField().setHorizontalAlignment(JTextField.RIGHT);
53 | setEnabledLoopGroup();
54 | }
55 |
56 | private void load() {
57 | DummyTextOptions options = DummyTextOptions.getInstance();
58 | textTextArea.setText(options.getText());
59 | loopCheckBox.setSelected(options.isLoop());
60 | textLengthRadioButton.setSelected(options.isTextLength());
61 | loopCountRadioButton.setSelected(options.isLoopCount());
62 | textLengthSpinner.setValue(options.getTextLength());
63 | loopCountSpinner.setValue(options.getLoopCount());
64 | }
65 |
66 | public boolean isLoop() {
67 | return loopCheckBox.isSelected();
68 | }
69 |
70 | public boolean isLoopCount() {
71 | return loopCountRadioButton.isSelected();
72 | }
73 |
74 | public int getLoopCount() {
75 | return (Integer) loopCountSpinner.getValue();
76 | }
77 |
78 | public boolean isTextLength() {
79 | return textLengthRadioButton.isSelected();
80 | }
81 |
82 | public int getTextLength() {
83 | return (Integer) textLengthSpinner.getValue();
84 | }
85 |
86 | public String getText() {
87 | return textTextArea.getText();
88 | }
89 |
90 | public String getInsertText() {
91 | String text = getText();
92 | String insertText = ""; // NOI18N
93 |
94 | if (text == null || text.isEmpty()) {
95 | return insertText;
96 | }
97 |
98 | if (!isLoop()) {
99 | return text;
100 | }
101 |
102 | // loop
103 | if (isLoopCount()) {
104 | insertText = getInsertTextWithLoopCount(text);
105 | } else if (isTextLength()) {
106 | insertText = getInsertTextWithTextLength(text);
107 | }
108 |
109 | return insertText;
110 | }
111 |
112 | private String getInsertTextWithLoopCount(String text) {
113 | StringBuilder sb = new StringBuilder();
114 | int loopCount = getLoopCount();
115 | for (int i = 0; i < loopCount; i++) {
116 | sb.append(text);
117 | }
118 | return sb.toString();
119 | }
120 |
121 | private String getInsertTextWithTextLength(String text) {
122 | StringBuilder sb = new StringBuilder();
123 | int textLength = getTextLength();
124 | sb.append(text);
125 | while (sb.length() < textLength) {
126 | sb.append(sb.toString());
127 | }
128 | sb.delete(textLength, sb.length());
129 | return sb.toString();
130 | }
131 |
132 | private void setEnabledLoopGroup() {
133 | boolean isSelected = loopCheckBox.isSelected();
134 | loopCountSpinner.setEnabled(isSelected);
135 | textLengthSpinner.setEnabled(isSelected);
136 | loopCountRadioButton.setEnabled(isSelected);
137 | textLengthRadioButton.setEnabled(isSelected);
138 | }
139 |
140 | /**
141 | * This method is called from within the constructor to initialize the form.
142 | * WARNING: Do NOT modify this code. The content of this method is always
143 | * regenerated by the Form Editor.
144 | */
145 | @SuppressWarnings("unchecked")
146 | // //GEN-BEGIN:initComponents
147 | private void initComponents() {
148 |
149 | loopButtonGroup = new javax.swing.ButtonGroup();
150 | textLabel = new javax.swing.JLabel();
151 | jScrollPane1 = new javax.swing.JScrollPane();
152 | textTextArea = new javax.swing.JTextArea();
153 | loopCheckBox = new javax.swing.JCheckBox();
154 | textLengthRadioButton = new javax.swing.JRadioButton();
155 | loopCountRadioButton = new javax.swing.JRadioButton();
156 | saveAsDefaultButton = new javax.swing.JButton();
157 | loadDefaultButton = new javax.swing.JButton();
158 | textLengthSpinner = new javax.swing.JSpinner();
159 | loopCountSpinner = new javax.swing.JSpinner();
160 |
161 | org.openide.awt.Mnemonics.setLocalizedText(textLabel, org.openide.util.NbBundle.getMessage(DummyTextPanel.class, "DummyTextPanel.textLabel.text")); // NOI18N
162 |
163 | textTextArea.setColumns(20);
164 | textTextArea.setRows(5);
165 | jScrollPane1.setViewportView(textTextArea);
166 |
167 | org.openide.awt.Mnemonics.setLocalizedText(loopCheckBox, org.openide.util.NbBundle.getMessage(DummyTextPanel.class, "DummyTextPanel.loopCheckBox.text")); // NOI18N
168 | loopCheckBox.addActionListener(new java.awt.event.ActionListener() {
169 | public void actionPerformed(java.awt.event.ActionEvent evt) {
170 | loopCheckBoxActionPerformed(evt);
171 | }
172 | });
173 |
174 | loopButtonGroup.add(textLengthRadioButton);
175 | org.openide.awt.Mnemonics.setLocalizedText(textLengthRadioButton, org.openide.util.NbBundle.getMessage(DummyTextPanel.class, "DummyTextPanel.textLengthRadioButton.text")); // NOI18N
176 |
177 | loopButtonGroup.add(loopCountRadioButton);
178 | org.openide.awt.Mnemonics.setLocalizedText(loopCountRadioButton, org.openide.util.NbBundle.getMessage(DummyTextPanel.class, "DummyTextPanel.loopCountRadioButton.text")); // NOI18N
179 |
180 | org.openide.awt.Mnemonics.setLocalizedText(saveAsDefaultButton, org.openide.util.NbBundle.getMessage(DummyTextPanel.class, "DummyTextPanel.saveAsDefaultButton.text")); // NOI18N
181 | saveAsDefaultButton.addActionListener(new java.awt.event.ActionListener() {
182 | public void actionPerformed(java.awt.event.ActionEvent evt) {
183 | saveAsDefaultButtonActionPerformed(evt);
184 | }
185 | });
186 |
187 | org.openide.awt.Mnemonics.setLocalizedText(loadDefaultButton, org.openide.util.NbBundle.getMessage(DummyTextPanel.class, "DummyTextPanel.loadDefaultButton.text")); // NOI18N
188 | loadDefaultButton.addActionListener(new java.awt.event.ActionListener() {
189 | public void actionPerformed(java.awt.event.ActionEvent evt) {
190 | loadDefaultButtonActionPerformed(evt);
191 | }
192 | });
193 |
194 | textLengthSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(100), Integer.valueOf(1), null, Integer.valueOf(1)));
195 |
196 | loopCountSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(5), Integer.valueOf(1), null, Integer.valueOf(1)));
197 |
198 | javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
199 | this.setLayout(layout);
200 | layout.setHorizontalGroup(
201 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
202 | .addGroup(layout.createSequentialGroup()
203 | .addContainerGap()
204 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
205 | .addGroup(layout.createSequentialGroup()
206 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
207 | .addGroup(layout.createSequentialGroup()
208 | .addComponent(textLabel)
209 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
210 | .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE))
211 | .addGroup(layout.createSequentialGroup()
212 | .addComponent(loopCheckBox)
213 | .addGap(0, 0, Short.MAX_VALUE)))
214 | .addContainerGap())
215 | .addGroup(layout.createSequentialGroup()
216 | .addGap(12, 12, 12)
217 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218 | .addComponent(textLengthRadioButton)
219 | .addComponent(loopCountRadioButton))
220 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
221 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
222 | .addComponent(textLengthSpinner, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
223 | .addComponent(loopCountSpinner))
224 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
225 | .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
226 | .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
227 | .addComponent(loadDefaultButton)
228 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
229 | .addComponent(saveAsDefaultButton)
230 | .addContainerGap())
231 | );
232 | layout.setVerticalGroup(
233 | layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
234 | .addGroup(layout.createSequentialGroup()
235 | .addContainerGap()
236 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
237 | .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
238 | .addComponent(textLabel))
239 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
240 | .addComponent(loopCheckBox)
241 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
242 | .addComponent(textLengthRadioButton)
243 | .addComponent(textLengthSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
244 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
245 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
246 | .addComponent(loopCountRadioButton)
247 | .addComponent(loopCountSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
248 | .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
249 | .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
250 | .addComponent(saveAsDefaultButton)
251 | .addComponent(loadDefaultButton))
252 | .addContainerGap())
253 | );
254 | }// //GEN-END:initComponents
255 |
256 | private void loopCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loopCheckBoxActionPerformed
257 | setEnabledLoopGroup();
258 | }//GEN-LAST:event_loopCheckBoxActionPerformed
259 |
260 | private void saveAsDefaultButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsDefaultButtonActionPerformed
261 | DummyTextOptions options = DummyTextOptions.getInstance();
262 | options.setLoop(isLoop());
263 | options.setLoopCount(isLoopCount());
264 | options.setLoopCount(getLoopCount());
265 | options.setText(getText());
266 | options.setTextLength(isTextLength());
267 | options.setTextLength(getTextLength());
268 | }//GEN-LAST:event_saveAsDefaultButtonActionPerformed
269 |
270 | private void loadDefaultButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadDefaultButtonActionPerformed
271 | load();
272 | setEnabledLoopGroup();
273 | }//GEN-LAST:event_loadDefaultButtonActionPerformed
274 | // Variables declaration - do not modify//GEN-BEGIN:variables
275 | private javax.swing.JScrollPane jScrollPane1;
276 | private javax.swing.JButton loadDefaultButton;
277 | private javax.swing.ButtonGroup loopButtonGroup;
278 | private javax.swing.JCheckBox loopCheckBox;
279 | private javax.swing.JRadioButton loopCountRadioButton;
280 | private javax.swing.JSpinner loopCountSpinner;
281 | private javax.swing.JButton saveAsDefaultButton;
282 | private javax.swing.JLabel textLabel;
283 | private javax.swing.JRadioButton textLengthRadioButton;
284 | private javax.swing.JSpinner textLengthSpinner;
285 | private javax.swing.JTextArea textTextArea;
286 | // End of variables declaration//GEN-END:variables
287 |
288 | }
289 |
--------------------------------------------------------------------------------