Changeset 25b5d220afcf17776b844086f439554f14dc63dc
- Timestamp:
- 06/28/09 23:36:50 (8 months ago)
- Author:
- mb0 <mb0@…>
- git-author:
- mb0 <mb0@mb0.org> / 2009-06-10T20:05:17Z+0200
- Parents:
- 49cbb509af4876ed4a2ccd7942c17372373a5ae2
- Children:
- 364575fc79ca0a2d7d0efbd5c165c1d2dfc36a3b
- git-committer:
- mb0 <mb0@mb0.org> / 2009-06-28T23:36:50Z+0200
- Message:
-
moved symboltable related code from parser to parse controller
changed diagnose visitors
added indexing visitor. sources are now added to the index0r.
every source folder is added as axroot.
added hyperlinks for source indexes
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r49cbb50
|
r25b5d22
|
|
| 1 | 1 | package org.axdt.as3.imp.parser; |
| 2 | 2 | |
| 3 | | import java.util.Stack; |
| | 3 | import java.util.HashSet; |
| | 4 | import java.util.Iterator; |
| | 5 | |
| | 6 | import lpg.runtime.IAst; |
| | 7 | import lpg.runtime.IToken; |
| 4 | 8 | |
| 5 | 9 | import org.axdt.as3.AS3Plugin; |
| 6 | 10 | import org.axdt.as3.imp.parser.Ast.ASTNode; |
| 7 | | import org.axdt.as3.imp.parser.Ast.Program; |
| 8 | 11 | import org.axdt.as3.imp.services.AS3SyntaxProperties; |
| 9 | 12 | import org.eclipse.core.runtime.IPath; |
| … |
… |
|
| 18 | 21 | import org.eclipse.imp.parser.SimpleLPGParseController; |
| 19 | 22 | import org.eclipse.imp.services.ILanguageSyntaxProperties; |
| | 23 | import org.eclipse.jface.text.IRegion; |
| 20 | 24 | |
| 21 | 25 | public class AS3ParseController extends SimpleLPGParseController implements IParseController { |
| … |
… |
|
| 27 | 31 | |
| 28 | 32 | private int lastHash; |
| | 33 | |
| | 34 | private IPath location; |
| | 35 | |
| | 36 | private SymbolTable topLevelSymbolTable = null; |
| 29 | 37 | |
| 30 | 38 | public AS3ParseController() { |
| … |
… |
|
| 78 | 86 | AS3Plugin.getDefault().debug("parsing "+ getPath().toString()); |
| 79 | 87 | lastHash = newHash; |
| | 88 | topLevelSymbolTable = null; |
| 80 | 89 | PMMonitor my_monitor = new PMMonitor(monitor); |
| 81 | 90 | char[] contentsArray = contents.toCharArray(); |
| … |
… |
|
| 84 | 93 | lexer = new AS3Lexer(); |
| 85 | 94 | } |
| 86 | | IPath fullpath = fProject.getResource().getLocation().append(fFilePath); |
| 87 | | lexer.reset(contentsArray, fullpath.toString()); |
| | 95 | location = fProject.getResource().getLocation().append(fFilePath); |
| | 96 | lexer.reset(contentsArray, location.toString()); |
| 88 | 97 | |
| 89 | 98 | if (parser == null) { |
| … |
… |
|
| 106 | 115 | if (fCurrentAst instanceof ASTNode) { |
| 107 | 116 | ASTNode node = (ASTNode) fCurrentAst; |
| 108 | | resolveSymbolTable(node); |
| | 117 | topLevelSymbolTable = resolveSymbolTable(node); |
| 109 | 118 | if (resolve) { |
| | 119 | buildIndex(node); |
| 110 | 120 | resolveDeclarations(node); |
| 111 | 121 | } |
| … |
… |
|
| 117 | 127 | } |
| 118 | 128 | |
| | 129 | protected void buildIndex(ASTNode root) { |
| | 130 | root.accept(new IndexingVisitor(this)); |
| | 131 | } |
| | 132 | |
| 119 | 133 | protected void resolveDeclarations(ASTNode root) { |
| 120 | | root.accept(new ResolvingVisitor(parser)); |
| | 134 | root.accept(new ResolvingVisitor(this)); |
| 121 | 135 | } |
| 122 | 136 | |
| 123 | | protected void resolveSymbolTable(ASTNode root) { |
| 124 | | parser.symbolTableStack = new Stack<SymbolTable>(); |
| 125 | | parser.topLevelSymbolTable = new SymbolTable(null, Program.class); |
| 126 | | parser.symbolTableStack.push(parser.topLevelSymbolTable); |
| 127 | | root.accept(new SymbolTableVisitor(parser)); |
| | 137 | protected SymbolTable resolveSymbolTable(ASTNode root) { |
| | 138 | SymbolTableVisitor symbolTableVisitor = new SymbolTableVisitor(this); |
| | 139 | root.accept(symbolTableVisitor); |
| | 140 | return symbolTableVisitor.getTopLevelSymbolTable(); |
| 128 | 141 | } |
| 129 | 142 | |
| … |
… |
|
| 131 | 144 | return backupAst; |
| 132 | 145 | } |
| | 146 | |
| | 147 | public SymbolTable getEnclosingSymbolTable(IAst node) { |
| | 148 | if (topLevelSymbolTable != null) { |
| | 149 | return topLevelSymbolTable.getEnclosingSymbolTable(node); |
| | 150 | } |
| | 151 | return null; |
| | 152 | } |
| 133 | 153 | } |
-
|
r82cecb8
|
r25b5d22
|
|
| 20 | 20 | |
| 21 | 21 | %Globals |
| 22 | | /.import org.eclipse.imp.parser.IParser; |
| 23 | | import java.util.Stack; |
| | 22 | /. |
| 24 | 23 | ./ |
| 25 | 24 | %End |
| … |
… |
|
| 27 | 26 | %Define |
| 28 | 27 | $ast_class /.Object./ |
| 29 | | $additional_interfaces /., IParser./ |
| | 28 | $additional_interfaces /., org.eclipse.imp.parser.IParser ./ |
| 30 | 29 | %End |
| 31 | 30 | |
| … |
… |
|
| 1043 | 1042 | %Headers |
| 1044 | 1043 | /. |
| 1045 | | Stack<SymbolTable> symbolTableStack = null; |
| 1046 | | SymbolTable topLevelSymbolTable = null; |
| 1047 | | |
| 1048 | | public SymbolTable getTopLevelSymbolTable() { |
| 1049 | | return topLevelSymbolTable; |
| 1050 | | } |
| 1051 | | |
| 1052 | | public SymbolTable getEnclosingSymbolTable(IAst n) { |
| 1053 | | if (topLevelSymbolTable != null) { |
| 1054 | | return topLevelSymbolTable.getEnclosingSymbolTable(n); |
| 1055 | | } |
| 1056 | | return null; |
| 1057 | | } |
| 1058 | | |
| 1059 | | public void resolve(ASTNode root) { |
| 1060 | | if (root != null) { |
| 1061 | | symbolTableStack = new Stack<SymbolTable>(); |
| 1062 | | topLevelSymbolTable = new SymbolTable(null, Program.class); |
| 1063 | | symbolTableStack.push(topLevelSymbolTable); |
| 1064 | | root.accept(new SymbolTableVisitor(this)); |
| 1065 | | } |
| 1066 | | } |
| 1067 | 1044 | ./ |
| 1068 | 1045 | %End |
-
|
r69d1ca8
|
r25b5d22
|
|
| 9 | 9 | import org.axdt.as3.imp.parser.Ast.ASTNode; |
| 10 | 10 | import org.axdt.as3.imp.parser.Ast.AbstractVisitor; |
| | 11 | import org.eclipse.core.resources.IFile; |
| | 12 | import org.eclipse.core.resources.IProject; |
| 11 | 13 | |
| 12 | 14 | public class DiagnoseVisitor extends AbstractVisitor { |
| 13 | 15 | protected static int[] NULL_LOCATION = new int[] {0,0}; |
| 14 | 16 | |
| 15 | | protected final IPrsStream prs; |
| 16 | | protected final ILexStream lex; |
| 17 | | protected final AS3Parser parser; |
| | 17 | protected final IPrsStream prsStream; |
| | 18 | protected final ILexStream lexStream; |
| | 19 | protected AS3ParseController parseController; |
| | 20 | protected int errorCount = 0; |
| | 21 | protected boolean severeError = false; |
| | 22 | |
| | 23 | public DiagnoseVisitor(AS3ParseController parseController) { |
| | 24 | this.parseController = parseController; |
| | 25 | this.prsStream = parseController.getParser().getIPrsStream(); |
| | 26 | this.lexStream = prsStream.getILexStream(); |
| | 27 | } |
| | 28 | |
| | 29 | protected IProject getProject() { |
| | 30 | return parseController.getProject().getRawProject(); |
| | 31 | } |
| 18 | 32 | |
| 19 | | public DiagnoseVisitor(AS3Parser parser) { |
| 20 | | this.prs = parser.getIPrsStream(); |
| 21 | | this.lex = prs.getILexStream(); |
| 22 | | this.parser = parser; |
| | 33 | protected IFile getFile() { |
| | 34 | return getProject().getFile(parseController.getPath()); |
| 23 | 35 | } |
| 24 | 36 | |
| … |
… |
|
| 35 | 47 | } |
| 36 | 48 | public void emitError(int code, int startOffset, int endOffset, String message) { |
| 37 | | int[] loc = lex.getLocation(startOffset, endOffset); |
| | 49 | int[] loc = lexStream.getLocation(startOffset, endOffset); |
| 38 | 50 | String[] msgs = new String[] {message}; |
| 39 | | IMessageHandler handler = lex.getMessageHandler(); |
| 40 | | handler.handleMessage(code, loc, NULL_LOCATION, prs.getFileName(), msgs); |
| | 51 | IMessageHandler handler = lexStream.getMessageHandler(); |
| | 52 | handler.handleMessage(code, loc, NULL_LOCATION, prsStream.getFileName(), msgs); |
| | 53 | errorCount++; |
| 41 | 54 | } |
| 42 | 55 | |
-
|
r69d1ca8
|
r25b5d22
|
|
| 4 | 4 | |
| 5 | 5 | import org.axdt.as3.AS3Plugin; |
| | 6 | import org.axdt.as3.imp.parser.Ast.AssignmentExpression; |
| 6 | 7 | import org.axdt.as3.imp.parser.Ast.Block; |
| 7 | 8 | import org.axdt.as3.imp.parser.Ast.ClassDefinition; |
| | 9 | import org.axdt.as3.imp.parser.Ast.ExpressionStatement; |
| 8 | 10 | import org.axdt.as3.imp.parser.Ast.FunctionDefinition; |
| 9 | 11 | import org.axdt.as3.imp.parser.Ast.FunctionExpression; |
| … |
… |
|
| 19 | 21 | import org.axdt.axdoc.util.Index0r; |
| 20 | 22 | import org.axdt.common.preferences.AxdtPreferences; |
| 21 | | import org.eclipse.core.resources.IFile; |
| 22 | | import org.eclipse.core.resources.ResourcesPlugin; |
| 23 | | import org.eclipse.core.runtime.Path; |
| 24 | 23 | |
| 25 | 24 | public class ResolvingVisitor extends DiagnoseVisitor { |
| … |
… |
|
| 27 | 26 | private boolean addDebugErrors; |
| 28 | 27 | |
| 29 | | public ResolvingVisitor(AS3Parser parser) { |
| 30 | | super(parser); |
| | 28 | public ResolvingVisitor(AS3ParseController parseController) { |
| | 29 | super(parseController); |
| 31 | 30 | addDebugErrors = AS3Plugin.getDefault() != null && AxdtPreferences.doDebug(); |
| 32 | 31 | index0r = Index0r.getInstance(); |
| … |
… |
|
| 40 | 39 | @Override |
| 41 | 40 | public boolean visit(PackageDefinition n) { |
| 42 | | String fileName = parser.getIPrsStream().getFileName(); |
| 43 | | IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(fileName)); |
| 44 | | String packageName = (files.length>0) ? AS3Util.getExpectedPackageName(files[0]): ""; |
| | 41 | String packageName = AS3Util.getExpectedPackageName(getFile()); |
| 45 | 42 | // check if name corresponds with folder names |
| 46 | 43 | if (n.getName() != null) { |
| … |
… |
|
| 125 | 122 | } |
| 126 | 123 | if (grandp != null) { |
| 127 | | String fileName = parser.getIPrsStream().getFileName(); |
| 128 | 124 | String nameString = name.getIdent().toString(); |
| 129 | | if (!fileName.endsWith(nameString+".as")) |
| | 125 | String expectedName = AS3Util.getExpectedMemberName(getFile()); |
| | 126 | if (!nameString.equals(expectedName)) |
| 130 | 127 | emitError(name, "public package member name should match the file name"); |
| 131 | 128 | } |
| … |
… |
|
| 134 | 131 | @Override |
| 135 | 132 | public boolean visit(FunctionDefinition n) { |
| 136 | | return true; |
| | 133 | return false; |
| 137 | 134 | } |
| 138 | 135 | |
| 139 | 136 | @Override |
| 140 | 137 | public boolean visit(FunctionExpression n) { |
| 141 | | return true; |
| | 138 | return false; |
| 142 | 139 | } |
| 143 | 140 | |
| 144 | 141 | @Override |
| 145 | 142 | public boolean visit(VariableBinding n) { |
| 146 | | return true; |
| | 143 | return false; |
| | 144 | } |
| | 145 | @Override |
| | 146 | public boolean visit(AssignmentExpression n) { |
| | 147 | return false; |
| | 148 | } |
| | 149 | @Override |
| | 150 | public boolean visit(ExpressionStatement n) { |
| | 151 | return false; |
| 147 | 152 | } |
| 148 | 153 | } |
-
|
r69d1ca8
|
r25b5d22
|
|
| 1 | 1 | package org.axdt.as3.imp.parser; |
| | 2 | |
| | 3 | import java.util.Stack; |
| 2 | 4 | |
| 3 | 5 | import lpg.runtime.IAst; |
| … |
… |
|
| 15 | 17 | import org.axdt.as3.imp.parser.Ast.PackageDefinition; |
| 16 | 18 | import org.axdt.as3.imp.parser.Ast.PlainParameter; |
| | 19 | import org.axdt.as3.imp.parser.Ast.Program; |
| 17 | 20 | import org.axdt.as3.imp.parser.Ast.RestParameter; |
| 18 | 21 | import org.axdt.as3.imp.parser.Ast.VariableBinding; |
| … |
… |
|
| 21 | 24 | public class SymbolTableVisitor extends DiagnoseVisitor { |
| 22 | 25 | |
| 23 | | public SymbolTableVisitor(AS3Parser parser) { |
| 24 | | super(parser); |
| | 26 | private Stack<SymbolTable> symbolTableStack = null; |
| | 27 | private SymbolTable topLevelSymbolTable = null; |
| | 28 | |
| | 29 | public SymbolTableVisitor(AS3ParseController parseController) { |
| | 30 | super(parseController); |
| | 31 | symbolTableStack = new Stack<SymbolTable>(); |
| | 32 | topLevelSymbolTable = pushNewTable(Program.class); |
| | 33 | } |
| | 34 | |
| | 35 | public SymbolTable getTopLevelSymbolTable() { |
| | 36 | return topLevelSymbolTable; |
| | 37 | } |
| | 38 | |
| | 39 | public SymbolTable getEnclosingSymbolTable(IAst n) { |
| | 40 | if (topLevelSymbolTable != null) { |
| | 41 | return topLevelSymbolTable.getEnclosingSymbolTable(n); |
| | 42 | } |
| | 43 | return null; |
| 25 | 44 | } |
| 26 | 45 | |
| 27 | 46 | private SymbolTable pushNewTable(Class<?> clazz) { |
| 28 | | SymbolTable table = new SymbolTable(peekTable(), clazz); |
| 29 | | parser.symbolTableStack.push(table); |
| | 47 | SymbolTable table = new SymbolTable(peek(), clazz); |
| | 48 | symbolTableStack.push(table); |
| 30 | 49 | return table; |
| 31 | 50 | } |
| 32 | 51 | |
| 33 | | private SymbolTable peekTable() { |
| 34 | | return parser.symbolTableStack.peek(); |
| | 52 | private SymbolTable peek() { |
| | 53 | return symbolTableStack.isEmpty() ? null : symbolTableStack.peek(); |
| | 54 | } |
| | 55 | private SymbolTable pop() { |
| | 56 | return symbolTableStack.isEmpty() ? null : symbolTableStack.pop(); |
| 35 | 57 | } |
| 36 | 58 | |
| … |
… |
|
| 41 | 63 | |
| 42 | 64 | public void endVisit(Block n) { |
| 43 | | parser.symbolTableStack.pop(); |
| | 65 | pop(); |
| 44 | 66 | } |
| 45 | 67 | |
| … |
… |
|
| 54 | 76 | |
| 55 | 77 | public void endVisit(ClassDefinition n) { |
| 56 | | parser.symbolTableStack.pop(); |
| | 78 | pop(); |
| 57 | 79 | } |
| 58 | 80 | |
| … |
… |
|
| 64 | 86 | public boolean visit(FunctionDefinition n) { |
| 65 | 87 | IToken id = n.getName().getIToken(); |
| 66 | | SymbolTable symbol_table = peekTable(); |
| | 88 | SymbolTable symbol_table = peek(); |
| 67 | 89 | String name = id.toString(); |
| 68 | 90 | if (n.getAccessor() != null) { |
| … |
… |
|
| 87 | 109 | |
| 88 | 110 | public void endVisit(FunctionDefinition n) { |
| 89 | | parser.symbolTableStack.pop(); |
| | 111 | pop(); |
| 90 | 112 | } |
| 91 | 113 | |
| … |
… |
|
| 96 | 118 | |
| 97 | 119 | public void endVisit(FunctionExpression n) { |
| 98 | | parser.symbolTableStack.pop(); |
| | 120 | pop(); |
| 99 | 121 | } |
| 100 | 122 | |
| … |
… |
|
| 102 | 124 | public boolean visit(PlainParameter n) { |
| 103 | 125 | String name = n.getIdent().toString(); |
| 104 | | if (!peekTable().create(name, n)) emitError(n, "Illegal redeclaration of " + name); |
| 105 | | return true; |
| | 126 | if (!peek().create(name, n)) emitError(n, "Illegal redeclaration of " + name); |
| | 127 | return false; |
| 106 | 128 | } |
| 107 | 129 | |
| … |
… |
|
| 109 | 131 | public boolean visit(RestParameter n) { |
| 110 | 132 | String name = (n.getIdent()!= null) ? n.getIdent().toString() : n.getUntyped().toString(); |
| 111 | | if (!peekTable().create(name, n)) emitError(n, "Illegal redeclaration of " + name); |
| 112 | | return true; |
| | 133 | if (!peek().create(name, n)) emitError(n, "Illegal redeclaration of " + name); |
| | 134 | return false; |
| 113 | 135 | } |
| 114 | 136 | |
| 115 | 137 | @Override |
| 116 | 138 | public boolean visit(AssignmentExpression n) { |
| 117 | | return true; |
| | 139 | return false; |
| 118 | 140 | } |
| 119 | 141 | |
| 120 | 142 | @Override |
| 121 | 143 | public boolean visit(ExpressionStatement n) { |
| 122 | | return true; |
| | 144 | return false; |
| 123 | 145 | } |
| 124 | 146 | |
| … |
… |
|
| 126 | 148 | public boolean visit(VariableBinding n) { |
| 127 | 149 | IAst parent = n.getParent().getParent(); |
| 128 | | SymbolTable symbol_table = peekTable(); |
| | 150 | SymbolTable symbol_table = peek(); |
| 129 | 151 | String name = n.getIdent().toString(); |
| 130 | 152 | if (parent instanceof VariableDefinition) { |
| … |
… |
|
| 142 | 164 | } |
| 143 | 165 | if (!symbol_table.create(name, n)) emitError(n, "Illegal redeclaration of " + name); |
| 144 | | return true; |
| | 166 | return false; |
| 145 | 167 | } |
| 146 | 168 | } |
-
|
r49cbb50
|
r25b5d22
|
|
| 99 | 99 | .getRightIToken().getEndOffset()); |
| 100 | 100 | } else if (helpNode instanceof String) { |
| 101 | | msg = "id: "+ helpNode.toString()+"<br/>"; |
| 102 | 101 | AXIndexNode[] found = Index0r.getInstance().find(helpNode.toString()); |
| | 102 | msg = ""; |
| 103 | 103 | if (found.length > 0) { |
| 104 | | AXNode indexNode = found[0].getReference(); |
| | 104 | AXNode indexNode = found[0].getOrCreateReference(); |
| 105 | 105 | if (indexNode != null && indexNode.getAsdoc().size() > 0) { |
| 106 | 106 | msg += indexNode.getAsdoc().get(0); |
| 107 | 107 | } |
| 108 | 108 | } |
| | 109 | if (msg.length() == 0) msg = "no doc for id: "+ helpNode.toString(); |
| 109 | 110 | } else if (helpNode != null) { |
| 110 | 111 | msg = helpNode.toString(); |
| 111 | 112 | } |
| 112 | | // int maxMsgLen = 80; |
| 113 | 113 | if (msg == null || msg.length() == 0) return null; |
| 114 | | // else if (msg.length() <= maxMsgLen) return msg; |
| 115 | | // else return msg.subSequence(0, maxMsgLen) + "..."; |
| 116 | 114 | return msg; |
| 117 | 115 | } |
-
|
r49cbb50
|
r25b5d22
|
|
| 1 | 1 | package org.axdt.as3.imp.services; |
| 2 | 2 | |
| 3 | | import org.axdt.as3.imp.builders.AS3Builder; |
| | 3 | import java.util.ArrayList; |
| | 4 | |
| | 5 | import org.axdt.as3.util.AS3EditorHyperLink; |
| 4 | 6 | import org.axdt.axdoc.model.AXIndex; |
| 5 | 7 | import org.axdt.axdoc.model.AXIndexNode; |
| … |
… |
|
| 7 | 9 | import org.axdt.axdoc.util.Index0r; |
| 8 | 10 | import org.axdt.util.URIHyperLink; |
| | 11 | import org.eclipse.core.resources.IFile; |
| | 12 | import org.eclipse.core.resources.IResource; |
| 9 | 13 | import org.eclipse.core.resources.ResourcesPlugin; |
| 10 | 14 | import org.eclipse.core.runtime.IPath; |
| | 15 | import org.eclipse.emf.common.util.URI; |
| 11 | 16 | import org.eclipse.imp.editor.IRegionSelectionService; |
| 12 | 17 | import org.eclipse.imp.editor.TargetLink; |
| 13 | 18 | import org.eclipse.imp.language.ILanguageService; |
| 14 | | import org.eclipse.imp.language.ServiceFactory; |
| 15 | 19 | import org.eclipse.imp.parser.IParseController; |
| 16 | 20 | import org.eclipse.imp.parser.ISourcePositionLocator; |
| 17 | | import org.eclipse.imp.services.IReferenceResolver; |
| 18 | 21 | import org.eclipse.imp.services.ISourceHyperlinkDetector; |
| 19 | 22 | import org.eclipse.jface.text.IRegion; |
| … |
… |
|
| 26 | 29 | public class AS3HyperLinkDetector implements ISourceHyperlinkDetector, ILanguageService { |
| 27 | 30 | |
| 28 | | private IReferenceResolver fResolver; |
| | 31 | private AS3ReferenceResolver resolver; |
| 29 | 32 | public AS3HyperLinkDetector() { |
| | 33 | resolver = new AS3ReferenceResolver(); |
| 30 | 34 | } |
| 31 | 35 | public IHyperlink[] detectHyperlinks(IRegion region, ITextEditor editor, |
| 32 | 36 | ITextViewer textViewer, IParseController parseController) { |
| 33 | 37 | // This is the only language-specific bit ... |
| 34 | | if (fResolver == null) { |
| 35 | | fResolver = ServiceFactory.getInstance().getReferenceResolver(AS3Builder.LANGUAGE); |
| 36 | | } |
| 37 | | if (fResolver == null) return null; |
| 38 | 38 | if (parseController == null) return null; |
| 39 | 39 | |
| … |
… |
|
| 47 | 47 | Object source = nodeLocator.findNode(ast, offset); |
| 48 | 48 | if (source == null) return null; |
| | 49 | // Got a suitable link source node; get link target node |
| | 50 | Object target = resolver.getLinkTarget(source, parseController); |
| | 51 | if (target == null) return null; |
| | 52 | |
| | 53 | String linkText = resolver.getLinkText(source); |
| | 54 | int srcStart= nodeLocator.getStartOffset(source); |
| | 55 | int srcLength= nodeLocator.getEndOffset(source) - srcStart + 1; |
| 49 | 56 | |
| 50 | | // Got a suitable link source node; get link target node |
| 51 | | final Object target = fResolver.getLinkTarget(source, parseController); |
| 52 | | if (target == null) return null; |
| 53 | | |
| 54 | | // Link target node exists; get info for new hyperlink |
| 55 | | // Note: source presumably has a legitimate starting offset |
| 56 | | // and length (since they have been selected from the source file) |
| 57 | | final int srcStart= nodeLocator.getStartOffset(source); |
| 58 | | final int srcLength= nodeLocator.getEndOffset(source) - srcStart + 1; |
| 59 | | |
| 60 | | if (target instanceof String) { |
| | 57 | if (target instanceof String) { |
| 61 | 58 | AXIndexNode[] find = Index0r.getInstance().find(target.toString()); |
| 62 | | IHyperlink[] result = new IHyperlink[find.length]; |
| | 59 | ArrayList<IHyperlink> result = new ArrayList<IHyperlink>(); |
| 63 | 60 | Region srcRegion = new Region(srcStart,srcLength); |
| 64 | 61 | for (int i=0; i < find.length; i++) { |
| 65 | | String url = find[i].fullUrl(); |
| 66 | | if (find[i] instanceof AXIndex) url += AXDocParser.URL_PACKAGE_DETAIL; |
| 67 | | result[i] = new URIHyperLink(srcRegion, url); |
| | 62 | URI uri = URI.createURI(find[i].fullUrl()); |
| | 63 | if (uri.isPlatformResource()) { |
| | 64 | try { |
| | 65 | String platformString = uri.toPlatformString(true); |
| | 66 | IResource targetResource = ResourcesPlugin.getWorkspace().getRoot().findMember(platformString); |
| | 67 | if (targetResource instanceof IFile) { |
| | 68 | result.add(new AS3EditorHyperLink(linkText, srcRegion, (IFile)targetResource)); |
| | 69 | } |
| | 70 | } catch (Exception e) { |
| | 71 | e.printStackTrace(); |
| | 72 | } |
| | 73 | } else { |
| | 74 | if (find[i] instanceof AXIndex) { |
| | 75 | uri.appendSegment(AXDocParser.URL_PACKAGE_DETAIL); |
| | 76 | } |
| | 77 | result.add(new URIHyperLink(srcRegion, uri.toString())); |
| | 78 | } |
| 68 | 79 | } |
| 69 | | return result; |
| | 80 | return result.toArray(new IHyperlink[result.size()]); |
| 70 | 81 | } |
| 71 | 82 | // The target (depending on what--and where--the target is) may not have a |
| … |
… |
|
| 73 | 84 | // to the beginning of the file and give it a nominal length. |
| 74 | 85 | |
| 75 | | final int targetStart= (nodeLocator.getStartOffset(target) < 0) ? 0 : nodeLocator.getStartOffset(target); |
| 76 | | final int targetLength= nodeLocator.getEndOffset(target) - targetStart + 1; |
| | 86 | int targetStart= (nodeLocator.getStartOffset(target) < 0) ? 0 : nodeLocator.getStartOffset(target); |
| | 87 | int targetLength= nodeLocator.getEndOffset(target) - targetStart + 1; |
| 77 | 88 | |
| 78 | 89 | // Use the file path info to determine whether the target editor is the same as |
| 79 | 90 | // the source editor, and initialize the TargetLink accordingly. |
| 80 | | final IPath targetPath= nodeLocator.getPath(target); |
| | 91 | IPath targetPath= nodeLocator.getPath(target); |
| 81 | 92 | // SMS 10 Sep 2007 |
| 82 | 93 | if (targetPath == null) { |
| … |
… |
|
| 84 | 95 | return null; |
| 85 | 96 | } |
| 86 | | final String linkText = fResolver.getLinkText(source); |
| 87 | 97 | |
| 88 | 98 | IPath srcPath= ((IFileEditorInput) editor.getEditorInput()).getFile().getLocation(); |
| … |
… |
|
| 113 | 123 | return null; |
| 114 | 124 | |
| | 125 | |
| 115 | 126 | IRegionSelectionService selService= isSamePath ? (IRegionSelectionService) editor.getAdapter(IRegionSelectionService.class) : null; |
| 116 | 127 | |
-
|
r49cbb50
|
r25b5d22
|
|
| 3 | 3 | import lpg.runtime.IAst; |
| 4 | 4 | |
| | 5 | import org.axdt.as3.imp.parser.AS3ParseController; |
| 5 | 6 | import org.axdt.as3.imp.parser.AS3Parser; |
| 6 | 7 | import org.axdt.as3.imp.parser.SymbolTable; |
| … |
… |
|
| 59 | 60 | |
| 60 | 61 | private Object lookInSymbolTable(IParseController controller, IAst node, String stringId) { |
| 61 | | AS3Parser parser = (AS3Parser) ((SimpleLPGParseController) controller).getParser(); |
| 62 | | SymbolTable symtab = parser.getEnclosingSymbolTable(node); |
| | 62 | SymbolTable symtab = ((AS3ParseController) controller).getEnclosingSymbolTable(node); |
| 63 | 63 | return symtab.findDeclaration(stringId); |
| 64 | 64 | } |
-
|
r2d81bf0
|
r25b5d22
|
|
| 20 | 20 | import org.axdt.axdoc.model.AXPackage; |
| 21 | 21 | import org.axdt.axdoc.model.AXRoot; |
| | 22 | import org.axdt.axdoc.model.AXRootType; |
| 22 | 23 | import org.axdt.axdoc.model.AXType; |
| 23 | 24 | import org.eclipse.emf.common.notify.Notification; |
| … |
… |
|
| 401 | 402 | String url = name; |
| 402 | 403 | AXIndexNode parent = getParent(); |
| 403 | | if (getType().isType()) { |
| | 404 | if (getRoot() != null && AXRootType.SOURCE.equals(getRoot().getRootType())) { |
| | 405 | url += ".as"; |
| | 406 | } else if (getType().isType()) { |
| 404 | 407 | url += ".html"; |
| 405 | 408 | } else if (getType().isMember()) { |