@Override public Converter getConverter(@NotNull GenericDomValue element) { StyleItem item = (StyleItem)element; String name = item.getName().getValue(); if (name != null) { String[] strs = name.split(":"); if (strs.length == 1 || strs.length == 2) { AndroidFacet facet = AndroidFacet.getInstance(element); if (facet != null) { String namespacePrefix = strs.length == 2 ? strs[0] : null; String localName = strs[strs.length - 1]; return findConverterForAttribute(namespacePrefix, localName, facet, element); } } } return null; }
private static Map<String, Pair<Type, Class>> getStaticallyRegisteredAttributes(final DomGenericInfo genericInfo) { final Map<String, Pair<Type, Class>> map = new HashMap<String, Pair<Type, Class>>(); for (DomAttributeChildDescription description : genericInfo.getAttributeChildrenDescriptions()) { final Type type = description.getType(); if (type instanceof ParameterizedType) { final Type[] typeArguments = ((ParameterizedType)type).getActualTypeArguments(); if (typeArguments.length == 1) { String name = description.getXmlElementName(); final Type attribType = typeArguments[0]; Class<? extends Converter> converterType = null; final Convert converterAnnotation = description.getAnnotation(Convert.class); if (converterAnnotation != null) { converterType = converterAnnotation.value(); } map.put(name.toLowerCase(Locale.US), new Pair<Type, Class>(attribType, converterType)); } } } return map; }
@Override public Converter getConverter(@NotNull GenericDomValue domElement) { Module module = domElement.getModule(); ParamValue value = domElement.getParentOfType(ParamValue.class, false); if (value != null) { String paramName = value.getParamName().getStringValue(); if (paramName != null) { for (ContextParamsProvider provider : Extensions.getExtensions(ContextParamsProvider.EP_NAME)) { Converter converter = provider.getContextParamValueConverter(paramName, module); if (converter != null) return converter; } } } return null; }
public void registerConverter(@NotNull Converter<?> provider, @NotNull final PsiType type) { registerConverter(provider, new Condition<Pair<PsiType, GenericDomValue>>() { public boolean value(final Pair<PsiType, GenericDomValue> pair) { return Comparing.equal(pair.getFirst(), type); } }); }
@Nullable public Converter<?> getConverter(@NotNull GenericDomValue domValue, @Nullable PsiType type) { final Pair<PsiType, GenericDomValue> pair = Pair.create(type, domValue); for (@NotNull Condition<Pair<PsiType, GenericDomValue>> condition : myConditionConverters.keySet()) { if (condition.value(pair)) { return myConditionConverters.get(condition); } } return null; }
public void registerConverter(@NotNull Converter<?> provider, @NotNull Class type) { final String name = type.getCanonicalName(); registerConverter(provider, new Condition<Pair<PsiType, GenericDomValue>>() { public boolean value(final Pair<PsiType, GenericDomValue> pair) { return pair.first != null && Comparing.equal(name, pair.first.getCanonicalText()); } }); }
private static void completeTailsInFlagAttribute(CompletionParameters parameters, CompletionResultSet resultSet, XmlAttributeValue parent) { final String currentValue = parent.getValue(); if (currentValue == null || currentValue.length() == 0 || currentValue.endsWith("|")) { return; } final PsiElement gp = parent.getParent(); if (!(gp instanceof XmlAttribute)) { return; } final GenericAttributeValue domValue = DomManager.getDomManager(gp.getProject()).getDomElement((XmlAttribute)gp); final Converter converter = domValue != null ? domValue.getConverter() : null; if (!(converter instanceof FlagConverter)) { return; } final TextRange valueRange = parent.getValueTextRange(); if (valueRange != null && valueRange.getEndOffset() == parameters.getOffset()) { final Set<String> valueSet = ((FlagConverter)converter).getValues(); if (valueSet.size() > 0) { final String prefix = resultSet.getPrefixMatcher().getPrefix(); if (valueSet.contains(prefix)) { final ArrayList<String> filteredValues = new ArrayList<String>(valueSet); //noinspection unchecked DelimitedListConverter.filterVariants(filteredValues, domValue); for (String variant : filteredValues) { resultSet.addElement(LookupElementBuilder.create(prefix + "|" + variant)); } } } } }
@Override protected boolean shouldCheckResolveProblems(GenericDomValue value) { final Converter realConverter = WrappingConverter.getDeepestConverter(value.getConverter(), value); return !(realConverter instanceof AndroidPackageConverter) && !(realConverter instanceof DeclareStyleableNameConverter) && !(realConverter instanceof OnClickConverter) && !(realConverter instanceof ConstantFieldConverter); }
@Override protected boolean shouldCheckResolveProblems(GenericDomValue value) { if (!isElementInsideManagedFile(value)) { return false; } Converter converter = value.getConverter(); if (converter instanceof MavenDomSoftAwareConverter) { return !((MavenDomSoftAwareConverter)converter).isSoft(value); } return true; }
@Override public Converter getConverter(@NotNull GenericDomValue domElement) { Project project = domElement.getManager().getProject(); JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project); PsiClass psiClass = psiFacade.findClass(myType, GlobalSearchScope.allScope(project)); if (psiClass != null) { GenericDomValueConvertersRegistry convertersRegistry = MavenDomConvertersRegistry.getInstance().getConvertersRegistry(); return convertersRegistry.getConverter(domElement, psiFacade.getElementFactory().createType(psiClass)); } return null; }
@NotNull public List<Converter> getConverters(@NotNull GenericDomValue domElement) { final String raw = domElement.getRawText(); if (raw != null) { if (raw.contains("${") || raw.contains(File.separator) || (File.separatorChar != '/' && raw.contains("/"))) { return Collections.<Converter>singletonList(new AntPathConverter()); } } return Collections.emptyList(); }
@Nullable public Converter<?> getConverter(@NotNull GenericDomValue domValue, @Nullable PsiType type) { final Pair<PsiType, GenericDomValue> pair = new Pair<PsiType, GenericDomValue>(type, domValue); for (@NotNull Condition<Pair<PsiType, GenericDomValue>> condition : myConditionConverters.keySet()) { if (condition.value(pair)) { return myConditionConverters.get(condition); } } return null; }
@NotNull private static Collection<?> getVariants(CompletionParameters parameters) { if (!MavenDomUtil.isMavenFile(parameters.getOriginalFile())) return Collections.emptyList(); SmartList<?> result = new SmartList<Object>(); for (PsiReference each : getReferences(parameters)) { if (each instanceof TagNameReference) continue; if (each instanceof GenericDomValueReference) { GenericDomValueReference reference = (GenericDomValueReference)each; Converter converter = reference.getConverter(); if (converter instanceof MavenSmartConverter) { result.addAll(((MavenSmartConverter)converter).getSmartVariants(reference.getConvertContext())); } else if (converter instanceof ResolvingConverter) { //noinspection unchecked result.addAll(((ResolvingConverter)converter).getVariants(reference.getConvertContext())); } } else { //noinspection unchecked Collections.addAll((Collection)result, each.getVariants()); } } return result; }
public void registerConverter(@NotNull Converter<?> provider, @NotNull Condition<Pair<PsiType, GenericDomValue>> condition) { myConditionConverters.put(condition, provider); }
@Override public DomExtension setConverter(@NotNull Converter converter) { return setConverter(converter, false); }
@Override public final DomExtension setConverter(@NotNull final Converter converter, final boolean soft) { myConverter = converter; mySoft = soft; return this; }
protected SetInvocation(final Converter converter) { myConverter = converter; }
public ConvertAnnotationImpl(final Converter converter, final boolean soft) { myConverter = converter; mySoft = soft; }
public Converter getConverter() { return myConverter; }
@Override public Class<? extends Converter> value() { return myConverter.getClass(); }
public Converter getConverter(@NotNull GenericDomValue domElement) { final List<Converter> converterList = getConverters(domElement); return converterList.isEmpty()? null : converterList.get(0); }
public DomExtension setConverter(@NotNull Converter converter) { return setConverter(converter, false); }
public final DomExtension setConverter(@NotNull final Converter converter, final boolean soft) { myConverter = converter; mySoft = soft; return this; }
public Class<? extends Converter> value() { return myConverter.getClass(); }
@Nullable public abstract Converter getContextParamValueConverter(@NotNull String paramName, @Nullable Module module);