Skip to content

[Haxe][FileParser] Added support for multiple inheritance #2664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion External/Plugins/ASCompletion/Model/ClassModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace ASCompletion.Model
{
/// <summary>
/// Object representation of an Actionscript class
/// Object representation of an ActionScript class
/// </summary>
[Serializable]
public class ClassModel: MemberModel
Expand All @@ -32,7 +32,16 @@ static ClassModel()
public string Constructor;
public MemberList Members;

/// <summary>
/// 1st extends type
/// </summary>
public string ExtendsType;

/// <summary>
/// Extensible types starting from the second
/// </summary>
public List<string> ExtendsTypes;

public string IndexType;
public List<string> Implements;
[NonSerialized]
Expand Down
27 changes: 14 additions & 13 deletions External/Plugins/ASCompletion/PluginUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -746,16 +746,20 @@ private void AddExtend(TreeNodeCollection tree, ClassModel aClass)
//if ((aClass.Flags & FlagType.TypeDef) > 0 && aClass.Members.Count == 0)
// folder.Text = "Defines"; // TODO need a better word I guess

while (!string.IsNullOrEmpty(aClass.ExtendsType) && aClass.ExtendsType != aClass.InFile.Context.Features.dynamicKey)
var features = ASContext.Context.Features;
while ((!string.IsNullOrEmpty(aClass.ExtendsType) && aClass.ExtendsType != features.dynamicKey) || aClass.ExtendsTypes != null)
{
var extends = aClass.ExtendsType;
var extendsType = aClass.ExtendsType;
var extends = aClass.Extends;
if (!extends.IsVoid()) extendsType = extends.QualifiedName;
if (extendsType != features.voidKey) folder.Nodes.Add(new TreeNode(extendsType, ICON_TYPE, ICON_TYPE) {Tag = "import"});
if (aClass.ExtendsTypes != null)
for (var i = 0; i < aClass.ExtendsTypes.Count; i++)
{
extendsType = aClass.ExtendsTypes[i];
if (extendsType != features.voidKey) folder.Nodes.Add(new TreeNode(extendsType, ICON_TYPE, ICON_TYPE) {Tag = "import"});
}
aClass = aClass.Extends;
if (!aClass.IsVoid()) extends = aClass.QualifiedName;
if (extends.ToLower() == "void")
break;
var extNode = new TreeNode(extends, ICON_TYPE, ICON_TYPE);
extNode.Tag = "import";
folder.Nodes.Add(extNode);
}
if (folder.Nodes.Count > 0) tree.Add(folder);
}
Expand All @@ -766,9 +770,7 @@ private void AddImplements(TreeNodeCollection tree, ICollection<string> implemen
var folder = new TreeNode(TextHelper.GetString("Info.ImplementsNode"), ICON_FOLDER_CLOSED, ICON_FOLDER_OPEN);
foreach (var implements in implementsTypes)
{
var impNode = new TreeNode(implements, ICON_INTERFACE, ICON_INTERFACE);
impNode.Tag = "import";
folder.Nodes.Add(impNode);
folder.Nodes.Add(new TreeNode(implements, ICON_INTERFACE, ICON_INTERFACE) {Tag = "import"});
}
tree.Add(folder);
}
Expand Down Expand Up @@ -804,10 +806,9 @@ private void AddMembersSorted(TreeNodeCollection tree, MemberList members)

private void AddRegionsExtended(TreeNodeCollection tree, FileModel aFile)
{
int index = 0;
MemberList regions = aFile.Regions;
int count = regions.Count;
for (index = 0; index < count; ++index)
for (var index = 0; index < count; ++index)
{
var region = regions[index];
MemberTreeNode node = new MemberTreeNode(region, ICON_PACKAGE);
Expand Down
25 changes: 21 additions & 4 deletions External/Plugins/HaXeContext/Model/FileParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ public void ParseSrc(FileModel fileModel, string src, bool allowBaReExtract)
{
foundColon = curMember != null && curMember.Type == null;
// recognize compiler config block
if (!foundColon && braceCount == 0
if (!foundColon && braceCount == 0
&& i < len - 2 && src[i] == ':' && char.IsLetter(src[i + 1]))
foundConstant = true;
}
Expand Down Expand Up @@ -1276,7 +1276,7 @@ public void ParseSrc(FileModel fileModel, string src, bool allowBaReExtract)
if (curClass != null && curMember == null) curClass.Members.Add(curMethod);
}
// an Abstract "opaque type"
else if (context == FlagType.Abstract && prevToken.Text == "abstract")
else if (context == FlagType.Abstract && prevToken.Text == "abstract")
{
foundKeyword = FlagType.Class;
curModifiers = FlagType.Extends;
Expand Down Expand Up @@ -1363,6 +1363,18 @@ public void ParseSrc(FileModel fileModel, string src, bool allowBaReExtract)
i++;
continue;
}
else if (c1 == '>' && context == FlagType.TypeDef && curClass != null && (curClass.Flags & FlagType.TypeDef) != 0)
{
buffer[0] = 'e';
buffer[1] = 'x';
buffer[2] = 't';
buffer[3] = 'e';
buffer[4] = 'n';
buffer[5] = 'd';
buffer[6] = 's';
length = 7;
context = FlagType.Class;
}
}

// put in buffer
Expand Down Expand Up @@ -1898,14 +1910,19 @@ private bool EvalToken(bool evalContext, bool evalKeyword)
if ((token == "Array" || token == "Proxy" || token == "flash.utils.Proxy")
&& lastComment != null && ASFileParserRegexes.ValidTypeName.IsMatch(lastComment))
{
Match m = ASFileParserRegexes.ValidTypeName.Match(lastComment);
var m = ASFileParserRegexes.ValidTypeName.Match(lastComment);
if (m.Success)
{
token += "<" + m.Groups["type"].Value + ">";
lastComment = null;
}
}
curClass.ExtendsType = token;
if (curClass.ExtendsType is null) curClass.ExtendsType = token;
else
{
if (curClass.ExtendsTypes is null) curClass.ExtendsTypes = new List<string>();
curClass.ExtendsTypes.Add(token);
}
if (inTypedef) context = FlagType.TypeDef;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@
<EmbeddedResource Include="Test Files\completion\BeforeOnCharAndReplaceText_issue2657_1.hx" />
<EmbeddedResource Include="Test Files\completion\AfterOnCharAndReplaceText_issue2657_1.hx" />
<EmbeddedResource Include="Test Files\parser\Issue2654_1.hx" />
<EmbeddedResource Include="Test Files\parser\Issue2660_1.hx" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,5 +529,13 @@ public void ParseFileIssue2654()
var model = ASContext.Context.GetCodeModel(ReadAllText("Issue2654_1"));
Assert.AreEqual(":optional", model.Classes.First().Members.Items.First().MetaDatas.First().Name);
}

[Test]
public void ParseFileIssue2660()
{
var model = ASContext.Context.GetCodeModel(ReadAllText("Issue2660_1"));
Assert.AreEqual("A", model.Classes.First().ExtendsType);
Assert.AreEqual(new List<string> {"B", "C"}, model.Classes.First().ExtendsTypes);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package;
typedef Issue2660_1 = {
> A,
> B,
> C,
}
typedef A = {}
typedef B = {}
typedef C = {}