use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.
the class WordCompletionTest method testNoWordCompletionForNonSoftReference.
public void testNoWordCompletionForNonSoftReference() throws Throwable {
final PsiReferenceProvider softProvider = new PsiReferenceProvider() {
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
return new PsiReference[] { new PsiReferenceBase<PsiElement>(element, true) {
@Override
public PsiElement resolve() {
return null;
}
@Override
@NotNull
public Object[] getVariants() {
return new Object[] { "MySoftVariant" };
}
} };
}
};
final PsiReferenceProvider hardProvider = new PsiReferenceProvider() {
@Override
@NotNull
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull final ProcessingContext context) {
return new PsiReference[] { new PsiReferenceBase<PsiElement>(element, false) {
@Override
public PsiElement resolve() {
return null;
}
@Override
@NotNull
public Object[] getVariants() {
return new Object[] { "MyHardVariant" };
}
} };
}
};
PsiReferenceRegistrarImpl registrar = (PsiReferenceRegistrarImpl) ReferenceProvidersRegistry.getInstance().getRegistrar(StdLanguages.JAVA);
try {
registrar.registerReferenceProvider(PsiLiteralExpression.class, softProvider);
registrar.registerReferenceProvider(PsiLiteralExpression.class, hardProvider);
configureByFile(BASE_PATH + "3.java");
checkResultByFile(BASE_PATH + "3_after.java");
} finally {
registrar.unregisterReferenceProvider(PsiLiteralExpression.class, softProvider);
registrar.unregisterReferenceProvider(PsiLiteralExpression.class, hardProvider);
}
}
use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.
the class StringPattern method matches.
@NotNull
public StringPattern matches(@NonNls @NotNull final String s) {
final String escaped = StringUtil.escapeToRegexp(s);
if (escaped.equals(s)) {
return equalTo(s);
}
// may throw PatternSyntaxException here
final Pattern pattern = Pattern.compile(s);
return with(new ValuePatternCondition<String>("matches") {
@Override
public boolean accepts(@NotNull final String str, final ProcessingContext context) {
return pattern.matcher(newBombedCharSequence(str)).matches();
}
@Override
public Collection<String> getValues() {
return Collections.singleton(s);
}
});
}
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));
}
}
}
Aggregations