Changeset 3863 for devel-tools/trunk


Ignore:
Timestamp:
Jul 23, 2008, 1:33:50 PM (12 years ago)
Author:
yura
Message:
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  
    22
    33import java.util.ArrayList;
     4import java.util.List;
    45
    56public 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) {
    78        Searcher search = new Searcher(offset);
    89        astImplem.accept(search);
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpEditor.java

    r3861 r3863  
    22
    33import java.util.ArrayList;
    4 import java.util.List;
    54
    65import org.eclipse.core.resources.IFile;
     
    3736import org.eclipse.ui.texteditor.ChainedPreferenceStore;
    3837import 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;
    4438import org.refal.rfpdt.ast.AstImplem;
    45 import org.refal.rfpdt.ast.AstName;
    46 import org.refal.rfpdt.ast.AstNative;
    4739import 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;
    5140import org.refal.rfpdt.core.RfpCore;
    5241import org.refal.rfpdt.core.RfpProject;
     
    5746
    5847public class RfpEditor extends TextEditor {
    59     private static final AstNode[] empty = new AstNode[0];
    6048    private static int editorCount = 0;
    61     private static ColorManager colorManager = null;
     49    private static ColorManager colorManager;
    6250
    6351    private static Object getLockObject (IAnnotationModel annotationModel) {
     
    7765        private final ArrayList<Annotation> annotations = new ArrayList<Annotation>();
    7866
    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                 else
    117                     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 
    12567        // public void selectionChanged (IWorkbenchPart part, ISelection selection) {}
    12668
    12769        public void selectionChanged (SelectionChangedEvent event) {
    128             if (rfpReconcilingStrategy == null)
    129                 return;
    130             AstImplem astImplem = rfpReconcilingStrategy.getAstImplem();
     70            AstImplem astImplem = getAstImplem();
    13171            if (astImplem == null)
    13272                return;
     
    13979                return;
    14080            int offset = textSelection.getOffset();
    141             AstNode[] astNodeList = getNodeList(astImplem, offset);
     81            AstNode[] astNodeList = astInfo.getUses(offset);
    14282            if (astNodeList == null)
    14383                return;
     
    163103    private IPropertyChangeListener propertyChangeListener;
    164104    private RfpSourceViewerConfiguration rfpSourceViewerConfiguration;
    165     private  IPreferenceStore store;
    166 
     105    private IPreferenceStore store;
     106    public final AstInfo astInfo;
     107
     108    /** May be <code>null<code>! */
    167109    RfpReconcilingStrategy rfpReconcilingStrategy = null;
    168110
     
    172114            colorManager = new ColorManager();
    173115        bracketMatcher = new BracketMatcher();
     116        astInfo = new AstInfo(this);
    174117        setDocumentProvider(new RfpDocumentProvider());
    175118    }
     
    325268                .addPostSelectionChangedListener(new SelectionChangedListener());
    326269    }
    327    
     270
    328271    public BracketMatcher getBracketMatcher () {
    329272        return bracketMatcher;
     
    341284        setStatusLineErrorMessage(str);
    342285    }
    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
    353292    public RfpProject getRfpProject () {
    354293        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  
    3232    }
    3333
     34    /** May return <code>null<code>! */
    3435    public synchronized AstImplem getAstImplem () {
    3536        if (!isRelevant)
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/editor/RfpTextHover.java

    r3858 r3863  
    11package org.refal.rfpdt.editor;
    2 
    3 import java.util.List;
    42
    53import org.eclipse.jface.text.DefaultTextHover;
     
    97import org.eclipse.jface.text.source.ISourceViewer;
    108import org.eclipse.ui.texteditor.MarkerAnnotation;
    11 import org.refal.rfpdt.ast.AstName;
    12 import org.refal.rfpdt.ast.AstNode;
    139import org.refal.rfpdt.ast.IHoverInfo;
    1410
     
    2521        if (res != null)
    2622            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;
    3425    }
    3526
  • devel-tools/trunk/eclipse/org.refal.rfpdt.ui/src/org/refal/rfpdt/ui/actions/OpenDeclarationAction.java

    r3862 r3863  
    11package org.refal.rfpdt.ui.actions;
    2 
    3 import java.util.List;
    42
    53import org.eclipse.core.resources.IFile;
     
    75import org.eclipse.ui.PartInitException;
    86import 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;
    157import org.refal.rfpdt.ast.AstNode;
    16 import org.refal.rfpdt.ast.AstRef;
    17 import org.refal.rfpdt.ast.AstVar;
    188import org.refal.rfpdt.editor.RfpEditor;
    199import org.refal.rfpdt.editor.RfpEditorMessages;
     
    2515            return;
    2616        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());
    3418        if (astNode == null) {
    3519            editor.statusLineErrorMessage(RfpEditorMessages.OpenDeclaration_error_invalidSelection);
     
    5135        }
    5236    }
    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             else
    79                 return null;
    80             return astDecl != null ? astDecl.name : null;
    81         }
    82         return null;
    83     }
    8437}
Note: See TracChangeset for help on using the changeset viewer.