blob: ef9a6a1bff8aa5bd68cea93ed445623ca31ddd46 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2012 NumberFour AG
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* NumberFour AG - initial API and Implementation (Alex Panchenko)
*******************************************************************************/
package org.eclipse.dltk.javascript.internal.search;
import org.eclipse.dltk.ast.ASTNode;
import org.eclipse.dltk.javascript.ast.Identifier;
import org.eclipse.dltk.javascript.ast.PropertyExpression;
import org.eclipse.dltk.javascript.core.JSBindings;
import org.eclipse.dltk.javascript.typeinference.IValueReference;
import org.eclipse.dltk.javascript.typeinference.ReferenceKind;
import org.eclipse.dltk.javascript.typeinference.ReferenceLocation;
public abstract class MemberReferenceNode extends
AbstractMatchingNode<Identifier> {
ReferenceLocation location;
ReferenceKind kind;
public MemberReferenceNode(Identifier node, ReferenceLocation location,
ReferenceKind kind) {
super(node);
this.location = location;
this.kind = kind;
}
public MemberReferenceNode(Identifier node) {
this(node, null, null);
}
@Override
public boolean needsResolve() {
return location == null;
}
@Override
public MatchingNode resolvePotentialMatch(JSBindings bindings) {
if (location == null) {
final IValueReference reference = bindings.get(node);
if (reference != null) {
final ReferenceLocation l = reference.getLocation();
if (l != ReferenceLocation.UNKNOWN) {
location = l;
kind = reference.getKind();
}
} else {
final ASTNode parent = node.getParent();
if (parent instanceof PropertyExpression
&& ((PropertyExpression) parent).getProperty() == node) {
final IValueReference parentReference = bindings
.get(parent);
if (parentReference != null) {
final ReferenceLocation l = parentReference
.getLocation();
if (l != ReferenceLocation.UNKNOWN) {
location = l;
kind = parentReference.getKind();
}
}
}
}
}
return this;
}
}