forked from qt-creator/qt-creator
QmlJS: Generalize EasingCurve name check to all enums.
Reviewed-by: Erik Verbruggen
This commit is contained in:
@@ -64,13 +64,27 @@ public:
|
||||
return _message;
|
||||
}
|
||||
|
||||
virtual void visit(const NumberValue *)
|
||||
virtual void visit(const NumberValue *value)
|
||||
{
|
||||
// ### Consider enums: elide: "ElideLeft" is valid, but currently elide is a NumberValue.
|
||||
if (/*cast<StringLiteral *>(_ast)
|
||||
if (const QmlEnumValue *enumValue = dynamic_cast<const QmlEnumValue *>(value)) {
|
||||
if (StringLiteral *stringLiteral = cast<StringLiteral *>(_ast)) {
|
||||
const QString valueName = stringLiteral->value->asString();
|
||||
|
||||
if (!enumValue->keys().contains(valueName)) {
|
||||
_message.message = QCoreApplication::translate("QmlJS::Check", "unknown value for enum");
|
||||
}
|
||||
} else if (_rhsValue->asUndefinedValue()) {
|
||||
_message.kind = DiagnosticMessage::Warning;
|
||||
_message.message = QCoreApplication::translate("QmlJS::Check", "value might be 'undefined'");
|
||||
} else if (! _rhsValue->asStringValue() && ! _rhsValue->asNumberValue()) {
|
||||
_message.message = QCoreApplication::translate("QmlJS::Check", "enum value is not a string or number");
|
||||
}
|
||||
} else {
|
||||
if (/*cast<StringLiteral *>(_ast)
|
||||
||*/ _ast->kind == Node::Kind_TrueLiteral
|
||||
|| _ast->kind == Node::Kind_FalseLiteral) {
|
||||
_message.message = QCoreApplication::translate("QmlJS::Check", "numerical value expected");
|
||||
|| _ast->kind == Node::Kind_FalseLiteral) {
|
||||
_message.message = QCoreApplication::translate("QmlJS::Check", "numerical value expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,22 +111,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void visit(const EasingCurveNameValue *)
|
||||
{
|
||||
if (StringLiteral *stringLiteral = cast<StringLiteral *>(_ast)) {
|
||||
const QString curveName = stringLiteral->value->asString();
|
||||
|
||||
if (!EasingCurveNameValue::curveNames().contains(curveName)) {
|
||||
_message.message = QCoreApplication::translate("QmlJS::Check", "unknown easing-curve name");
|
||||
}
|
||||
} else if (_rhsValue->asUndefinedValue()) {
|
||||
_message.kind = DiagnosticMessage::Warning;
|
||||
_message.message = QCoreApplication::translate("QmlJS::Check", "value might be 'undefined'");
|
||||
} else if (! _rhsValue->asStringValue() && ! _rhsValue->asNumberValue()) {
|
||||
_message.message = QCoreApplication::translate("QmlJS::Check", "easing-curve name is not a string or number");
|
||||
}
|
||||
}
|
||||
|
||||
virtual void visit(const ColorValue *)
|
||||
{
|
||||
if (StringLiteral *stringLiteral = cast<StringLiteral *>(_ast)) {
|
||||
|
||||
@@ -846,15 +846,6 @@ const Value *QmlObjectValue::propertyValue(const FakeMetaProperty &prop) const
|
||||
value = engine()->colorValue();
|
||||
} else if (typeName == QLatin1String("QDeclarativeAnchorLine")) {
|
||||
value = engine()->anchorLineValue();
|
||||
} else if (typeName == QLatin1String("QEasingCurve")) {
|
||||
// ### cache
|
||||
ObjectValue *object = engine()->newObject(/*prototype =*/ 0);
|
||||
object->setClassName(QLatin1String("EasingCurve"));
|
||||
object->setProperty("type", engine()->easingCurveNameValue());
|
||||
object->setProperty("period", engine()->numberValue());
|
||||
object->setProperty("amplitude", engine()->numberValue());
|
||||
object->setProperty("overshoot", engine()->numberValue());
|
||||
value = object;
|
||||
}
|
||||
|
||||
// might be an enum
|
||||
@@ -1199,10 +1190,6 @@ void ValueVisitor::visit(const Reference *)
|
||||
{
|
||||
}
|
||||
|
||||
void ValueVisitor::visit(const EasingCurveNameValue *)
|
||||
{
|
||||
}
|
||||
|
||||
void ValueVisitor::visit(const ColorValue *)
|
||||
{
|
||||
}
|
||||
@@ -1267,11 +1254,6 @@ const Reference *Value::asReference() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
const EasingCurveNameValue *Value::asEasingCurveNameValue() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const ColorValue *Value::asColorValue() const
|
||||
{
|
||||
return 0;
|
||||
@@ -1557,67 +1539,6 @@ const Value *Reference::value(Context *) const
|
||||
return _engine->undefinedValue();
|
||||
}
|
||||
|
||||
void EasingCurveNameValue::accept(ValueVisitor *visitor) const
|
||||
{
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
QSet<QString> EasingCurveNameValue::_curveNames;
|
||||
QSet<QString> EasingCurveNameValue::curveNames()
|
||||
{
|
||||
if (_curveNames.isEmpty()) {
|
||||
_curveNames = QSet<QString>()
|
||||
<< "Linear"
|
||||
<< "InQuad"
|
||||
<< "OutQuad"
|
||||
<< "InOutQuad"
|
||||
<< "OutInQuad"
|
||||
<< "InCubic"
|
||||
<< "OutCubic"
|
||||
<< "InOutCubic"
|
||||
<< "OutInCubic"
|
||||
<< "InQuart"
|
||||
<< "OutQuart"
|
||||
<< "InOutQuart"
|
||||
<< "OutInQuart"
|
||||
<< "InQuint"
|
||||
<< "OutQuint"
|
||||
<< "InOutQuint"
|
||||
<< "OutInQuint"
|
||||
<< "InSine"
|
||||
<< "OutSine"
|
||||
<< "InOutSine"
|
||||
<< "OutInSine"
|
||||
<< "InExpo"
|
||||
<< "OutExpo"
|
||||
<< "InOutExpo"
|
||||
<< "OutInExpo"
|
||||
<< "InCirc"
|
||||
<< "OutCirc"
|
||||
<< "InOutCirc"
|
||||
<< "OutInCirc"
|
||||
<< "InElastic"
|
||||
<< "OutElastic"
|
||||
<< "InOutElastic"
|
||||
<< "OutInElastic"
|
||||
<< "InBack"
|
||||
<< "OutBack"
|
||||
<< "InOutBack"
|
||||
<< "OutInBack"
|
||||
<< "InBounce"
|
||||
<< "OutBounce"
|
||||
<< "InOutBounce"
|
||||
<< "OutInBounce";
|
||||
}
|
||||
|
||||
return _curveNames;
|
||||
}
|
||||
|
||||
const EasingCurveNameValue *EasingCurveNameValue::asEasingCurveNameValue() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void ColorValue::accept(ValueVisitor *visitor) const
|
||||
{
|
||||
visitor->visit(this);
|
||||
@@ -2337,11 +2258,6 @@ void TypeId::visit(const FunctionValue *object)
|
||||
_result = QLatin1String("Function");
|
||||
}
|
||||
|
||||
void TypeId::visit(const EasingCurveNameValue *)
|
||||
{
|
||||
_result = QLatin1String("string");
|
||||
}
|
||||
|
||||
void TypeId::visit(const ColorValue *)
|
||||
{
|
||||
_result = QLatin1String("string");
|
||||
@@ -2412,11 +2328,6 @@ const StringValue *Engine::stringValue() const
|
||||
return &_stringValue;
|
||||
}
|
||||
|
||||
const EasingCurveNameValue *Engine::easingCurveNameValue() const
|
||||
{
|
||||
return &_easingCurveNameValue;
|
||||
}
|
||||
|
||||
const ColorValue *Engine::colorValue() const
|
||||
{
|
||||
return &_colorValue;
|
||||
|
||||
@@ -60,7 +60,6 @@ class StringValue;
|
||||
class ObjectValue;
|
||||
class FunctionValue;
|
||||
class Reference;
|
||||
class EasingCurveNameValue;
|
||||
class ColorValue;
|
||||
class AnchorLineValue;
|
||||
|
||||
@@ -88,7 +87,6 @@ public:
|
||||
virtual void visit(const ObjectValue *);
|
||||
virtual void visit(const FunctionValue *);
|
||||
virtual void visit(const Reference *);
|
||||
virtual void visit(const EasingCurveNameValue *);
|
||||
virtual void visit(const ColorValue *);
|
||||
virtual void visit(const AnchorLineValue *);
|
||||
};
|
||||
@@ -113,7 +111,6 @@ public:
|
||||
virtual const ObjectValue *asObjectValue() const;
|
||||
virtual const FunctionValue *asFunctionValue() const;
|
||||
virtual const Reference *asReference() const;
|
||||
virtual const EasingCurveNameValue *asEasingCurveNameValue() const;
|
||||
virtual const ColorValue *asColorValue() const;
|
||||
virtual const AnchorLineValue *asAnchorLineValue() const;
|
||||
|
||||
@@ -172,12 +169,6 @@ template <> Q_INLINE_TEMPLATE const Reference *value_cast(const Value *v)
|
||||
else return 0;
|
||||
}
|
||||
|
||||
template <> Q_INLINE_TEMPLATE const EasingCurveNameValue *value_cast(const Value *v)
|
||||
{
|
||||
if (v) return v->asEasingCurveNameValue();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
template <> Q_INLINE_TEMPLATE const ColorValue *value_cast(const Value *v)
|
||||
{
|
||||
if (v) return v->asColorValue();
|
||||
@@ -342,18 +333,6 @@ private:
|
||||
Engine *_engine;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT EasingCurveNameValue: public Value
|
||||
{
|
||||
static QSet<QString> _curveNames;
|
||||
|
||||
public:
|
||||
static QSet<QString> curveNames();
|
||||
|
||||
// Value interface
|
||||
virtual const EasingCurveNameValue *asEasingCurveNameValue() const;
|
||||
virtual void accept(ValueVisitor *) const;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT ColorValue: public Value
|
||||
{
|
||||
public:
|
||||
@@ -639,7 +618,6 @@ protected:
|
||||
virtual void visit(const StringValue *);
|
||||
virtual void visit(const ObjectValue *object);
|
||||
virtual void visit(const FunctionValue *object);
|
||||
virtual void visit(const EasingCurveNameValue *);
|
||||
virtual void visit(const ColorValue *);
|
||||
virtual void visit(const AnchorLineValue *);
|
||||
};
|
||||
@@ -658,7 +636,6 @@ public:
|
||||
const NumberValue *numberValue() const;
|
||||
const BooleanValue *booleanValue() const;
|
||||
const StringValue *stringValue() const;
|
||||
const EasingCurveNameValue *easingCurveNameValue() const;
|
||||
const ColorValue *colorValue() const;
|
||||
const AnchorLineValue *anchorLineValue() const;
|
||||
|
||||
@@ -744,7 +721,6 @@ private:
|
||||
NumberValue _numberValue;
|
||||
BooleanValue _booleanValue;
|
||||
StringValue _stringValue;
|
||||
EasingCurveNameValue _easingCurveNameValue;
|
||||
ColorValue _colorValue;
|
||||
AnchorLineValue _anchorLineValue;
|
||||
QList<Value *> _registeredValues;
|
||||
|
||||
Reference in New Issue
Block a user