Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Overbey2008-04-04 14:45:52 +0000
committerJeffrey Overbey2008-04-04 14:45:52 +0000
commita7360476513ccbbe2e970eb3b96d195e7ea1bd97 (patch)
treef0752a3729d4096e3c7a07fcd803d99a636f7f30
parente61041fdbeb3e4f24c353528dcc9e50cf2be33ed (diff)
downloadorg.eclipse.photran-a7360476513ccbbe2e970eb3b96d195e7ea1bd97.tar.gz
org.eclipse.photran-a7360476513ccbbe2e970eb3b96d195e7ea1bd97.tar.xz
org.eclipse.photran-a7360476513ccbbe2e970eb3b96d195e7ea1bd97.zip
Fortran elements have pos and lines set correctly
-rw-r--r--org.eclipse.photran.core.vpg/model/org/eclipse/photran/internal/core/model/FortranModelBuildingVisitor.java35
-rw-r--r--org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranRefactoring.java23
2 files changed, 41 insertions, 17 deletions
diff --git a/org.eclipse.photran.core.vpg/model/org/eclipse/photran/internal/core/model/FortranModelBuildingVisitor.java b/org.eclipse.photran.core.vpg/model/org/eclipse/photran/internal/core/model/FortranModelBuildingVisitor.java
index 55231873..5bc5c6bf 100644
--- a/org.eclipse.photran.core.vpg/model/org/eclipse/photran/internal/core/model/FortranModelBuildingVisitor.java
+++ b/org.eclipse.photran.core.vpg/model/org/eclipse/photran/internal/core/model/FortranModelBuildingVisitor.java
@@ -22,6 +22,7 @@ import org.eclipse.photran.internal.core.parser.ASTSubroutineSubprogramNode;
import org.eclipse.photran.internal.core.parser.ASTVisitor;
import org.eclipse.photran.internal.core.parser.GenericParseTreeVisitor;
import org.eclipse.photran.internal.core.parser.Parser.InteriorNode;
+import org.eclipse.photran.internal.core.refactoring.infrastructure.FortranRefactoring;
/**
* This parse tree visitor is used by the <code>FortranModelBuilder</code> to create the model you
@@ -125,30 +126,42 @@ public final class FortranModelBuildingVisitor extends GenericParseTreeVisitor
private class ElementMappingVisitor extends ASTVisitor
{
+ private <T extends FortranElement> T setPos(T element, InteriorNode astNode)
+ {
+ Token first = FortranRefactoring.findFirstTokenIn(astNode);
+ Token last = FortranRefactoring.findLastTokenIn(astNode);
+ if (first != null && last != null)
+ {
+ element.setPos(first.getFileOffset(), last.getFileOffset()+last.getLength()-first.getFileOffset());
+ element.setLines(first.getLine(), last.getLine());
+ }
+ return element;
+ }
+
public void visitASTMainProgramNode(ASTMainProgramNode node)
{
Token token = node.getProgramStmt() == null
? null
: node.getProgramStmt().getProgramName().getProgramName();
- addToModel(node, new FortranElement.MainProgram(getCurrentParent(), token));
+ addToModel(node, setPos(new FortranElement.MainProgram(getCurrentParent(), token), node));
}
public void visitASTModuleNode(ASTModuleNode node)
{
Token token = node.getModuleStmt().getModuleName().getModuleName();
- addToModel(node, new FortranElement.Module(getCurrentParent(), token));
+ addToModel(node, setPos(new FortranElement.Module(getCurrentParent(), token), node));
}
public void visitASTFunctionSubprogramNode(ASTFunctionSubprogramNode node)
{
Token token = node.getFunctionStmt().getFunctionName().getFunctionName();
- addToModel(node, new FortranElement.Function(getCurrentParent(), token));
+ addToModel(node, setPos(new FortranElement.Function(getCurrentParent(), token), node));
}
public void visitASTSubroutineSubprogramNode(ASTSubroutineSubprogramNode node)
{
Token token = node.getSubroutineStmt().getSubroutineName().getSubroutineName();
- addToModel(node, new FortranElement.Subroutine(getCurrentParent(), token));
+ addToModel(node, setPos(new FortranElement.Subroutine(getCurrentParent(), token), node));
}
public void visitASTBlockDataSubprogramNode(ASTBlockDataSubprogramNode node)
@@ -156,27 +169,27 @@ public final class FortranModelBuildingVisitor extends GenericParseTreeVisitor
Token token = node.getBlockDataStmt().getBlockDataName() == null
? null
: node.getBlockDataStmt().getBlockDataName().getBlockDataName();
- addToModel(node, new FortranElement.BlockData(getCurrentParent(), token));
+ addToModel(node, setPos(new FortranElement.BlockData(getCurrentParent(), token), node));
}
public void visitASTDerivedTypeDefNode(ASTDerivedTypeDefNode node)
{
Token token = node.getDerivedTypeStmt().getTypeName();
- addToModel(node, new FortranElement.DerivedType(getCurrentParent(), token));
+ addToModel(node, setPos(new FortranElement.DerivedType(getCurrentParent(), token), node));
}
public void visitASTComponentDefStmtNode(ASTComponentDefStmtNode node)
{
ASTComponentDeclListNode list = node.getComponentDeclList();
for (int i = 0; i < list.size(); i++)
- addToModelNoChildren(new FortranElement.Variable(getCurrentParent(), list.getComponentDecl(i).getComponentName().getComponentName()));
+ addToModelNoChildren(setPos(new FortranElement.Variable(getCurrentParent(), list.getComponentDecl(i).getComponentName().getComponentName()), node));
}
public void visitASTExternalStmtNode(ASTExternalStmtNode node)
{
ASTExternalNameListNode list = node.getExternalNameList();
for (int i = 0; i < list.size(); i++)
- addToModel(node, new FortranElement.Variable(getCurrentParent(), list.getExternalName(i)));
+ addToModel(node, setPos(new FortranElement.Variable(getCurrentParent(), list.getExternalName(i)), node));
}
public void visitASTInterfaceBlockNode(ASTInterfaceBlockNode node)
@@ -184,19 +197,19 @@ public final class FortranModelBuildingVisitor extends GenericParseTreeVisitor
Token token = node.getInterfaceStmt().getGenericName() == null
? null
: node.getInterfaceStmt().getGenericName().getGenericName();
- addToModel(node, new FortranElement.Variable(getCurrentParent(), token));
+ addToModel(node, setPos(new FortranElement.Variable(getCurrentParent(), token), node));
}
public void visitASTIntrinsicStmtNode(ASTIntrinsicStmtNode node)
{
ASTIntrinsicListNode list = node.getIntrinsicList();
for (int i = 0; i < list.size(); i++)
- addToModel(node, new FortranElement.Variable(getCurrentParent(), list.getIntrinsicProcedureName(i)));
+ addToModel(node, setPos(new FortranElement.Variable(getCurrentParent(), list.getIntrinsicProcedureName(i)), node));
}
public void visitASTStmtFunctionStmtNode(ASTStmtFunctionStmtNode node)
{
- addToModel(node, new FortranElement.Variable(getCurrentParent(), node.getName().getName()));
+ addToModel(node, setPos(new FortranElement.Variable(getCurrentParent(), node.getName().getName()), node));
}
}
}
diff --git a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranRefactoring.java b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranRefactoring.java
index 5ace3ed8..4c9cbade 100644
--- a/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranRefactoring.java
+++ b/org.eclipse.photran.core.vpg/src/org/eclipse/photran/internal/core/refactoring/infrastructure/FortranRefactoring.java
@@ -93,16 +93,27 @@ public abstract class FortranRefactoring extends Refactoring
public FortranRefactoring(IFile file, /* boolean isFixedForm, */ ITextSelection selection)
{
- assert file != null && file.isAccessible();
- assert selection != null;
+ assert file != null && file.isAccessible();
+ assert selection != null;
- this.vpg = PhotranVPG.getInstance();
-
+ this.vpg = PhotranVPG.getInstance();
+
this.fileInEditor = file;
//this.isFixedForm = isFixedForm;
this.selectedRegionInEditor = selection;
}
+ public FortranRefactoring(IFile file /* boolean isFixedForm, */)
+ {
+ assert file != null && file.isAccessible();
+
+ this.vpg = PhotranVPG.getInstance();
+
+ this.fileInEditor = file;
+ //this.isFixedForm = isFixedForm;
+ this.selectedRegionInEditor = null;
+ }
+
///////////////////////////////////////////////////////////////////////////
// LTK Refactoring Implementation
///////////////////////////////////////////////////////////////////////////
@@ -508,7 +519,7 @@ public abstract class FortranRefactoring extends Refactoring
// PARSE TREE SEARCHING ///////////////////////////////////////////////////
- protected Token findFirstTokenIn(InteriorNode node)
+ public static Token findFirstTokenIn(InteriorNode node)
{
try
{
@@ -542,7 +553,7 @@ public abstract class FortranRefactoring extends Refactoring
public Token getLastToken() { return lastToken; }
}
- protected Token findLastTokenIn(InteriorNode node)
+ public static Token findLastTokenIn(InteriorNode node)
{
LastTokenVisitor lastTokenVisitor = new LastTokenVisitor();
node.visitUsing(lastTokenVisitor);

Back to the top