use of org.eclipse.titan.designer.AST.TTCN3.definitions.ControlPart in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method createDebugInfo.
private String createDebugInfo() {
final StringBuilder sb = new StringBuilder();
sb.append("ExtractToFunctionRefactoring->SelectionFinder debug info: \n");
sb.append(" Runs on reference: ");
sb.append(runsOnRef == null ? "null" : runsOnRef.getId());
sb.append(", enclosing function: ");
if (parentFunc == null) {
sb.append("null");
} else if (parentFunc instanceof Definition) {
sb.append(((Definition) parentFunc).getIdentifier());
} else if (parentFunc instanceof ControlPart) {
sb.append("<controlpart>");
} else {
sb.append("<invalid: ").append(parentFunc).append('>');
}
sb.append('\n');
sb.append(" Return clause: ");
sb.append(returnType == null ? "null" : returnType.getIdentifier());
sb.append(" Warnings: ");
for (RefactoringStatusEntry rse : warnings) {
sb.append("severity: " + rse.getSeverity() + "; msg: " + rse.getMessage());
sb.append('\n');
}
return sb.toString();
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ControlPart in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method performHeadless.
void performHeadless(final IFile selFile, final ITextSelection textSel) {
selectedFile = selFile;
final String fileContents = readFileContents(selFile);
if (fileContents == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): selFile does not exist at: " + selFile.getFullPath());
return;
}
final IDocument doc = new Document(fileContents);
textSelection = new TextSelection(doc, textSel.getOffset(), textSel.getLength());
//
project = selFile.getProject();
sourceParser = GlobalParser.getProjectSourceParser(project);
selectedModule = sourceParser.containedModule(selectedFile);
if (selectedModule == null) {
ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): The module in the file " + selectedFile.getName() + " has no name.");
return;
}
// iterating through the module for the selected statements
final SelectionVisitor selectionVisitor = new SelectionVisitor(textSelection.getOffset(), textSelection.getLength());
selectedModule.accept(selectionVisitor);
selectedStatements = selectionVisitor.createStatementList(textSelection);
if (selectedStatements.isEmpty()) {
ErrorReporter.logError(ERR_MSG_NO_SELECTION);
return;
}
if (ExtractToFunctionRefactoring.DEBUG_MESSAGES_ON) {
ErrorReporter.logError(selectedStatements.createDebugInfo());
ErrorReporter.logError(createDebugInfo());
}
// finding return type & runs on clause
final RunsOnClauseFinder runsonVisitor = new RunsOnClauseFinder(selectedStatements.getLocation());
selectedModule.accept(runsonVisitor);
runsOnRef = runsonVisitor.getRunsOnRef();
parentFunc = runsonVisitor.getFuncDef();
// finding insert location
if (parentFunc instanceof Definition) {
insertLoc = ((Definition) parentFunc).getLocation().getEndOffset();
} else if (parentFunc instanceof ControlPart) {
final ControlPart cp = (ControlPart) parentFunc;
final Location commentLoc = cp.getCommentLocation();
insertLoc = commentLoc == null ? cp.getLocation().getOffset() : commentLoc.getOffset();
}
//
final ReturnVisitor retVis = new ReturnVisitor();
selectedStatements.accept(retVis);
returnCertainty = retVis.getCertainty();
if (retVis.getCertainty() != ReturnCertainty.NO) {
returnType = runsonVisitor.getReturnType();
}
// checking erroneousness of selection
checkErroneousGoto();
if (containsBreakWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_BREAK));
}
if (containsContinueWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_CONTINUE));
}
if (retVis.getCertainty() == ReturnCertainty.MAYBE) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_UNCERTAIN_RETURN));
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ControlPart in project titan.EclipsePlug-ins by eclipse.
the class SelectionFinder method perform.
void perform() {
// getting the active editor
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editor == null || !(editor instanceof TTCN3Editor)) {
return;
}
final TTCN3Editor targetEditor = (TTCN3Editor) editor;
statusLineManager = targetEditor.getEditorSite().getActionBars().getStatusLineManager();
// getting current selection
final ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
textSelection = extractSelection(selectionService.getSelection());
if (textSelection == null) {
ErrorReporter.logError("No valid statements were found in the selection.");
ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
return;
}
// getting selected module
final IResource selectedRes = extractResource(targetEditor);
if (!(selectedRes instanceof IFile)) {
ErrorReporter.logError("ExtractToFunctionRefactoring.findSelection(): Selected resource `" + selectedRes.getName() + "' is not a file.");
return;
}
selectedFile = (IFile) selectedRes;
project = selectedFile.getProject();
sourceParser = GlobalParser.getProjectSourceParser(project);
selectedModule = sourceParser.containedModule(selectedFile);
// iterating through the module for the selected statements
final SelectionVisitor selectionVisitor = new SelectionVisitor(textSelection.getOffset(), textSelection.getLength());
selectedModule.accept(selectionVisitor);
selectedStatements = selectionVisitor.createStatementList(textSelection);
if (selectedStatements.isEmpty()) {
ExtractToFunctionRefactoring.setStatusLineMsg(ERR_MSG_NO_SELECTION, statusLineManager);
return;
}
if (ExtractToFunctionRefactoring.DEBUG_MESSAGES_ON) {
ErrorReporter.logError(selectedStatements.createDebugInfo());
ErrorReporter.logError(createDebugInfo());
}
// finding return type & runs on clause
final RunsOnClauseFinder runsonVisitor = new RunsOnClauseFinder(selectedStatements.getLocation());
selectedModule.accept(runsonVisitor);
runsOnRef = runsonVisitor.getRunsOnRef();
parentFunc = runsonVisitor.getFuncDef();
// finding insert location
if (parentFunc instanceof Definition) {
insertLoc = ((Definition) parentFunc).getLocation().getEndOffset();
} else if (parentFunc instanceof ControlPart) {
final ControlPart cp = (ControlPart) parentFunc;
final Location commentLoc = cp.getCommentLocation();
insertLoc = commentLoc == null ? cp.getLocation().getOffset() : commentLoc.getOffset();
}
//
final ReturnVisitor retVis = new ReturnVisitor();
selectedStatements.accept(retVis);
returnCertainty = retVis.getCertainty();
if (retVis.getCertainty() != ReturnCertainty.NO) {
returnType = runsonVisitor.getReturnType();
}
// checking erroneousness of selection
checkErroneousGoto();
if (containsBreakWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_BREAK));
}
if (containsContinueWithoutLoop()) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_ERRONEOUS_CONTINUE));
}
if (retVis.getCertainty() == ReturnCertainty.MAYBE) {
warnings.add(new RefactoringStatusEntry(RefactoringStatus.WARNING, WARNING_UNCERTAIN_RETURN));
}
}
use of org.eclipse.titan.designer.AST.TTCN3.definitions.ControlPart 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