Package dtool.ast.util

Source Code of dtool.ast.util.NamedElementUtil

package dtool.ast.util;

import static melnorme.utilbox.core.Assert.AssertNamespace.assertNotNull;
import dtool.ast.definitions.EArcheType;
import dtool.ast.definitions.INamedElement;

public class NamedElementUtil {
 
  /**
   * Return a name identifying this defUnit in the projects source code.
   * It's similar to a fully qualified name, but has some more information on the name about
   * the containing defunits.
   * (the name is not enough to uniquely locate a defUnit in a project. That's the goal anyways)
   */
  public static String getElementTypedQualification(INamedElement namedElement) {
    switch(namedElement.getArcheType()) {
    case Package:
      return namedElement.getFullyQualifiedName() + "/";
    default:
    }
    return getElementTypeQualificationBase(namedElement);
  }
 
  public static String getElementTypeQualificationBase(INamedElement namedElement) {
    if(namedElement.getArcheType() == EArcheType.Module) {
      return namedElement.getModuleFullyQualifiedName() + "/";
    }
   
    if(namedElement.isLanguageIntrinsic()) {
      return NATIVES_ROOT + namedElement.getName();
    }
   
    INamedElement parentNamespace = namedElement.getParentElement();
    assertNotNull(parentNamespace);
    String sep = parentNamespace.getArcheType() == EArcheType.Module  ? "" : ".";
    String parentQualifedName = getElementTypeQualificationBase(parentNamespace);
    String qualification = parentQualifedName + sep;
    return qualification + namedElement.getName();
  }
 
  public static String NATIVES_ROOT = "/";
 
}
TOP

Related Classes of dtool.ast.util.NamedElementUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.