Skip to content

Commit b921bef

Browse files
committed
structure (SourceElementParser) reimplemented based on AST
1 parent e8bc7d8 commit b921bef

File tree

60 files changed

+2225
-1094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2225
-1094
lines changed

plugins/org.eclipse.dltk.javascript.core/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ Require-Bundle: org.eclipse.core.runtime,
1515
org.eclipse.emf.ecore.xmi
1616
Bundle-Activator: org.eclipse.dltk.javascript.core.JavaScriptPlugin
1717
Export-Package: org.eclipse.dltk.internal.javascript.parser,
18-
org.eclipse.dltk.internal.javascript.parser.structure,
18+
org.eclipse.dltk.internal.javascript.parser.structure;x-internal:=true,
1919
org.eclipse.dltk.internal.javascript.ti;x-internal:=true,
2020
org.eclipse.dltk.internal.javascript.typeinference,
2121
org.eclipse.dltk.internal.javascript.validation;x-internal:=true,
2222
org.eclipse.dltk.javascript.core,
2323
org.eclipse.dltk.javascript.internal.core.codeassist;x-internal:=true,
24+
org.eclipse.dltk.javascript.structure,
2425
org.eclipse.dltk.javascript.typeinference,
2526
org.eclipse.dltk.javascript.typeinfo,
2627
org.eclipse.dltk.javascript.typeinfo.model,

plugins/org.eclipse.dltk.javascript.core/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<extension
4242
point="org.eclipse.dltk.core.sourceElementParsers">
4343
<parser
44-
class="org.eclipse.dltk.internal.javascript.parser.JavaScriptSourceElementParser2"
44+
class="org.eclipse.dltk.internal.javascript.parser.structure.JavaScriptSourceElementParser3"
4545
nature="org.eclipse.dltk.javascript.core.nature"
4646
priority="0">
4747
</parser>

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/parser/structure/Declaration.java

Lines changed: 0 additions & 61 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012 NumberFour AG
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* NumberFour AG - initial API and Implementation (Alex Panchenko)
11+
*******************************************************************************/
12+
package org.eclipse.dltk.internal.javascript.parser.structure;
13+
14+
import org.eclipse.dltk.javascript.ast.Identifier;
15+
import org.eclipse.dltk.javascript.structure.IDeclaration;
16+
import org.eclipse.dltk.javascript.structure.IParentNode;
17+
import org.eclipse.dltk.javascript.structure.IStructureContext;
18+
import org.eclipse.dltk.javascript.structure.IStructureNode;
19+
import org.eclipse.dltk.javascript.structure.IStructureRequestor;
20+
import org.eclipse.dltk.javascript.structure.ObjectDeclaration;
21+
import org.eclipse.dltk.javascript.structure.StructureNode;
22+
23+
public class ExpressionNode extends StructureNode implements IParentNode {
24+
25+
public ExpressionNode(IParentNode parent) {
26+
super(parent);
27+
}
28+
29+
public int start() {
30+
// TODO Auto-generated method stub
31+
return 0;
32+
}
33+
34+
public void reportStructure(IStructureRequestor requestor,
35+
IStructureContext context) {
36+
}
37+
38+
public void addLocalReference(Identifier node, IDeclaration resolved) {
39+
parent.addLocalReference(node, resolved);
40+
}
41+
42+
public void addMethodReference(Identifier identifier, int argCount) {
43+
parent.addMethodReference(identifier, argCount);
44+
}
45+
46+
public void addFieldReference(Identifier identifier) {
47+
parent.addFieldReference(identifier);
48+
}
49+
50+
public void addToScope(IStructureNode child) {
51+
if (child instanceof ObjectDeclaration) {
52+
return;
53+
}
54+
parent.addToScope(child);
55+
}
56+
}

plugins/org.eclipse.dltk.javascript.core/src/org/eclipse/dltk/internal/javascript/parser/structure/FieldDeclaration.java

