use of org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule in project titan.EclipsePlug-ins by eclipse.
the class MissingFriend method process.
@Override
public void process(final IVisitableNode node, final Problems problems) {
if (node instanceof FriendModule) {
final FriendModule s = (FriendModule) node;
final Identifier identifier = s.getIdentifier();
final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(s.getProject());
if (parser != null && identifier != null) {
final Module referredModule = parser.getModuleByName(identifier.getName());
if (referredModule == null) {
final String msg = MessageFormat.format(MISSING_MODULE, identifier.getDisplayName());
problems.report(identifier.getLocation(), msg);
}
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule in project titan.EclipsePlug-ins by eclipse.
the class DependencyCollector method filterFriendDefinitions.
/**
* Returns the <code>friendDefs</code> list, with the {@link FriendModule}s removed which refer to
* modules that are not contained in the <code>allFiles</code> set.
*/
private static void filterFriendDefinitions(final Set<IResource> allFiles, final List<FriendModule> friendDefs, final ProjectSourceParser projParser) {
final List<Identifier> allFileIds = new ArrayList<Identifier>(allFiles.size());
for (IResource r : allFiles) {
if (!(r instanceof IFile)) {
continue;
}
final IFile f = (IFile) r;
final Module m = projParser.containedModule(f);
allFileIds.add(m.getIdentifier());
}
final ListIterator<FriendModule> importIt = friendDefs.listIterator();
while (importIt.hasNext()) {
final FriendModule fm = importIt.next();
final Identifier id = fm.getIdentifier();
if (!allFileIds.contains(id)) {
importIt.remove();
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule in project titan.EclipsePlug-ins by eclipse.
the class DependencyCollector method reportOverlappingError.
private void reportOverlappingError(final ILocateableNode defCurrent, final ILocateableNode defOverlapping) {
final Location dLocOverlap = defOverlapping == null ? null : defOverlapping.getLocation();
final Location dLocCurr = defCurrent == null ? null : defCurrent.getLocation();
String idOverlap = null;
if (defOverlapping instanceof Definition) {
idOverlap = ((Definition) defOverlapping).getIdentifier().toString();
} else if (defOverlapping instanceof ImportModule) {
idOverlap = "ImportModule{" + ((ImportModule) defOverlapping).getIdentifier().toString() + "}";
} else if (defOverlapping instanceof FriendModule) {
idOverlap = "FriendModule{" + ((FriendModule) defOverlapping).getIdentifier().toString() + "}";
}
String idCurr = null;
if (defCurrent instanceof Definition) {
idCurr = ((Definition) defCurrent).getIdentifier().toString();
} else if (defCurrent instanceof ImportModule) {
idCurr = "ImportModule{" + ((ImportModule) defCurrent).getIdentifier().toString() + "}";
} else if (defCurrent instanceof FriendModule) {
idCurr = "FriendModule{" + ((FriendModule) defCurrent).getIdentifier().toString() + "}";
}
final String msg1 = (dLocCurr == null) ? "null" : "Definition id: " + idCurr + " (" + defCurrent.getClass().getSimpleName() + ") at " + dLocCurr.getFile() + ", offset " + dLocCurr.getOffset() + "-" + dLocCurr.getEndOffset();
final String msg2 = (dLocOverlap == null) ? "null" : "Definition id: " + idOverlap + " (" + defOverlapping.getClass().getSimpleName() + ") at " + dLocOverlap.getFile() + ", offset " + dLocOverlap.getOffset() + "-" + dLocOverlap.getEndOffset();
ErrorReporter.logError("Warning! Locations overlap while reading source project: \n" + msg1 + "\n WITH \n" + msg2);
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule in project titan.EclipsePlug-ins by eclipse.
the class DependencyCollector method readDependencies.
public WorkspaceJob readDependencies() {
final WorkspaceJob job = new WorkspaceJob("ExtractModulePar: reading dependencies from source project") {
@Override
public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(sourceProj);
// find all dependencies of the 'selection' definition
Set<IResource> allFiles = new HashSet<IResource>();
Set<IResource> asnFiles = new HashSet<IResource>();
NavigableSet<ILocateableNode> dependencies = new TreeSet<ILocateableNode>(new LocationComparator());
for (Def_ModulePar def : selection) {
/*
* Def_ModulePars with mutliple entries in a single modulepar block have incorrect location info
* (all entries have a location info equal to the location of their parent block)
* that is why the dependencies must be collected into a set that is not sorted by location
*
* TODO fix grammar definitions
* */
Set<ILocateableNode> nonSortedTempSet = new HashSet<ILocateableNode>();
collectDependencies(def, nonSortedTempSet, allFiles, asnFiles);
dependencies.addAll(nonSortedTempSet);
allFiles.add(def.getLocation().getFile());
// adding the selection itself to the dependencies
if (!dependencies.contains(def)) {
dependencies.add(def);
}
// get imports and friends for all files
for (IResource r : allFiles) {
if (!(r instanceof IFile)) {
continue;
}
IFile f = (IFile) r;
Module m = projectSourceParser.containedModule(f);
ImportFinderVisitor impVisitor = new ImportFinderVisitor();
m.accept(impVisitor);
List<ImportModule> impDefs = impVisitor.getImportDefs();
List<FriendModule> friendDefs = impVisitor.getFriendDefs();
filterImportDefinitions(allFiles, impDefs, projectSourceParser);
filterFriendDefinitions(allFiles, friendDefs, projectSourceParser);
dependencies.addAll(impDefs);
dependencies.addAll(friendDefs);
// the dependencies are sorted by file & location to avoid reading through a file multiple times
}
}
// collect the text to insert into the new project
copyMap = new HashMap<IPath, StringBuilder>();
try {
InputStream is = null;
InputStreamReader isr = null;
IResource lastFile = null;
IResource currFile;
ILocateableNode lastD = null;
int currOffset = 0;
for (ILocateableNode d : dependencies) {
currFile = d.getLocation().getFile();
if (!(currFile instanceof IFile)) {
ErrorReporter.logError("ExtractModulePar/DependencyCollector: IResource `" + currFile.getName() + "' is not an IFile.");
continue;
}
if (currFile != lastFile) {
// started reading new file
lastD = null;
if (lastFile != null) {
addToCopyMap(lastFile.getProjectRelativePath(), MODULE_TRAILER);
}
if (isr != null) {
isr.close();
}
if (is != null) {
is.close();
}
is = ((IFile) currFile).getContents();
isr = new InputStreamReader(is);
currOffset = 0;
Module m = projectSourceParser.containedModule((IFile) currFile);
String moduleName = m.getIdentifier().getTtcnName();
addToCopyMap(currFile.getProjectRelativePath(), MessageFormat.format(MODULE_HEADER, moduleName));
}
int toSkip = getNodeOffset(d) - currOffset;
if (toSkip < 0) {
reportOverlappingError(lastD, d);
continue;
}
isr.skip(toSkip);
// separators
if (d instanceof ImportModule && lastD instanceof ImportModule) {
addToCopyMap(currFile.getProjectRelativePath(), SINGLE_SEPARATOR);
} else if (d instanceof FriendModule && lastD instanceof FriendModule) {
addToCopyMap(currFile.getProjectRelativePath(), SINGLE_SEPARATOR);
} else {
addToCopyMap(currFile.getProjectRelativePath(), DOUBLE_SEPARATOR);
}
//
insertDependency(d, currFile, isr);
currOffset = d.getLocation().getEndOffset();
lastFile = currFile;
lastD = d;
}
if (lastFile != null) {
addToCopyMap(lastFile.getProjectRelativePath(), MODULE_TRAILER);
}
if (isr != null) {
isr.close();
}
if (is != null) {
is.close();
}
// copy the full content of asn files without opening them
filesToCopy = new ArrayList<IFile>();
for (IResource r : asnFiles) {
if (!(r instanceof IFile)) {
ErrorReporter.logError("ExtractModulePar/DependencyCollector: IResource `" + r.getName() + "' is not an IFile.");
continue;
}
filesToCopy.add((IFile) r);
}
} catch (IOException ioe) {
ErrorReporter.logError("ExtractModulePar/DependencyCollector: Error while reading source project.");
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
private void insertDependency(final ILocateableNode d, final IResource res, final InputStreamReader isr) throws IOException {
char[] content = new char[d.getLocation().getEndOffset() - getNodeOffset(d)];
isr.read(content, 0, content.length);
addToCopyMap(res.getProjectRelativePath(), new String(content));
}
};
job.setUser(true);
job.schedule();
return job;
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.FriendModule in project titan.EclipsePlug-ins by eclipse.
the class Definitions method updateSyntax.
/**
* Handles the incremental parsing of this list of definitions.
*
* @param reparser
* the parser doing the incremental parsing.
* @param importedModules
* the list of module importations found in the same
* module.
* @param friendModules
* the list of friend module declaration in the same
* module.
* @param controlpart
* the control part found in the same module.
* @throws ReParseException
* if there was an error while refreshing the location
* information and it could not be solved internally.
*/
public void updateSyntax(final TTCN3ReparseUpdater reparser, final List<ImportModule> importedModules, final List<FriendModule> friendModules, final ControlPart controlpart) throws ReParseException {
// calculate damaged region
int result = 0;
boolean enveloped = false;
int nofDamaged = 0;
int leftBoundary = location.getOffset();
int rightBoundary = location.getEndOffset();
final int damageOffset = reparser.getDamageStart();
final int damageEndOffset = reparser.getDamageEnd();
IAppendableSyntax lastAppendableBeforeChange = null;
IAppendableSyntax lastPrependableBeforeChange = null;
boolean isControlPossible = controlpart == null;
if (controlpart != null) {
final Location tempLocation = controlpart.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
} else if (!reparser.isDamaged(tempLocation)) {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = controlpart;
}
if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = controlpart;
}
}
}
for (int i = 0, size = groups.size(); i < size && !enveloped; i++) {
final Group tempGroup = groups.get(i);
final Location tempLocation = tempGroup.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = tempGroup;
}
if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = tempGroup;
}
}
}
if (!groups.isEmpty()) {
isControlPossible &= groups.get(groups.size() - 1).getLocation().getEndOffset() < leftBoundary;
}
for (int i = 0, size = importedModules.size(); i < size && !enveloped; i++) {
final ImportModule tempImport = importedModules.get(i);
if (tempImport.getParentGroup() == null) {
final Location tempLocation = tempImport.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = tempImport;
}
if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = tempImport;
}
}
}
}
if (!importedModules.isEmpty()) {
isControlPossible &= importedModules.get(importedModules.size() - 1).getLocation().getEndOffset() < leftBoundary;
}
for (int i = 0, size = friendModules.size(); i < size && !enveloped; i++) {
final FriendModule tempFriend = friendModules.get(i);
if (tempFriend.getParentGroup() == null) {
final Location tempLocation = tempFriend.getLocation();
if (reparser.envelopsDamage(tempLocation)) {
enveloped = true;
leftBoundary = tempLocation.getOffset();
rightBoundary = tempLocation.getEndOffset();
} else if (reparser.isDamaged(tempLocation)) {
nofDamaged++;
} else {
if (tempLocation.getEndOffset() < damageOffset && tempLocation.getEndOffset() > leftBoundary) {
leftBoundary = tempLocation.getEndOffset();
lastAppendableBeforeChange = tempFriend;
}
if (tempLocation.getOffset() > damageEndOffset && tempLocation.getOffset() < rightBoundary) {
rightBoundary = tempLocation.getOffset();
lastPrependableBeforeChange = tempFriend;
}
}
}
}
if (!friendModules.isEmpty()) {
isControlPossible &= friendModules.get(friendModules.size() - 1).getLocation().getEndOffset() < leftBoundary;
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext() && !enveloped; ) {
final Definition temp = iterator.next();
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (tempLocation.equals(cumulativeLocation) && reparser.envelopsDamage(cumulativeLocation)) {
enveloped = true;
leftBoundary = cumulativeLocation.getOffset();
rightBoundary = cumulativeLocation.getEndOffset();
} else if (reparser.isDamaged(cumulativeLocation)) {
nofDamaged++;
if (reparser.getDamageStart() == cumulativeLocation.getEndOffset()) {
lastAppendableBeforeChange = temp;
} else if (reparser.getDamageEnd() == cumulativeLocation.getOffset()) {
lastPrependableBeforeChange = temp;
}
} else {
if (cumulativeLocation.getEndOffset() < damageOffset && cumulativeLocation.getEndOffset() > leftBoundary) {
leftBoundary = cumulativeLocation.getEndOffset();
lastAppendableBeforeChange = temp;
}
if (cumulativeLocation.getOffset() > damageEndOffset && cumulativeLocation.getOffset() < rightBoundary) {
rightBoundary = cumulativeLocation.getOffset();
lastPrependableBeforeChange = temp;
}
}
final Location tempCommentLocation = temp.getCommentLocation();
if (tempCommentLocation != null && reparser.isDamaged(tempCommentLocation)) {
nofDamaged++;
rightBoundary = tempLocation.getEndOffset();
}
}
}
if (!definitions.isEmpty()) {
isControlPossible &= definitions.get(definitions.size() - 1).getLocation().getEndOffset() < leftBoundary;
}
// was not enveloped
if (!enveloped && reparser.isDamaged(location)) {
// the extension might be correct
if (lastAppendableBeforeChange != null) {
final boolean isBeingExtended = reparser.startsWithFollow(lastAppendableBeforeChange.getPossibleExtensionStarterTokens());
if (isBeingExtended) {
leftBoundary = lastAppendableBeforeChange.getLocation().getOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (lastPrependableBeforeChange != null) {
final List<Integer> temp = lastPrependableBeforeChange.getPossiblePrefixTokens();
if (temp != null && reparser.endsWithToken(temp)) {
rightBoundary = lastPrependableBeforeChange.getLocation().getEndOffset();
nofDamaged++;
enveloped = false;
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
}
if (nofDamaged != 0) {
// remove damaged stuff
removeStuffInRange(reparser, importedModules, friendModules);
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
lastCompilationTimeStamp = null;
}
// extend damaged region till the neighbor definitions just here to avoid calculating something damaged or extended:
// Perhaps it should be moved even farther:
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
}
// update what is left
for (int i = 0; i < groups.size(); i++) {
final Group temp = groups.get(i);
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
temp.updateSyntax(reparser, importedModules, definitions, friendModules);
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
groups.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
e.decreaseDepth();
throw e;
}
}
}
}
for (int i = 0; i < importedModules.size(); i++) {
final ImportModule temp = importedModules.get(i);
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
if (isDamaged) {
((TTCN3Module) parentScope).checkRoot();
}
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
importedModules.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
e.decreaseDepth();
throw e;
}
}
}
}
}
for (int i = 0; i < friendModules.size(); i++) {
final FriendModule temp = friendModules.get(i);
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
try {
final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
temp.updateSyntax(reparser, enveloped && reparser.envelopsDamage(tempLocation));
if (isDamaged) {
((TTCN3Module) parentScope).checkRoot();
}
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
friendModules.remove(i);
i--;
reparser.extendDamagedRegion(tempLocation);
result = 1;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
e.decreaseDepth();
throw e;
}
}
}
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(cumulativeLocation)) {
try {
final boolean isDamaged = enveloped && reparser.envelopsDamage(tempLocation);
temp.updateSyntax(reparser, isDamaged);
if (reparser.getNameChanged()) {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
// to recheck the whole module
lastCompilationTimeStamp = null;
reparser.setNameChanged(false);
// This could also spread
}
if (isDamaged) {
// TODO lets move this into the definitions
temp.checkRoot();
}
} catch (ReParseException e) {
if (e.getDepth() == 1) {
enveloped = false;
definitions.remove(temp);
reparser.extendDamagedRegion(cumulativeLocation);
result = 1;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
e.decreaseDepth();
throw e;
}
}
}
}
}
if (result == 1) {
removeStuffInRange(reparser, importedModules, friendModules);
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
lastCompilationTimeStamp = null;
}
for (int i = 0, size = groups.size(); i < size; i++) {
final Group temp = groups.get(i);
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
for (int i = 0, size = importedModules.size(); i < size; i++) {
final ImportModule temp = importedModules.get(i);
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
}
for (int i = 0, size = friendModules.size(); i < size; i++) {
final FriendModule temp = friendModules.get(i);
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
if (reparser.isAffected(tempLocation)) {
reparser.updateLocation(tempLocation);
}
}
}
for (final Iterator<Definition> iterator = definitions.iterator(); iterator.hasNext(); ) {
final Definition temp = iterator.next();
if (temp.getParentGroup() == null) {
final Location tempLocation = temp.getLocation();
final Location cumulativeLocation = temp.getCumulativeDefinitionLocation();
if (reparser.isAffected(tempLocation)) {
if (tempLocation != cumulativeLocation) {
reparser.updateLocation(cumulativeLocation);
}
reparser.updateLocation(tempLocation);
}
}
}
final boolean tempIsControlPossible = isControlPossible;
if (!enveloped) {
if (reparser.envelopsDamage(location)) {
reparser.extendDamagedRegion(leftBoundary, rightBoundary);
result = reparse(reparser, tempIsControlPossible);
result = Math.max(result - 1, 0);
lastCompilationTimeStamp = null;
} else {
result = Math.max(result, 1);
}
}
if (result == 0) {
lastUniquenessCheckTimeStamp = null;
} else {
if (doubleDefinitions != null) {
doubleDefinitions.clear();
}
lastUniquenessCheckTimeStamp = null;
throw new ReParseException(result);
}
}
Aggregations