use of com.intellij.util.xml.ConvertContext in project intellij-plugins by JetBrains.
the class InterceptorRefResolveConverterImpl method fromString.
public InterceptorOrStackBase fromString(@Nullable @NonNls final String name, final ConvertContext context) {
if (name == null) {
return null;
}
final Condition<InterceptorOrStackBase> nameCondition = interceptorOrStackBase -> name.equals(interceptorOrStackBase.getName().getStringValue());
final Ref<InterceptorOrStackBase> resolveResult = new Ref<>();
final Processor<StrutsPackage> processor = strutsPackage -> {
final InterceptorOrStackBase result = ContainerUtil.find(getAllInterceptors(strutsPackage), nameCondition);
if (result != null) {
resolveResult.set(result);
return false;
}
return true;
};
final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
walker.walkUp();
return resolveResult.get();
}
use of com.intellij.util.xml.ConvertContext in project intellij-plugins by JetBrains.
the class ResultTypeResolvingConverterImpl method fromString.
public ResultType fromString(@Nullable @NonNls final String name, final ConvertContext context) {
if (StringUtil.isEmpty(name)) {
return null;
}
final Condition<ResultType> nameCondition = resultType -> Comparing.equal(name, resultType.getName().getStringValue());
final Ref<ResultType> resolveResult = new Ref<>();
final Processor<StrutsPackage> processor = strutsPackage -> {
final ResultType result = ContainerUtil.find(strutsPackage.getResultTypes(), nameCondition);
if (result != null) {
resolveResult.set(result);
return false;
}
return true;
};
final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(ConverterUtil.getCurrentStrutsPackage(context), processor);
walker.walkUp();
return resolveResult.get();
}
use of com.intellij.util.xml.ConvertContext in project intellij-plugins by JetBrains.
the class DefaultInterceptorRefResolveConverterImpl method fromString.
public InterceptorStack fromString(@Nullable @NonNls final String name, final ConvertContext context) {
if (name == null) {
return null;
}
final Condition<InterceptorStack> nameCondition = interceptorStack -> name.equals(interceptorStack.getName().getStringValue());
final Ref<InterceptorStack> resolveResult = new Ref<>();
final Processor<StrutsPackage> processor = strutsPackage -> {
final InterceptorStack result = ContainerUtil.find(strutsPackage.getInterceptorStacks(), nameCondition);
if (result != null) {
resolveResult.set(result);
return false;
}
return true;
};
final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(getCurrentStrutsPackage(context), processor);
walker.walkUp();
return resolveResult.get();
}
use of com.intellij.util.xml.ConvertContext in project android by JetBrains.
the class DimensionConverterTest method test.
public void test() {
DimensionConverter converter = new DimensionConverter();
StyleItem element = createElement("<item>10dp</item>", StyleItem.class);
DomInvocationHandler handler = DomManagerImpl.getDomInvocationHandler(element);
assertNotNull(handler);
ConvertContext context = ConvertContextFactory.createConvertContext(handler);
List<String> variants = new ArrayList<>(converter.getVariants(context));
Collections.sort(variants);
assertEquals(Arrays.asList("10dp", "10in", "10mm", "10pt", "10px", "10sp"), variants);
// Valid units
assertEquals("1dip", converter.fromString("1dip", context));
assertEquals("1dp", converter.fromString("1dp", context));
assertEquals("1px", converter.fromString("1px", context));
assertEquals("1in", converter.fromString("1in", context));
assertEquals("1mm", converter.fromString("1mm", context));
assertEquals("1sp", converter.fromString("1sp", context));
assertEquals("1pt", converter.fromString("1pt", context));
// Invalid dimensions (missing units)
assertNull(converter.fromString("not_a_dimension", context));
assertNull(converter.fromString("", context));
assertEquals("Cannot resolve symbol ''", converter.getErrorMessage("", context));
assertNull(converter.fromString("1", context));
assertEquals("Cannot resolve symbol '1'", converter.getErrorMessage("1", context));
assertNull(converter.fromString("1.5", context));
assertEquals("Cannot resolve symbol '1.5'", converter.getErrorMessage("1.5", context));
// Unknown units
assertNull(converter.fromString("15d", context));
assertEquals("Unknown unit 'd'", converter.getErrorMessage("15d", context));
assertNull(converter.fromString("15wrong", context));
assertEquals("Unknown unit 'wrong'", converter.getErrorMessage("15wrong", context));
// Normal conversions
assertEquals("15px", converter.fromString("15px", context));
assertEquals("15", DimensionConverter.getIntegerPrefix("15px"));
assertEquals("px", DimensionConverter.getUnitFromValue("15px"));
// Make sure negative numbers work
assertEquals("-10px", converter.fromString("-10px", context));
assertEquals("-10", DimensionConverter.getIntegerPrefix("-10px"));
assertEquals("px", DimensionConverter.getUnitFromValue("-10px"));
// Make sure decimals work
assertEquals("1.5sp", converter.fromString("1.5sp", context));
assertEquals("1.5", DimensionConverter.getIntegerPrefix("1.5sp"));
assertEquals("sp", DimensionConverter.getUnitFromValue("1.5sp"));
assertEquals(".5sp", converter.fromString(".5sp", context));
assertEquals(".5", DimensionConverter.getIntegerPrefix(".5sp"));
assertEquals("sp", DimensionConverter.getUnitFromValue(".5sp"));
// Make sure the right type of decimal separator is used
assertNull(converter.fromString("1,5sp", context));
assertEquals("Use a dot instead of a comma as the decimal mark", converter.getErrorMessage("1,5sp", context));
// Documentation
assertEquals("<html><body>" + "<b>Density-independent Pixels</b> - an abstract unit that is based on the physical density of the screen." + "</body></html>", converter.getDocumentation("1dp"));
assertEquals("<html><body>" + "<b>Pixels</b> - corresponds to actual pixels on the screen. Not recommended." + "</body></html>", converter.getDocumentation("-10px"));
assertEquals("<html><body>" + "<b>Scale-independent Pixels</b> - this is like the dp unit, but " + "it is also scaled by the user's font size preference." + "</body></html>", converter.getDocumentation("1.5sp"));
}
use of com.intellij.util.xml.ConvertContext in project intellij-plugins by JetBrains.
the class StrutsConstantManagerImpl method getConvertedValue.
@Override
@Nullable
public <T> T getConvertedValue(@NotNull final PsiElement context, @NotNull final StrutsConstantKey<T> strutsConstantKey) {
final PsiFile containingFile = context.getContainingFile();
final StrutsModel strutsModel = getStrutsModel(containingFile);
if (strutsModel == null) {
return null;
}
final String stringValue = getStringValue(containingFile, strutsModel, strutsConstantKey.getKey());
if (stringValue == null) {
return null;
}
final Converter<T> converter = findConverter(context, strutsConstantKey);
if (converter == null) {
//noinspection unchecked
return (T) stringValue;
}
final DomFileElement<StrutsRoot> first = strutsModel.getRoots().iterator().next();
final ConvertContext convertContext = ConvertContextFactory.createConvertContext(first);
//noinspection unchecked
return converter.fromString(stringValue, convertContext);
}
Aggregations