Lines changed: 0 additions & 46 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012 NumberFour AG
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* NumberFour AG - initial API and Implementation (Alex Panchenko)
11+
*******************************************************************************/
12+
package org.eclipse.dltk.internal.javascript.parser.structure;
13+
14+
import java.util.Collections;
15+
import java.util.List;
16+
17+
import org.eclipse.dltk.compiler.IElementRequestor.FieldInfo;
18+
import org.eclipse.dltk.javascript.ast.Expression;
19+
import org.eclipse.dltk.javascript.structure.IDeclaration;
20+
import org.eclipse.dltk.javascript.structure.IParentNode;
21+
import org.eclipse.dltk.javascript.structure.IStructureContext;
22+
import org.eclipse.dltk.javascript.structure.IStructureNode;
23+
import org.eclipse.dltk.javascript.structure.IStructureRequestor;
24+
import org.eclipse.dltk.javascript.structure.ParentNode;
25+
import org.eclipse.dltk.javascript.typeinference.ReferenceLocation;
26+
import org.eclipse.dltk.javascript.typeinfo.model.JSType;
27+
28+
public class FieldNode extends ParentNode implements IDeclaration {
29+
30+
private final Expression node;
31+
private final String name;
32+
private final ReferenceLocation location;
33+
private IStructureNode value;
34+
35+
public FieldNode(IParentNode parent, Expression node, String name,
36+
ReferenceLocation location) {
37+
super(parent);
38+
this.node = node;
39+
this.name = name;
40+
this.location = location;
41+
}
42+
43+
public String getName() {
44+
return name;
45+
}
46+
47+
public JSType getType() {
48+
return null;
49+
}
50+
51+
public ReferenceLocation getLocation() {
52+
return location;
53+
}
54+
55+
public int start() {
56+
return getLocation().getDeclarationStart();
57+
}
58+
59+
public IStructureNode getValue() {
60+
return value;
61+
}
62+
63+
public void setValue(IStructureNode value) {
64+
this.value = value;
65+
}
66+
67+
@Override
68+
public List<IStructureNode> getChildren() {
69+
return value != null ? Collections.singletonList(value) : Collections
70+
.<IStructureNode> emptyList();
71+
}
72+
73+
@Override
74+
public String toString() {
75+
final StringBuilder sb = new StringBuilder();
76+
sb.append("this.");
77+
sb.append(getName());
78+
sb.append(":field");
79+
if (value != null) {
80+
sb.append("=");
81+
sb.append(value);
82+
}
83+
return sb.toString();
84+
}
85+
86+
public void reportStructure(IStructureRequestor requestor,
87+
IStructureContext context) {
88+
final FieldInfo info = new FieldInfo();
89+
info.declarationStart = location.getDeclarationStart();
90+
info.name = getName();
91+
info.nameSourceStart = location.getNameStart();
92+
info.nameSourceEnd = location.getNameEnd() - 1;
93+
// info.type = typeToModel(variable.getType());
94+
// if (variable.isDeprecated()) {
95+
// info.modifiers |= JSModifiers.DEPRECATED;
96+
// }
97+
requestor.enterField(info, node, null, true);
98+
reportChildrenStructure(requestor, context);
99+
requestor.exitField(location.getDeclarationEnd() - 1);
100+
}
101+
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2012 NumberFour AG
3+
*
4+
* All rights reserved. This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License v1.0
6+
* which accompanies this distribution, and is available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* NumberFour AG - initial API and Implementation (Alex Panchenko)
11+
*******************************************************************************/
12+
package org.eclipse.dltk.internal.javascript.parser.structure;
13+
14+
import org.eclipse.dltk.core.ISourceNode;
15+
import org.eclipse.dltk.javascript.ast.Expression;
16+
import org.eclipse.dltk.javascript.ast.FunctionStatement;
17+
import org.eclipse.dltk.javascript.structure.FunctionDeclaration;
18+
import org.eclipse.dltk.javascript.structure.IParentNode;
19+
import org.eclipse.dltk.javascript.typeinfo.IModelBuilder.IMethod;
20+
21+
class FunctionDeclarationExpressionLike extends FunctionDeclaration {
22+
23+
private final String name;
24+
private final ISourceNode nameNode;
25+
26+
public FunctionDeclarationExpressionLike(IParentNode parent,
27+
FunctionStatement function, IMethod method, String name,
28+
ISourceNode nameNode) {
29+
super(parent, function, method);
30+
this.name = name;
31+
this.nameNode = nameNode;
32+
}
33+
34+
@Override
35+
public String getName() {
36+
return name;
37+
}
38+
39+
@Override
40+
public ISourceNode getNameNode() {
41+
return nameNode;
42+
}
43+
44+
@Override
45+
protected Expression getStructureNameNode() {
46+
if (nameNode instanceof Expression) {
47+
return (Expression) nameNode;
48+
}
49+
return super.getStructureNameNode();
50+
}
51+
52+
}

0 commit comments

Comments
 (0)