use of com.intellij.util.ProcessingContext in project intellij-community by JetBrains.
the class DomHighlightingHelperImpl method checkResolveProblems.
@Override
@NotNull
public List<DomElementProblemDescriptor> checkResolveProblems(GenericDomValue element, final DomElementAnnotationHolder holder) {
if (StringUtil.isEmpty(element.getStringValue())) {
final Required required = element.getAnnotation(Required.class);
if (required != null && !required.nonEmpty())
return Collections.emptyList();
}
final XmlElement valueElement = DomUtil.getValueElement(element);
if (valueElement != null && !isSoftReference(element)) {
final SmartList<DomElementProblemDescriptor> list = new SmartList<>();
final PsiReference[] psiReferences = myProvider.getReferencesByElement(valueElement, new ProcessingContext());
GenericDomValueReference domReference = ContainerUtil.findInstance(psiReferences, GenericDomValueReference.class);
final Converter converter = WrappingConverter.getDeepestConverter(element.getConverter(), element);
boolean hasBadResolve = false;
if (domReference == null || !isDomResolveOK(element, domReference, converter)) {
for (final PsiReference reference : psiReferences) {
if (reference != domReference && hasBadResolve(reference)) {
hasBadResolve = true;
list.add(holder.createResolveProblem(element, reference));
}
}
final boolean isResolvingConverter = converter instanceof ResolvingConverter;
//noinspection unchecked
if (!hasBadResolve && (domReference != null || isResolvingConverter && hasBadResolve(domReference = new GenericDomValueReference(element)))) {
hasBadResolve = true;
final String errorMessage = converter.getErrorMessage(element.getStringValue(), ConvertContextFactory.createConvertContext(DomManagerImpl.getDomInvocationHandler(element)));
if (errorMessage != null) {
list.add(holder.createResolveProblem(element, domReference));
}
}
}
if (!hasBadResolve && psiReferences.length == 0 && element.getValue() == null && !PsiTreeUtil.hasErrorElements(valueElement)) {
final String errorMessage = converter.getErrorMessage(element.getStringValue(), ConvertContextFactory.createConvertContext(DomManagerImpl.getDomInvocationHandler(element)));
if (errorMessage != null) {
list.add(holder.createProblem(element, errorMessage));
}
}
return list;
}
return Collections.emptyList();
}
use of com.intellij.util.ProcessingContext in project intellij-plugins by JetBrains.
the class ActionScriptReferenceContributor method registerReferenceProviders.
@Override
public void registerReferenceProviders(@NotNull final PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
public boolean isAcceptable(Object element, PsiElement context) {
PsiElement parent = ((JSLiteralExpression) element).getParent();
if (parent instanceof JSArgumentList) {
JSExpression[] arguments = ((JSArgumentList) parent).getArguments();
if (arguments.length > 0 && arguments[0] == element) {
parent = parent.getParent();
if (parent instanceof JSCallExpression) {
JSExpression invokedMethod = ((JSCallExpression) parent).getMethodExpression();
if (invokedMethod instanceof JSReferenceExpression) {
String methodName = ((JSReferenceExpression) invokedMethod).getReferencedName();
if (SET_STYLE_METHOD_NAME.equals(methodName)) {
Module module = findModuleForPsiElement(parent);
return module != null && ModuleType.get(module) == FlexModuleType.getInstance();
}
}
}
}
}
return false;
}
public boolean isClassAcceptable(Class hintClass) {
return true;
}
})), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
String value = element.getText();
if (FlexCssUtil.inQuotes(value)) {
return new PsiReference[] { new CssPropertyValueReference(element) };
}
return PsiReference.EMPTY_ARRAY;
}
});
registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
public boolean isAcceptable(Object element, PsiElement context) {
PsiElement parent = ((JSLiteralExpression) element).getParent();
if (parent instanceof JSAssignmentExpression) {
PsiElement assignee = parent.getChildren()[0];
if (assignee instanceof JSDefinitionExpression) {
JSExpression expression = ((JSDefinitionExpression) assignee).getExpression();
if (expression instanceof JSReferenceExpression) {
String refName = ((JSReferenceExpression) expression).getReferencedName();
if (refName != null && FlexCssUtil.isStyleNameProperty(refName)) {
Module module = findModuleForPsiElement(parent);
return module != null && ModuleType.get(module) == FlexModuleType.getInstance();
}
}
}
}
return false;
}
public boolean isClassAcceptable(Class hintClass) {
return true;
}
})), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
String value = element.getText();
if (FlexCssUtil.inQuotes(value)) {
return new PsiReference[] { new CssClassValueReference(element) };
}
return PsiReference.EMPTY_ARRAY;
}
});
registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class).and(new FilterPattern(new ElementFilter() {
public boolean isAcceptable(Object element, PsiElement context) {
PsiElement parent = ((JSLiteralExpression) element).getParent();
if (parent instanceof JSArgumentList) {
final JSExpression[] arguments = ((JSArgumentList) parent).getArguments();
if (arguments.length > 0 && arguments[0] == element) {
parent = parent.getParent();
if (parent instanceof JSCallExpression) {
final JSExpression invokedMethod = ((JSCallExpression) parent).getMethodExpression();
if (invokedMethod instanceof JSReferenceExpression) {
final String methodName = ((JSReferenceExpression) invokedMethod).getReferencedName();
if (methodName != null && FlexCssUtil.isStyleNameMethod(methodName)) {
Module module = findModuleForPsiElement(parent);
return module != null && ModuleType.get(module) == FlexModuleType.getInstance();
}
}
}
}
}
return false;
}
public boolean isClassAcceptable(Class hintClass) {
return true;
}
})), new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
String value = element.getText();
if (FlexCssUtil.inQuotes(value)) {
return new PsiReference[] { new CssClassValueReference(element) };
}
return PsiReference.EMPTY_ARRAY;
}
});
registrar.registerReferenceProvider(psiElement(JSLiteralExpression.class), new FlexPropertyReferenceProvider());
registrar.registerReferenceProvider(psiElement(JSAttributeNameValuePair.class), new FlexAttributeReferenceProvider());
}
use of com.intellij.util.ProcessingContext in project intellij-plugins by JetBrains.
the class PhoneGapEventLiteralsCompletionContributor method getProvider.
private static CompletionProvider<CompletionParameters> getProvider() {
return new CompletionProvider<CompletionParameters>() {
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
Project project = completionParameters.getEditor().getProject();
if (null == project || !PhoneGapUtil.isPhoneGapProject(project)) {
return;
}
completionResultSet.addElement(LookupElementBuilder.create("deviceready"));
completionResultSet.addElement(LookupElementBuilder.create("pause"));
completionResultSet.addElement(LookupElementBuilder.create("resume"));
completionResultSet.addElement(LookupElementBuilder.create("online"));
completionResultSet.addElement(LookupElementBuilder.create("offline"));
completionResultSet.addElement(LookupElementBuilder.create("backbutton"));
completionResultSet.addElement(LookupElementBuilder.create("menubutton"));
completionResultSet.addElement(LookupElementBuilder.create("searchbutton"));
completionResultSet.addElement(LookupElementBuilder.create("startcallbutton"));
completionResultSet.addElement(LookupElementBuilder.create("endcallbutton"));
completionResultSet.addElement(LookupElementBuilder.create("volumedownbutton"));
completionResultSet.addElement(LookupElementBuilder.create("volumeupbutton"));
}
};
}
Aggregations