use of abs.frontend.ast.ModuleDecl in project abstools by abstools.
the class ModulePath method getModulesForPrefix.
/**
* Collects ModuleDecls with a given prefix. Only ModuleDecls with a name
* prefix.Name are returned, ModuleDecls with a name prefix.subPrefix.Name
* are ignored.
*
* prefix is the current module path of this instance.
*
* @return Only ModuleDecls with a name prefix.Name are returned,
* ModuleDecls with a name prefix.subPrefix.Name are ignored
*/
public Set<InternalASTNode<ModuleDecl>> getModulesForPrefix() {
LinkedHashSet<InternalASTNode<ModuleDecl>> names = new LinkedHashSet<InternalASTNode<ModuleDecl>>();
Model model = absNature.getCompleteModel();
if ("".equals(modulePath)) {
for (ModuleDecl m : model.getModuleDecls()) {
String name = m.getName();
if (!name.equals(STDLIB_NAME)) {
if (name.indexOf('.') < 0 && !hasSubModule(name) && !name.equals(modulePath) && !names.contains(m)) {
// FIXME: Review, can a ModuleDecl really be inside Set<nternalASTNode<..>>? GC_UNRELATED_TYPES
names.add(new InternalASTNode<ModuleDecl>(m, absNature));
}
}
}
return names;
} else {
for (ModuleDecl m : model.getModuleDecls()) {
String name = m.getName();
if (!name.equals(STDLIB_NAME)) {
String regex = NavigatorUtils.buildRegex(modulePath);
if ((name.matches(regex) && !existsSubLayer(name)) && !hasSubModule(name)) {
names.add(new InternalASTNode<ModuleDecl>(m, absNature));
}
}
}
return names;
}
}
use of abs.frontend.ast.ModuleDecl in project abstools by abstools.
the class WizardUtil method validateInterface.
/**
* Same as {@link #validate(String)} but additionally checks, whether the specified
* interface name already exists in the given module declaration
*
* @param text
* Name to be checked.
* @param decl
* Target ModuleDecl.
* @return In case of a duplicate name, this method returns
* ErrorType.ERROR_NO_DUPLICATE_NAME with the duplicate name set in
* its information string.
*/
public static ErrorType validateInterface(String text, ModuleDecl decl) {
if (decl != null) {
for (Decl d : decl.getDecls()) {
if (d instanceof InterfaceDecl && d.getName().equals(text)) {
ErrorType type = ErrorType.ERROR_DUPLICATE_NAME;
type.setInformationString(text);
return type;
}
}
}
return validate(text);
}
use of abs.frontend.ast.ModuleDecl in project abstools by abstools.
the class WizardUtil method validateClass.
/**
* Same as {@link #validate(String)} but additionally checks, whether the specified
* class name already exists in the given module declaration
*
* @param text
* Name to be checked.
* @param decl
* Target ModuleDecl.
* @return In case of a duplicate name, this method returns
* ErrorType.ERROR_NO_DUPLICATE_NAME with the duplicate name set in
* its information string.
*/
public static ErrorType validateClass(String text, ModuleDecl decl) {
if (decl != null) {
for (Decl d : decl.getDecls()) {
if (d instanceof ClassDecl && d.getName().equals(text)) {
ErrorType type = ErrorType.ERROR_DUPLICATE_NAME;
type.setInformationString(text);
return type;
}
}
}
return validate(text);
}
use of abs.frontend.ast.ModuleDecl in project abstools by abstools.
the class ModuleGroupContentProvider method getChildrenOf.
/**
* Returns the children of a project.
*
* @param project
* @return The children of the Project or an empty object array if the
* project is closed or not an ABS project or an Exception occurs
*/
private Object[] getChildrenOf(IProject project) {
try {
if (project.isAccessible() && project.hasNature(Constants.NATURE_ID)) {
AbsNature nature = UtilityFunctions.getAbsNature(project);
if (nature != null) {
synchronized (nature.modelLock) {
ArrayList<InternalASTNode<?>> decls = new ArrayList<InternalASTNode<?>>();
Model model = nature.getCompleteModel();
// something could be compiled in the project (i.e. the project is not empty...)
if (model != null) {
Collection<ModuleDecl> moduleDecls = model.getModuleDecls();
for (ModuleDecl m : moduleDecls) {
String name = m.getName();
/* Don't show internal resources which would be read-only anyway.
* This is either the standard lib, or e.g. ABS.FLI, ABS.DC */
if (name.startsWith("ABS.")) {
continue;
}
decls.add(new InternalASTNode<ModuleDecl>(m, nature));
}
}
return decls.toArray();
}
}
}
} catch (CoreException ce) {
ce.printStackTrace();
return EMPTY_OBJECT_ARRAY;
}
return EMPTY_OBJECT_ARRAY;
}
use of abs.frontend.ast.ModuleDecl in project abstools by abstools.
the class WizardUtilsTests method testValidateInterface.
@Test
public void testValidateInterface() {
ModuleDecl mockDecl = mock(ModuleDecl.class);
List<Decl> list = new List<Decl>();
InterfaceDecl m1 = mock(InterfaceDecl.class);
InterfaceDecl m2 = mock(InterfaceDecl.class);
when(m1.getName()).thenReturn("Interface1");
when(m2.getName()).thenReturn("Interface2");
list.add(m1);
list.add(m2);
when(mockDecl.getDecls()).thenReturn(list);
String valid1 = "A";
String valid2 = "Abc3";
String valid3 = "ABC3";
String invalid1 = "";
String invalid2 = "a";
String invalid3 = "a.b";
String invalid4 = ";";
String invalid5 = "module";
String invalid6 = "Interface1";
String invalid7 = "Interface2";
assertTrue(validateInterface(valid1, mockDecl).equals(ErrorType.NO_ERROR));
assertTrue(validateInterface(valid2, mockDecl).equals(ErrorType.NO_ERROR));
assertTrue(validateInterface(valid3, mockDecl).equals(ErrorType.NO_ERROR));
assertTrue(validateInterface(invalid1, mockDecl).equals(ErrorType.ERROR_NO_NAME));
assertTrue(validateInterface(invalid2, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
assertTrue(validateInterface(invalid3, mockDecl).equals(ErrorType.ERROR_NO_UPPER_CASE));
assertTrue(validateInterface(invalid4, mockDecl).equals(ErrorType.ERROR_INVALID_NAME));
assertTrue(validateInterface(invalid5, mockDecl).equals(ErrorType.ERROR_KEYWORD));
assertTrue(validateInterface(invalid6, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
assertTrue(validateInterface(invalid7, mockDecl).equals(ErrorType.ERROR_DUPLICATE_NAME));
}
Aggregations