<orderEntry type="module" module-name="openapi" />
<orderEntry type="library" name="JUnit4" level="project" />
<orderEntry type="module" module-name="lang-impl" />
+ <orderEntry type="module" module-name="ExtendedApi" />
</component>
<component name="RetroweaverPlugin">
<setting name="active" value="false" />
<extensions defaultExtensionNs="com.intellij">
<errorHandler implementation="com.intellij.diagnostic.ITNReporter" />
+
+ <lang.documentationProvider language="RegExp" implementationClass="org.intellij.lang.regexp.RegExpDocumentionProvider"/>
+ <completion.contributor implementation="org.intellij.lang.regexp.RegExpCompletionContributor"/>
</extensions>
</idea-plugin>
--- /dev/null
+package org.intellij.lang.regexp;
+
+import com.intellij.codeInsight.TailType;
+import com.intellij.codeInsight.completion.*;
+import com.intellij.codeInsight.lookup.LookupElementFactory;
+import com.intellij.codeInsight.lookup.MutableLookupElement;
+import com.intellij.patterns.ElementPattern;
+import static com.intellij.patterns.PlatformPatterns.psiElement;
+import com.intellij.psi.PsiElement;
+import com.intellij.util.ProcessingContext;
+import org.intellij.lang.regexp.psi.impl.RegExpPropertyImpl;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: vnikolaenko
+ * Date: 22.09.2008
+ * Time: 12:14:14
+ * To change this template use File | Settings | File Templates.
+ */
+public class RegExpCompletionContributor extends CompletionContributor {
+ public RegExpCompletionContributor() {
+ final ElementPattern<PsiElement> backSlashPattern = psiElement().withText("\\\\");
+ extend(CompletionType.BASIC, psiElement().afterLeaf(backSlashPattern), new CharacterClassesNameCompletionProvider());
+
+ final ElementPattern<PsiElement> propertyPattern
+ = psiElement().withText("p").afterLeaf(backSlashPattern);
+ extend(CompletionType.BASIC, psiElement().afterLeaf(propertyPattern), new PropertyCompletionProvider());
+
+ final ElementPattern<PsiElement> propertyNamePattern
+ = psiElement().afterLeaf(psiElement().withText("{").afterLeaf(propertyPattern));
+ extend(CompletionType.BASIC, propertyNamePattern, new PropertyNameCompletionProvider());
+ }
+
+ private static MutableLookupElement<String> addLookupElement(final CompletionResultSet result,
+ final String name) {
+ MutableLookupElement<String> element = LookupElementFactory.getInstance().createLookupElement(name);
+ result.addElement(element);
+ return element;
+ }
+
+ private static class PropertyNameCompletionProvider extends CompletionProvider<CompletionParameters> {
+
+ public void addCompletions(@NotNull final CompletionParameters parameters,
+ final ProcessingContext context,
+ @NotNull final CompletionResultSet result) {
+ for (String[] stringArray : RegExpPropertyImpl.PROPERTY_NAMES) {
+ addLookupElement(result, stringArray[0]).setTailType(TailType.createSimpleTailType('}'));
+ }
+ }
+ }
+
+ private static class PropertyCompletionProvider extends CompletionProvider<CompletionParameters> {
+
+ public void addCompletions(@NotNull final CompletionParameters parameters,
+ final ProcessingContext context,
+ @NotNull final CompletionResultSet result) {
+ for (String[] stringArray : RegExpPropertyImpl.PROPERTY_NAMES) {
+ addLookupElement(result, "{" + stringArray[0] + "}");
+ }
+ }
+ }
+ private static class CharacterClassesNameCompletionProvider extends CompletionProvider<CompletionParameters> {
+
+ public void addCompletions(@NotNull final CompletionParameters parameters,
+ final ProcessingContext context,
+ @NotNull final CompletionResultSet result) {
+ String[] completions = {
+ "d", "D", "s", "S", "w", "W", "b", "B", "A", "G", "Z", "z", "Q", "E",
+ "t", "n", "r", "f", "a", "e"
+ };
+ for (String s : completions) {
+ addLookupElement(result, s);
+ }
+ for (String[] stringArray : RegExpPropertyImpl.PROPERTY_NAMES) {
+ addLookupElement(result, "p{" + stringArray[0] + "}");
+ }
+ }
+ }
+}
--- /dev/null
+package org.intellij.lang.regexp;
+
+import com.intellij.lang.documentation.QuickDocumentationProvider;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiManager;
+import org.intellij.lang.regexp.psi.impl.RegExpPropertyImpl;
+import org.intellij.lang.regexp.psi.impl.RegExpElementImpl;
+import org.intellij.lang.regexp.psi.RegExpGroup;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: vnikolaenko
+ * Date: 17.09.2008
+ * Time: 19:24:29
+ * To change this template use File | Settings | File Templates.
+ */
+public class RegExpDocumentionProvider extends QuickDocumentationProvider {
+ @Nullable
+ public String getUrlFor(PsiElement element, PsiElement originalElement) {
+ return null;
+ }
+
+ @Nullable
+ public String generateDoc(PsiElement element, PsiElement originalElement) {
+ if (element instanceof RegExpPropertyImpl) {
+ String elementName = ((RegExpPropertyImpl)element).getCategoryNode().getText();
+ for (String[] stringArray : RegExpPropertyImpl.PROPERTY_NAMES) {
+ if (stringArray[0].equals(elementName)) {
+ return "Property block stands for " + stringArray[1];
+ }
+ }
+ }
+ return null;
+ }
+
+ @Nullable
+ public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object, PsiElement element){
+ return null;
+ }
+
+ @Nullable
+ public PsiElement getDocumentationElementForLink(PsiManager psiManager, String link, PsiElement context) {
+ return null;
+ }
+
+ @Nullable
+ public String getQuickNavigateInfo(PsiElement element) {
+ if (element instanceof RegExpGroup) {
+ return "Capturing Group: " + ((RegExpElementImpl)element).getUnescapedText();
+ } else {
+ return null;
+ }
+ }
+}
*/
package org.intellij.lang.regexp;
-import com.intellij.lang.BracePair;
-import com.intellij.lang.Language;
-import com.intellij.lang.LanguageAnnotators;
-import com.intellij.lang.LanguageBraceMatching;
-import com.intellij.lang.LanguageDocumentation;
-import com.intellij.lang.LanguageParserDefinitions;
-import com.intellij.lang.LanguageSurrounders;
-import com.intellij.lang.PairedBraceMatcher;
-import com.intellij.lang.documentation.QuickDocumentationProvider;
+import com.intellij.lang.*;
import com.intellij.openapi.fileTypes.SingleLazyInstanceSyntaxHighlighterFactory;
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory;
-import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.tree.IElementType;
-import org.intellij.lang.regexp.psi.RegExpGroup;
-import org.intellij.lang.regexp.psi.impl.RegExpElementImpl;
import org.intellij.lang.regexp.surroundWith.SimpleSurroundDescriptor;
import org.intellij.lang.regexp.validation.RegExpAnnotator;
import org.jetbrains.annotations.NotNull;
return new RegExpHighlighter(null, parserDefinition);
}
});
-
- LanguageDocumentation.INSTANCE.addExplicitExtension(this, new QuickDocumentationProvider() {
- @Nullable
- public String getQuickNavigateInfo(PsiElement element) {
- if (element instanceof RegExpGroup) {
- return "Capturing Group: " + ((RegExpElementImpl)element).getUnescapedText();
- } else {
- return null;
- }
- }
- });
}
@NotNull
--- /dev/null
+package test;
+
+import com.intellij.testFramework.fixtures.CodeInsightFixtureTestCase;
+import org.intellij.lang.regexp.psi.impl.RegExpPropertyImpl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: vnikolaenko
+ * Date: 25.09.2008
+ * Time: 15:10:10
+ */
+public class RegExpCompletionTest extends CodeInsightFixtureTestCase {
+
+ // util methods
+ private String getInputDataFileName(String testName) {
+ return Character.toUpperCase(testName.charAt(0)) + testName.substring(1) + ".regexp";
+ }
+
+ private String getExpectedResultFileName(String testName) {
+ return Character.toUpperCase(testName.charAt(0)) + testName.substring(1) + "Expected" + ".regexp";
+ }
+
+ public void testBackSlashVariants() throws Throwable {
+ java.util.List<String> nameList = new ArrayList<String>(Arrays.asList("d", "D", "s", "S", "w", "W", "b", "B", "A", "G", "Z", "z", "Q", "E",
+ "t", "n", "r", "f", "a", "e"));
+ for (String[] stringArray : RegExpPropertyImpl.PROPERTY_NAMES) {
+ nameList.add("p{" + stringArray[0] + "}");
+ }
+ myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), nameList.toArray(new String[nameList.size()]));
+ }
+
+ public void testPropertyVariants() throws Throwable {
+ java.util.List<String> nameList = new ArrayList<String>();
+ for (String[] stringArray : RegExpPropertyImpl.PROPERTY_NAMES) {
+ nameList.add("{" + stringArray[0] + "}");
+ }
+ myFixture.testCompletionVariants(getInputDataFileName(getTestName(true)), nameList.toArray(new String[nameList.size()]));
+ }
+
+ public void testPropertyAlpha() throws Throwable {
+ doTest();
+ }
+
+ public void doTest() throws Throwable {
+ String inputDataFileName = getInputDataFileName(getTestName(true));
+ String expectedResultFileName = getExpectedResultFileName(getTestName(true));
+ myFixture.testCompletion(inputDataFileName, expectedResultFileName);
+ }
+
+ @Override
+ protected String getBasePath() {
+ return "/svnPlugins/RegExpSupport/testData/completion";
+ }
+}
--- /dev/null
+[0-9]\\<caret>
--- /dev/null
+\\p{Alp<caret>}
--- /dev/null
+\\p{Alpha}
--- /dev/null
+[0-9].*\\p<caret>