Skip to content

Commit 1ded59b

Browse files
committed
Merge branch 'nb74dev'
2 parents ec3f7d9 + adfd92f commit 1ded59b

5 files changed

Lines changed: 90 additions & 19 deletions

File tree

manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ Manifest-Version: 1.0
22
OpenIDE-Module: org.netbeans.modules.php.wordpress
33
OpenIDE-Module-Layer: org/netbeans/modules/php/wordpress/resources/layer.xml
44
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/php/wordpress/Bundle.properties
5-
OpenIDE-Module-Specification-Version: 0.6.3
5+
OpenIDE-Module-Specification-Version: 0.6.4
66
OpenIDE-Module-Install: org/netbeans/modules/php/wordpress/WordPressModule.class

nbproject/phpcsmd.properties

Whitespace-only changes.

src/org/netbeans/modules/php/wordpress/editor/completion/FilterAndActionCompletion.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@
5353
import java.util.Set;
5454
import java.util.logging.Level;
5555
import java.util.logging.Logger;
56-
import javax.swing.text.AbstractDocument;
5756
import javax.swing.text.Document;
5857
import javax.swing.text.JTextComponent;
5958
import org.netbeans.api.editor.mimelookup.MimeRegistration;
6059
import org.netbeans.api.lexer.Token;
61-
import org.netbeans.api.lexer.TokenHierarchy;
6260
import org.netbeans.api.lexer.TokenSequence;
6361
import org.netbeans.modules.parsing.spi.indexing.support.QuerySupport;
6462
import org.netbeans.modules.php.api.phpmodule.PhpModule;
@@ -70,6 +68,7 @@
7068
import org.netbeans.modules.php.editor.api.elements.FunctionElement;
7169
import org.netbeans.modules.php.editor.lexer.PHPTokenId;
7270
import org.netbeans.modules.php.wordpress.util.Charset;
71+
import org.netbeans.modules.php.wordpress.util.DocUtils;
7372
import org.netbeans.spi.editor.completion.CompletionProvider;
7473
import org.netbeans.spi.editor.completion.CompletionResultSet;
7574
import org.netbeans.spi.editor.completion.CompletionTask;
@@ -87,7 +86,7 @@
8786
*
8887
* @author junichi11
8988
*/
90-
@MimeRegistration(mimeType = "text/x-php5", service = CompletionProvider.class)
89+
@MimeRegistration(mimeType = FileUtils.PHP_MIME_TYPE, service = CompletionProvider.class)
9190
public final class FilterAndActionCompletion extends WordPressCompletionProvider {
9291

9392
private static final Logger LOGGER = Logger.getLogger(FilterAndActionCompletion.class.getName());
@@ -112,16 +111,15 @@ public CompletionTask createTask(int queryType, JTextComponent component, final
112111
return new AsyncCompletionTask(new AsyncCompletionQuery() {
113112
@Override
114113
protected void query(CompletionResultSet completionResultSet, Document doc, int caretOffset) {
115-
AbstractDocument ad = (AbstractDocument) doc;
116-
ad.readLock();
117-
TokenHierarchy hierarchy = TokenHierarchy.get(doc);
118114
try {
119-
TokenSequence<PHPTokenId> ts = (TokenSequence<PHPTokenId>) hierarchy.tokenSequence(PHPTokenId.language());
115+
TokenSequence<PHPTokenId> ts = DocUtils.getTokenSequence(doc);
116+
if (ts == null) {
117+
return;
118+
}
120119
ts.move(caretOffset);
121120
ts.moveNext();
122121
Token<PHPTokenId> token = ts.token();
123122
if (token.id() != PHPTokenId.PHP_CONSTANT_ENCAPSED_STRING) {
124-
completionResultSet.finish();
125123
return;
126124
}
127125
String caretInput = ts.token().text().toString();
@@ -135,7 +133,6 @@ protected void query(CompletionResultSet completionResultSet, Document doc, int
135133

136134
// check whether funciton is add_filter
137135
if (!isValidCompletion(ts) || length < 2) {
138-
completionResultSet.finish();
139136
return;
140137
}
141138

@@ -161,10 +158,8 @@ protected void query(CompletionResultSet completionResultSet, Document doc, int
161158
}
162159
}
163160
} finally {
164-
ad.readUnlock();
161+
completionResultSet.finish();
165162
}
166-
167-
completionResultSet.finish();
168163
}
169164
}, component);
170165
}
@@ -267,10 +262,8 @@ public void refresh() {
267262
// use custom file
268263
if (phpModule != null) {
269264
FileObject projectDirectory = phpModule.getProjectDirectory();
270-
if (projectDirectory != null) {
271-
filterXml = projectDirectory.getFileObject(CUSTOM_FILTER_CODE_COMPLETION_XML);
272-
actionXml = projectDirectory.getFileObject(CUSTOM_ACTION_CODE_COMPLETION_XML);
273-
}
265+
filterXml = projectDirectory.getFileObject(CUSTOM_FILTER_CODE_COMPLETION_XML);
266+
actionXml = projectDirectory.getFileObject(CUSTOM_ACTION_CODE_COMPLETION_XML);
274267
}
275268
// TODO improve loop
276269
InputStream filterInputStream = null;

src/org/netbeans/modules/php/wordpress/resources/org-netbeans-modules-phpeditor-snippets.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Portions Copyrighted 2013 Sun Microsystems, Inc.
4343

4444
<!DOCTYPE codetemplates PUBLIC "-//NetBeans//DTD Editor Code Templates settings 1.0//EN" "http://www.netbeans.org/dtds/EditorCodeTemplates-1_0.dtd">
4545
<codetemplates>
46-
<codetemplate abbreviation="wpph" xml:space="preserve">
46+
<codetemplate contexts="wp-code" abbreviation="wpph">
4747
<code><![CDATA[/*
4848
Plugin Name: ${name}
4949
Plugin URI: http://${url}/
@@ -56,7 +56,7 @@ License: ${GPLv2}
5656
${cursor}]]></code>
5757
<description>WordPress Snippet wordpress plugin header</description>
5858
</codetemplate>
59-
<codetemplate abbreviation="wpgpl" xml:space="preserve">
59+
<codetemplate contexts="wp-code" abbreviation="wpgpl">
6060
<code><![CDATA[/* Copyright ${year} ${author_name} (email : ${email})
6161
6262
This program is free software; you can redistribute it and/or modify
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2013 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*
40+
* Portions Copyrighted 2013 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress.util;
43+
44+
import javax.swing.text.AbstractDocument;
45+
import javax.swing.text.Document;
46+
import org.netbeans.api.lexer.TokenHierarchy;
47+
import org.netbeans.api.lexer.TokenSequence;
48+
import org.netbeans.modules.php.editor.lexer.PHPTokenId;
49+
50+
/**
51+
*
52+
* @author junichi11
53+
*/
54+
public final class DocUtils {
55+
56+
private DocUtils() {
57+
}
58+
59+
/**
60+
* Get token sequence.
61+
*
62+
* @param doc
63+
* @return token sequence
64+
*/
65+
public static TokenSequence<PHPTokenId> getTokenSequence(Document doc) {
66+
AbstractDocument ad = (AbstractDocument) doc;
67+
ad.readLock();
68+
TokenSequence<PHPTokenId> ts = null;
69+
try {
70+
TokenHierarchy hierarchy = TokenHierarchy.get(doc);
71+
ts = (TokenSequence<PHPTokenId>) hierarchy.tokenSequence(PHPTokenId.language());
72+
} finally {
73+
ad.readUnlock();
74+
}
75+
return ts;
76+
}
77+
78+
}

0 commit comments

Comments
 (0)