Changeset 3863
- Timestamp:
- Jul 23, 2008, 1:33:50 PM (12 years ago)
- Location:
- devel-tools/trunk/eclipse
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/ast/Searcher.java
r3846 r3863 2 2 3 3 import java.util.ArrayList; 4 import java.util.List; 4 5 5 6 public class Searcher implements ProgramVisitor, SentenceVisitor, ExprVisitor { 6 public static ArrayList<AstNode> search (AstImplem astImplem, int offset) {7 public static List<AstNode> search (AstImplem astImplem, int offset) { 7 8 Searcher search = new Searcher(offset); 8 9 astImplem.accept(search); -
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpEditor.java
r3861 r3863 2 2 3 3 import java.util.ArrayList; 4 import java.util.List;5 4 6 5 import org.eclipse.core.resources.IFile; … … 37 36 import org.eclipse.ui.texteditor.ChainedPreferenceStore; 38 37 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; 39 import org.refal.rfpdt.ast.AstCall;40 import org.refal.rfpdt.ast.AstCut;41 import org.refal.rfpdt.ast.AstDecl;42 import org.refal.rfpdt.ast.AstFence;43 import org.refal.rfpdt.ast.AstFuncDef;44 38 import org.refal.rfpdt.ast.AstImplem; 45 import org.refal.rfpdt.ast.AstName;46 import org.refal.rfpdt.ast.AstNative;47 39 import org.refal.rfpdt.ast.AstNode; 48 import org.refal.rfpdt.ast.AstRef;49 import org.refal.rfpdt.ast.AstVar;50 import org.refal.rfpdt.ast.Searcher;51 40 import org.refal.rfpdt.core.RfpCore; 52 41 import org.refal.rfpdt.core.RfpProject; … … 57 46 58 47 public class RfpEditor extends TextEditor { 59 private static final AstNode[] empty = new AstNode[0];60 48 private static int editorCount = 0; 61 private static ColorManager colorManager = null;49 private static ColorManager colorManager; 62 50 63 51 private static Object getLockObject (IAnnotationModel annotationModel) { … … 77 65 private final ArrayList<Annotation> annotations = new ArrayList<Annotation>(); 78 66 79 private AstNode[] getNodeList (AstImplem astImplem, int offset) {80 ArrayList<AstNode> astNodeList = Searcher.search(astImplem, offset);81 int size = astNodeList.size();82 AstVar astVar = null;83 if (size > 0 && astNodeList.get(size-1) instanceof AstVar)84 astVar = (AstVar) astNodeList.get(size-1);85 else if (size > 1 && astNodeList.get(size-2) instanceof AstVar)86 astVar = (AstVar) astNodeList.get(size-2);87 if (astVar != null) {88 astVar = astVar.varDefinition;89 if (astVar == null || astVar.varUses == null)90 return empty;91 return astVar.varUses.toArray(new AstNode[astVar.varUses.size()]);92 }93 else if (size > 0 && astNodeList.get(size-1) instanceof AstFence) {94 AstFence astFence = (AstFence) astNodeList.get(size-1);95 if (astFence.uses == null)96 return empty;97 return astFence.uses.toArray(new AstNode[astFence.uses.size()]);98 } else if (size > 0 && astNodeList.get(size-1) instanceof AstCut) {99 AstFence astFence = ((AstCut) astNodeList.get(size-1)).fence;100 if (astFence == null || astFence.uses == null)101 return empty;102 return astFence.uses.toArray(new AstNode[astFence.uses.size()]);103 } else if (size > 1 && astNodeList.get(size-1) instanceof AstName){104 AstNode astNode = astNodeList.get(size-2);105 AstDecl astDecl = null;106 if (astNode instanceof AstDecl)107 astDecl = (AstDecl) astNode;108 else if (astNode instanceof AstFuncDef)109 astDecl = ((AstFuncDef) astNode).funcDecl;110 else if (astNode instanceof AstRef)111 astDecl = ((AstRef) astNode).decl;112 else if (astNode instanceof AstCall)113 astDecl = ((AstCall) astNode).funcDecl;114 else if (astNode instanceof AstNative)115 astDecl = ((AstNative) astNode).funcDecl;116 else117 return null;118 if (astDecl == null || astDecl.uses == null)119 return empty;120 return astDecl.uses.toArray(new AstNode[astDecl.uses.size()]);121 }122 return null;123 }124 125 67 // public void selectionChanged (IWorkbenchPart part, ISelection selection) {} 126 68 127 69 public void selectionChanged (SelectionChangedEvent event) { 128 if (rfpReconcilingStrategy == null) 129 return; 130 AstImplem astImplem = rfpReconcilingStrategy.getAstImplem(); 70 AstImplem astImplem = getAstImplem(); 131 71 if (astImplem == null) 132 72 return; … … 139 79 return; 140 80 int offset = textSelection.getOffset(); 141 AstNode[] astNodeList = getNodeList(astImplem,offset);81 AstNode[] astNodeList = astInfo.getUses(offset); 142 82 if (astNodeList == null) 143 83 return; … … 163 103 private IPropertyChangeListener propertyChangeListener; 164 104 private RfpSourceViewerConfiguration rfpSourceViewerConfiguration; 165 private IPreferenceStore store; 166 105 private IPreferenceStore store; 106 public final AstInfo astInfo; 107 108 /** May be <code>null<code>! */ 167 109 RfpReconcilingStrategy rfpReconcilingStrategy = null; 168 110 … … 172 114 colorManager = new ColorManager(); 173 115 bracketMatcher = new BracketMatcher(); 116 astInfo = new AstInfo(this); 174 117 setDocumentProvider(new RfpDocumentProvider()); 175 118 } … … 325 268 .addPostSelectionChangedListener(new SelectionChangedListener()); 326 269 } 327 270 328 271 public BracketMatcher getBracketMatcher () { 329 272 return bracketMatcher; … … 341 284 setStatusLineErrorMessage(str); 342 285 } 343 344 public List<AstNode> getNodes (int offset) { 345 if (rfpReconcilingStrategy == null) 346 return null; 347 AstImplem astImplem = rfpReconcilingStrategy.getAstImplem(); 348 if (astImplem == null) 349 return null; 350 return Searcher.search(astImplem, offset); 351 } 352 286 287 /** May return <code>null<code>! */ 288 public AstImplem getAstImplem () { 289 return rfpReconcilingStrategy != null ? rfpReconcilingStrategy.getAstImplem() : null; 290 } 291 353 292 public RfpProject getRfpProject () { 354 293 return RfpCore.getRfpProject(((IFile) getEditorInput().getAdapter(IFile.class)).getProject()); -
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpReconcilingStrategy.java
r3787 r3863 32 32 } 33 33 34 /** May return <code>null<code>! */ 34 35 public synchronized AstImplem getAstImplem () { 35 36 if (!isRelevant) -
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpTextHover.java
r3858 r3863 1 1 package org.refal.rfpdt.editor; 2 3 import java.util.List;4 2 5 3 import org.eclipse.jface.text.DefaultTextHover; … … 9 7 import org.eclipse.jface.text.source.ISourceViewer; 10 8 import org.eclipse.ui.texteditor.MarkerAnnotation; 11 import org.refal.rfpdt.ast.AstName;12 import org.refal.rfpdt.ast.AstNode;13 9 import org.refal.rfpdt.ast.IHoverInfo; 14 10 … … 25 21 if (res != null) 26 22 return res; 27 List<AstNode> astNodeList = editor.getNodes(hoverRegion.getOffset()); 28 if (astNodeList == null) 29 return null; 30 int size = astNodeList.size(); 31 if (size > 1 && astNodeList.get(size-1) instanceof AstName && astNodeList.get(size-2) instanceof IHoverInfo) 32 return ((IHoverInfo) astNodeList.get(size-2) ).getHoverInfo(); 33 return null; 23 IHoverInfo iHoverInfo = editor.astInfo.getIHoverInfo(hoverRegion.getOffset()); 24 return iHoverInfo != null ? iHoverInfo.getHoverInfo() : null; 34 25 } 35 26 -
devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/OpenDeclarationAction.java
r3862 r3863 1 1 package org.refal.rfpdt.ui.actions; 2 3 import java.util.List;4 2 5 3 import org.eclipse.core.resources.IFile; … … 7 5 import org.eclipse.ui.PartInitException; 8 6 import org.eclipse.ui.ide.IDE; 9 import org.refal.rfpdt.ast.AstCall;10 import org.refal.rfpdt.ast.AstCut;11 import org.refal.rfpdt.ast.AstDecl;12 import org.refal.rfpdt.ast.AstFuncDef;13 import org.refal.rfpdt.ast.AstName;14 import org.refal.rfpdt.ast.AstNative;15 7 import org.refal.rfpdt.ast.AstNode; 16 import org.refal.rfpdt.ast.AstRef;17 import org.refal.rfpdt.ast.AstVar;18 8 import org.refal.rfpdt.editor.RfpEditor; 19 9 import org.refal.rfpdt.editor.RfpEditorMessages; … … 25 15 return; 26 16 ISourceViewer sourceViewer = editor.sourceViewer(); 27 List<AstNode> nodeList = editor.getNodes(getSelection().getOffset()); 28 if (nodeList == null) { 29 editor.statusLineErrorMessage(RfpEditorMessages.OpenDeclaration_error_invalidSelection); 30 sourceViewer.getTextWidget().getDisplay().beep(); 31 return; 32 } 33 AstNode astNode = getNode(nodeList); 17 AstNode astNode = editor.astInfo.getDeclaration(getSelection().getOffset()); 34 18 if (astNode == null) { 35 19 editor.statusLineErrorMessage(RfpEditorMessages.OpenDeclaration_error_invalidSelection); … … 51 35 } 52 36 } 53 54 private AstNode getNode (List<AstNode> astNodeList) {55 int size = astNodeList.size();56 AstVar astVar = null;57 if (size > 0 && astNodeList.get(size - 1) instanceof AstVar)58 astVar = (AstVar) astNodeList.get(size - 1);59 else if (size > 1 && astNodeList.get(size - 2) instanceof AstVar)60 astVar = (AstVar) astNodeList.get(size - 2);61 if (astVar != null)62 return astVar.varDefinition;63 else if (size > 0 && astNodeList.get(size - 1) instanceof AstCut)64 return ((AstCut) astNodeList.get(size - 1)).fence;65 else if (size > 1 && astNodeList.get(size - 1) instanceof AstName) {66 AstNode astNode = astNodeList.get(size - 2);67 AstDecl astDecl = null;68 if (astNode instanceof AstDecl)69 astDecl = (AstDecl) astNode;70 else if (astNode instanceof AstFuncDef)71 astDecl = ((AstFuncDef) astNode).funcDecl;72 else if (astNode instanceof AstRef)73 astDecl = ((AstRef) astNode).decl;74 else if (astNode instanceof AstCall)75 astDecl = ((AstCall) astNode).funcDecl;76 else if (astNode instanceof AstNative)77 astDecl = ((AstNative) astNode).funcDecl;78 else79 return null;80 return astDecl != null ? astDecl.name : null;81 }82 return null;83 }84 37 }
Note: See TracChangeset
for help on using the changeset viewer.