| /******************************************************************************* |
| * Copyright (c) 2005, 2016 IBM Corporation and others. |
| * 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 |
| * |
| *******************************************************************************/ |
| package org.eclipse.dltk.ti; |
| |
| import org.eclipse.dltk.ast.declarations.ModuleDeclaration; |
| import org.eclipse.dltk.core.DLTKLanguageManager; |
| import org.eclipse.dltk.core.IDLTKLanguageToolkit; |
| import org.eclipse.dltk.core.ISourceModule; |
| |
| public class BasicContext implements IContext, ISourceModuleContext { |
| |
| private final ISourceModule sourceModule; |
| private final ModuleDeclaration rootNode; |
| |
| public BasicContext(ISourceModule sourceModule, ModuleDeclaration rootNode) { |
| this.sourceModule = sourceModule; |
| this.rootNode = rootNode; |
| } |
| |
| public BasicContext(ISourceModuleContext parent) { |
| sourceModule = parent.getSourceModule(); |
| rootNode = parent.getRootNode(); |
| } |
| |
| @Override |
| public ModuleDeclaration getRootNode() { |
| return rootNode; |
| } |
| |
| @Override |
| public ISourceModule getSourceModule() { |
| return sourceModule; |
| } |
| |
| @Override |
| public String getLangNature() { |
| if (sourceModule != null) { |
| IDLTKLanguageToolkit languageToolkit = DLTKLanguageManager |
| .getLanguageToolkit(sourceModule); |
| if (languageToolkit != null) { |
| return languageToolkit.getNatureId(); |
| } |
| } |
| return null; |
| } |
| |
| @Override |
| public String toString() { |
| return "BasicContext, module " + sourceModule.getElementName(); //$NON-NLS-1$ |
| } |
| |
| @Override |
| public int hashCode() { |
| final int prime = 31; |
| int result = 1; |
| result = prime * result |
| + ((sourceModule == null) ? 0 : sourceModule.hashCode()); |
| return result; |
| } |
| |
| @Override |
| public boolean equals(Object obj) { |
| if (this == obj) |
| return true; |
| if (obj == null) |
| return false; |
| if (getClass() != obj.getClass()) |
| return false; |
| BasicContext other = (BasicContext) obj; |
| if (sourceModule == null) { |
| if (other.sourceModule != null) |
| return false; |
| } else if (!sourceModule.equals(other.sourceModule)) |
| return false; |
| return true; |
| } |
| } |