Browse Source

Fixed SD2-1181: Remove unused imports removes using statements required for type arguments

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2032 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
5691c03e96
  1. 11
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Node.cs
  2. 61
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  3. 5
      src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs
  4. 15
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs
  5. 30
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs
  6. 4
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryRefactoringProvider.cs

11
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Node.cs

@ -44,9 +44,16 @@ namespace NRefactoryASTGenerator.Ast @@ -44,9 +44,16 @@ namespace NRefactoryASTGenerator.Ast
}
[CustomImplementation]
class TypeReference : AbstractNode {}
class TypeReference : AbstractNode
{
List<TypeReference> genericTypes;
}
[CustomImplementation]
class InnerClassTypeReference : TypeReference {}
class InnerClassTypeReference : TypeReference
{
TypeReference baseType;
}
class AttributeSection : AbstractNode, INullable
{

61
src/Libraries/NRefactory/Project/Src/Ast/Generated.cs

@ -12,6 +12,7 @@ namespace ICSharpCode.NRefactory.Ast { @@ -12,6 +12,7 @@ namespace ICSharpCode.NRefactory.Ast {
using System;
using System.Collections.Generic;
public class AddHandlerStatement : Statement {
Expression eventExpression;
@ -1596,9 +1597,9 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1596,9 +1597,9 @@ namespace ICSharpCode.NRefactory.Ast {
initializer = Expression.Null;
}
public bool HasAddRegion {
public bool HasRemoveRegion {
get {
return !addRegion.IsNull;
return !removeRegion.IsNull;
}
}
@ -1608,9 +1609,9 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1608,9 +1609,9 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public bool HasRemoveRegion {
public bool HasAddRegion {
get {
return !removeRegion.IsNull;
return !addRegion.IsNull;
}
}
@ -1816,15 +1817,6 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1816,15 +1817,6 @@ namespace ICSharpCode.NRefactory.Ast {
}
public TypeReference GetTypeForField(int fieldIndex)
{
if (!typeReference.IsNull) {
return typeReference;
}
return ((VariableDeclaration)Fields[fieldIndex]).TypeReference;
}
public VariableDeclaration GetVariableDeclaration(string variableName)
{
foreach (VariableDeclaration variableDeclaration in Fields) {
@ -1835,6 +1827,15 @@ namespace ICSharpCode.NRefactory.Ast { @@ -1835,6 +1827,15 @@ namespace ICSharpCode.NRefactory.Ast {
return null;
}
public TypeReference GetTypeForField(int fieldIndex)
{
if (!typeReference.IsNull) {
return typeReference;
}
return ((VariableDeclaration)Fields[fieldIndex]).TypeReference;
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitFieldDeclaration(this, data);
}
@ -2279,22 +2280,16 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2279,22 +2280,16 @@ namespace ICSharpCode.NRefactory.Ast {
}
public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement)
public IfElseStatement(Expression condition, Statement trueStatement)
: this(condition) {
this.trueStatement.Add(Statement.CheckNull(trueStatement));
this.falseStatement.Add(Statement.CheckNull(falseStatement));
}
public bool HasElseIfSections {
get {
return elseIfSections.Count > 0;
}
}
public IfElseStatement(Expression condition, Statement trueStatement)
public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement)
: this(condition) {
this.trueStatement.Add(Statement.CheckNull(trueStatement));
this.falseStatement.Add(Statement.CheckNull(falseStatement));
}
public bool HasElseStatements {
@ -2303,6 +2298,12 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2303,6 +2298,12 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public bool HasElseIfSections {
get {
return elseIfSections.Count > 0;
}
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitIfElseStatement(this, data);
}
@ -2416,15 +2417,15 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2416,15 +2417,15 @@ namespace ICSharpCode.NRefactory.Ast {
setRegion = PropertySetRegion.Null;
}
public bool IsReadOnly {
public bool HasSetRegion {
get {
return HasGetRegion && !HasSetRegion;
return !setRegion.IsNull;
}
}
public bool HasGetRegion {
public bool IsReadOnly {
get {
return !getRegion.IsNull;
return HasGetRegion && !HasSetRegion;
}
}
@ -2434,9 +2435,9 @@ namespace ICSharpCode.NRefactory.Ast { @@ -2434,9 +2435,9 @@ namespace ICSharpCode.NRefactory.Ast {
}
}
public bool HasSetRegion {
public bool HasGetRegion {
get {
return !setRegion.IsNull;
return !getRegion.IsNull;
}
}
@ -4226,10 +4227,10 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam @@ -4226,10 +4227,10 @@ public TypeReferenceExpression(string typeName) : this(new TypeReference(typeNam
Usings = usings;
}
public UsingDeclaration(string @namespace) : this(@namespace, null) {}
public UsingDeclaration(string @namespace, TypeReference alias) { usings = new List<Using>(1); usings.Add(new Using(@namespace, alias)); }
public UsingDeclaration(string @namespace) : this(@namespace, null) {}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitUsingDeclaration(this, data);
}

5
src/Libraries/NRefactory/Project/Src/Ast/TypeReference.cs

@ -359,9 +359,8 @@ namespace ICSharpCode.NRefactory.Ast @@ -359,9 +359,8 @@ namespace ICSharpCode.NRefactory.Ast
TypeReference baseType;
public TypeReference BaseType {
get {
return baseType;
}
get { return baseType; }
set { baseType = value; }
}
public override TypeReference Clone()

15
src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs

@ -10,9 +10,11 @@ @@ -10,9 +10,11 @@
namespace ICSharpCode.NRefactory.Visitors {
using System;
using System.Collections.Generic;
using System.Diagnostics;
using ICSharpCode.NRefactory.Ast;
public abstract class AbstractAstVisitor : IAstVisitor {
public virtual object VisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data) {
@ -566,7 +568,13 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -566,7 +568,13 @@ namespace ICSharpCode.NRefactory.Visitors {
public virtual object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data) {
Debug.Assert((innerClassTypeReference != null));
return null;
Debug.Assert((innerClassTypeReference.GenericTypes != null));
Debug.Assert((innerClassTypeReference.BaseType != null));
foreach (TypeReference o in innerClassTypeReference.GenericTypes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
return innerClassTypeReference.BaseType.AcceptVisitor(this, data);
}
public virtual object VisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data) {
@ -952,6 +960,11 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -952,6 +960,11 @@ namespace ICSharpCode.NRefactory.Visitors {
public virtual object VisitTypeReference(TypeReference typeReference, object data) {
Debug.Assert((typeReference != null));
Debug.Assert((typeReference.GenericTypes != null));
foreach (TypeReference o in typeReference.GenericTypes) {
Debug.Assert(o != null);
o.AcceptVisitor(this, data);
}
return null;
}

30
src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs

@ -12,9 +12,9 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -12,9 +12,9 @@ namespace ICSharpCode.NRefactory.Visitors {
using System;
using System.Collections.Generic;
using System.Diagnostics;
using ICSharpCode.NRefactory.Ast;
/// <summary>
/// The AbstractAstTransformer will iterate through the whole AST,
/// just like the AbstractAstVisitor. However, the AbstractAstTransformer allows
@ -1034,6 +1034,22 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1034,6 +1034,22 @@ namespace ICSharpCode.NRefactory.Visitors {
public virtual object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data) {
Debug.Assert((innerClassTypeReference != null));
Debug.Assert((innerClassTypeReference.GenericTypes != null));
Debug.Assert((innerClassTypeReference.BaseType != null));
for (int i = 0; i < innerClassTypeReference.GenericTypes.Count; i++) {
TypeReference o = innerClassTypeReference.GenericTypes[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (TypeReference)nodeStack.Pop();
if (o == null)
innerClassTypeReference.GenericTypes.RemoveAt(i--);
else
innerClassTypeReference.GenericTypes[i] = o;
}
nodeStack.Push(innerClassTypeReference.BaseType);
innerClassTypeReference.BaseType.AcceptVisitor(this, data);
innerClassTypeReference.BaseType = ((TypeReference)(nodeStack.Pop()));
return null;
}
@ -1748,6 +1764,18 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1748,6 +1764,18 @@ namespace ICSharpCode.NRefactory.Visitors {
public virtual object VisitTypeReference(TypeReference typeReference, object data) {
Debug.Assert((typeReference != null));
Debug.Assert((typeReference.GenericTypes != null));
for (int i = 0; i < typeReference.GenericTypes.Count; i++) {
TypeReference o = typeReference.GenericTypes[i];
Debug.Assert(o != null);
nodeStack.Push(o);
o.AcceptVisitor(this, data);
o = (TypeReference)nodeStack.Pop();
if (o == null)
typeReference.GenericTypes.RemoveAt(i--);
else
typeReference.GenericTypes[i] = o;
}
return null;
}

4
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/Refactoring/NRefactoryRefactoringProvider.cs

@ -113,7 +113,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -113,7 +113,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
}
}
protected virtual Dictionary<PossibleTypeReference, object> FindPossibleTypeReferences(string extension, string fileContent)
protected virtual Dictionary<PossibleTypeReference, object> FindPossibleTypeReferences(string fileContent)
{
NR.IParser parser = ParseFile(fileContent);
if (parser == null) {
@ -136,7 +136,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring @@ -136,7 +136,7 @@ namespace ICSharpCode.SharpDevelop.Dom.Refactoring
{
IClass @class = cu.Classes.Count == 0 ? null : cu.Classes[0];
Dictionary<PossibleTypeReference, object> references = FindPossibleTypeReferences(Path.GetExtension(fileName), fileContent);
Dictionary<PossibleTypeReference, object> references = FindPossibleTypeReferences(fileContent);
if (references == null) return new IUsing[0];
Dictionary<IUsing, object> dict = new Dictionary<IUsing, object>();

Loading…
Cancel
Save