use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.
the class AbstractTab method updateErrors.
/**
* Don't recommend to start projects which have errors.
* TODO: manipulating the error message here does not cooperate well with isValid().
*/
protected boolean updateErrors() {
boolean res = true;
String projectName = getSelectedProjectName();
String prod = getSelectedProductName();
if (this.lastProjectName != null && this.lastProd != null && this.lastProjectName.equals(projectName) && this.lastProd.equals(prod)) {
// every time something changes in the run configuration dialog
return lastResult;
}
if (projectName != null) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
try {
AbsNature nat = UtilityFunctions.getAbsNature(project);
assert nat != null;
synchronized (nat.modelLock) {
Model model = nat.getCompleteModel();
/* E.g. errors in the project */
if (model == null)
return false;
/* Check product if any */
// work on a copy:
model = model.treeCopyNoTransform();
model.flushTreeCache();
if (prod != null) {
model.flattenForProduct(prod);
/* Type check again */
// #335, see IncrementalModelBuilder#flushAll()
model.flushCache();
}
SemanticConditionList errs = model.getErrors();
// TODO: check for warnings also
if (errs != null && errs.containsErrors()) {
createMarkers(nat, errs);
throw new AbsJobException(new TypeCheckerException(errs));
}
errs = model.typeCheck();
// TODO: check for warnings also
if (errs != null && errs.containsErrors()) {
createMarkers(nat, errs);
throw new AbsJobException(new TypeCheckerException(errs));
}
}
setErrorMessage(null);
} catch (AbsJobException e) {
setErrorMessage(e.getMessage());
res = false;
} catch (WrongProgramArgumentException e) {
setErrorMessage(e.getMessage());
res = false;
} catch (DeltaModellingException e) {
setErrorMessage(e.getMessage());
res = false;
}
getLaunchConfigurationDialog().updateMessage();
}
// cache the result
lastProd = prod;
lastProjectName = projectName;
lastResult = res;
return res;
}
use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.
the class ProjectAddLocationHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getActiveMenuSelection(event);
Object firstElement = selection.getFirstElement();
if (firstElement instanceof IProject) {
IProject project = (IProject) firstElement;
AbsNature nature = UtilityFunctions.getAbsNature(project);
if (nature == null)
return null;
IPersistentPreferenceStore projectStore = nature.getProjectPreferenceStore();
boolean locationTypecheckingEnabled = projectStore.getBoolean(Constants.LOCATION_TYPECHECK);
if (!locationTypecheckingEnabled) {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Locationtypechecking", "Location type checking is disabled. Please enable for this function to work!");
return null;
}
UtilityFunctions.saveEditors(project, false);
Map<LocationTypeVariable, LocationType> locationTypeInferrerResult = nature.getLocationTypeInferrerResult();
if (locationTypeInferrerResult != null) {
InferMain inferMain = new InferMain();
String commandId = event.getCommand().getId();
if ("org.abs-models.abs.plugin.projectaddalllocations".equals(commandId)) {
inferMain.setConfig(InferMain.Config.values());
} else if ("org.abs-models.abs.plugin.projectaddclasslocations".equals(commandId)) {
inferMain.setConfig(InferMain.Config.CLASSES);
} else if ("org.abs-models.abs.plugin.projectaddfieldlocations".equals(commandId)) {
inferMain.setConfig(InferMain.Config.FIELDS);
} else if ("org.abs-models.abs.plugin.projectaddfunctionlocations".equals(commandId)) {
inferMain.setConfig(InferMain.Config.FUNCTIONS);
} else if ("org.abs-models.abs.plugin.projectaddinterfacelocations".equals(commandId)) {
inferMain.setConfig(InferMain.Config.INTERFACES);
}
try {
inferMain.writeInferenceResultsBack(locationTypeInferrerResult);
try {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
}
} catch (IOException e) {
MessageDialog.openError(Display.getDefault().getActiveShell(), "Error while inserting locations", "An error occurred while inserting locations!\n" + e.getLocalizedMessage());
}
}
}
return null;
}
use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.
the class JavaTabMain method getRunTargets.
private List<RunTarget> getRunTargets(IProject proj) {
AbsNature n = UtilityFunctions.getAbsNature(proj);
if (n == null) {
return Collections.emptyList();
}
Model m = n.getCompleteModel();
if (m == null) {
return Collections.emptyList();
}
List<RunTarget> result = new ArrayList<RunTarget>();
for (CompilationUnit cu : m.getCompilationUnits()) {
for (ModuleDecl module : cu.getModuleDecls()) {
if (module.getBlockOpt().hasChildren()) {
if (module.getName().equals(ABSTestRunnerGenerator.RUNNER_MAIN)) {
// do not show generated unit test file
continue;
}
result.add(new RunTargetModule(module));
}
// TODO add unit test classes
// for (Decl d : module.getDecls()) {
// if (d.isInterface()) {
// InterfaceDecl i = (InterfaceDecl) d;
// for (Annotation annotation : i.getAnnotations()) {
// if (annotation.getValue() )
// }
// }
// }
}
}
result.add(new RunTargetUnitTests());
return result;
}
use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.
the class ABSCodeScanner method evalAST.
/**
* Takes the AST-node for the current identifier, resolves uses (like e.g. type use) and
* matches against the semantic rules
* @return null, if the document could not be parsed, else the token of the matching semantic rule
* or {@link Token#UNDEFINED} if no rule matched.
*/
private IToken evalAST() {
if (compilationUnit == null) {
return null;
}
IToken token = Token.UNDEFINED;
try {
AbsNature nature = fEditor.getAbsNature();
if (nature == null)
return token;
synchronized (nature.modelLock) {
final ASTNode<?> currentNode = getASTNodeOfOffset(fDocument, compilationUnit, fTokenOffset);
Model typecheckedModel = nature.getCompleteModel();
if (typecheckedModel == null)
return null;
Class<?> semClass = null;
ASTNode<?> declNode = null;
if (currentNode instanceof TypeUse) {
TypeUse tu = (TypeUse) currentNode;
declNode = resolveTypeUse(tu, typecheckedModel);
}
if (currentNode instanceof VarOrFieldUse) {
VarOrFieldUse vofu = (VarOrFieldUse) currentNode;
declNode = vofu.getDecl();
if (declNode != null && declNode.getContextMethod() == null) {
semClass = FieldDecl.class;
}
}
if (currentNode instanceof FnApp || currentNode instanceof DataConstructorExp) {
semClass = currentNode.getClass();
}
if (semClass == null) {
if (declNode != null) {
semClass = declNode.getClass();
}
}
if (semClass != null) {
Iterator<SemanticRule> iter = semanticrules.iterator();
// iterate over rules and try to match
while (iter.hasNext()) {
SemanticRule rule = iter.next();
if (rule.getSemclass().isAssignableFrom(semClass)) {
token = rule.getToken();
break;
}
}
}
}
} catch (BadLocationException e) {
if (doDebug)
e.printStackTrace();
}
return token;
}
use of org.absmodels.abs.plugin.builder.AbsNature in project abstools by abstools.
the class ABSEditor method initCompilationUnit.
private void initCompilationUnit() {
AbsNature absNature = UtilityFunctions.getAbsNature(getResource());
if (absNature != null) {
AbsModelManager modelManager = absNature.getModelManager();
compilationUnit = modelManager.getCompilationUnit(getAbsoluteFilePath());
} else {
// we are looking at abslang.abs or a file inside a jar-package
IURIEditorInput uriInput = (IURIEditorInput) getEditorInput().getAdapter(IURIEditorInput.class);
if (uriInput != null) {
// We're looking e.g. at abslang.abs which only exists in memory.
// create an empty model which only contains abslang.abs:
absNature = new AbsNature();
absNature.emptyModel();
File f = new File(uriInput.getURI());
String path = f.getAbsolutePath();
compilationUnit = absNature.getCompilationUnit(path);
}
}
}
Aggregations