use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.
the class StringPattern method matchesBrics.
@NotNull
public StringPattern matchesBrics(@NonNls @NotNull final String s) {
final String escaped = StringUtil.escapeToRegexp(s);
if (escaped.equals(s)) {
return equalTo(s);
}
StringBuilder sb = new StringBuilder(s.length() * 5);
for (int i = 0; i < s.length(); i++) {
final char c = s.charAt(i);
if (c == ' ') {
sb.append("<whitespacechar>");
} else //This is really stupid and inconvenient builder - it breaks any normal pattern with uppercase
if (Character.isUpperCase(c)) {
sb.append('[').append(Character.toUpperCase(c)).append(Character.toLowerCase(c)).append(']');
} else {
sb.append(c);
}
}
final RegExp regExp = new RegExp(sb.toString());
final Automaton automaton = regExp.toAutomaton(new DatatypesAutomatonProvider());
final RunAutomaton runAutomaton = new RunAutomaton(automaton, true);
return with(new ValuePatternCondition<String>("matchesBrics") {
@Override
public boolean accepts(@NotNull String str, final ProcessingContext context) {
return runAutomaton.run(str);
}
@Override
public Collection<String> getValues() {
return Collections.singleton(s);
}
});
}
use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.
the class InlineToAnonymousConstructorProcessor method addSuperConstructorArguments.
private void addSuperConstructorArguments(PsiExpressionList argumentList) throws IncorrectOperationException {
final PsiCodeBlock body = myConstructor.getBody();
assert body != null;
PsiStatement[] statements = body.getStatements();
if (statements.length == 0) {
return;
}
ProcessingContext context = new ProcessingContext();
if (!ourSuperCallPattern.accepts(statements[0], context)) {
return;
}
PsiExpressionList superArguments = context.get(ourCallKey).getArgumentList();
if (superArguments != null) {
for (PsiExpression argument : superArguments.getExpressions()) {
final PsiElement superArgument = replaceParameterReferences(argument.copy(), new ArrayList<>(), true);
argumentList.add(superArgument);
}
}
}
use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.
the class NamedObjectProviderBinding method addMatchingProviders.
static void addMatchingProviders(@NotNull PsiElement position, @Nullable final List<ProviderInfo<ElementPattern>> providerList, @NotNull Collection<ProviderInfo<ProcessingContext>> output, @NotNull PsiReferenceService.Hints hints) {
if (providerList == null)
return;
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < providerList.size(); i++) {
ProviderInfo<ElementPattern> info = providerList.get(i);
if (hints != PsiReferenceService.Hints.NO_HINTS && !info.provider.acceptsHints(position, hints)) {
continue;
}
final ProcessingContext context = new ProcessingContext();
if (hints != PsiReferenceService.Hints.NO_HINTS) {
context.put(PsiReferenceService.HINTS, hints);
}
boolean suitable = false;
try {
suitable = info.processingContext.accepts(position, context);
} catch (IndexNotReadyException ignored) {
}
if (suitable) {
output.add(new ProviderInfo<>(info.provider, context, info.priority));
}
}
}
use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.
the class StandardPatternsTest method testSave.
public void testSave() {
Key<String> key = Key.create("abc");
final ProcessingContext context = new ProcessingContext();
assertFalse(string().contains("abc").save(key).accepts(null));
assertNull(context.get(key));
assertFalse(string().contains("abc").save(key).accepts("def"));
assertNull(context.get(key));
final String s = "defabcdef";
assertTrue(string().contains("abc").save(key).accepts(s, context));
assertSame(s, context.get(key));
}
use of com.intellij.util.ProcessingContext in project intellij-plugins by JetBrains.
the class JstdConfigFileReferenceContributor method registerReferenceProviders.
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(JstdConfigFileUtils.CONFIG_FILE_ELEMENT_PATTERN, new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
final YAMLKeyValue keyValue = ObjectUtils.tryCast(element, YAMLKeyValue.class);
if (keyValue == null) {
return PsiReference.EMPTY_ARRAY;
}
final YAMLDocument yamlDocument = ObjectUtils.tryCast(keyValue.getParent(), YAMLDocument.class);
if (yamlDocument == null) {
return PsiReference.EMPTY_ARRAY;
}
final BasePathInfo basePathInfo = new BasePathInfo(yamlDocument);
if (BasePathInfo.isBasePathKey(keyValue)) {
PsiReference basePathRef = createBasePathRef(basePathInfo);
if (basePathRef != null) {
return new PsiReference[] { basePathRef };
}
} else if (JstdConfigFileUtils.isTopLevelKeyWithInnerFileSequence(keyValue)) {
VirtualFile basePath = basePathInfo.getBasePath();
if (basePath != null) {
List<PsiReference> references = Lists.newArrayList();
addReferencesForKeyValueWithInnerFileSequence(basePathInfo, keyValue, references);
return references.toArray(new PsiReference[references.size()]);
}
}
return PsiReference.EMPTY_ARRAY;
}
});
}
Aggregations