use of org.eclipse.cdt.core.dom.ast.IASTFileLocation in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class ASTComparison method generateBasicComparisonResultAttributes.
/**
* Generates the basic comparison attributes (EXPECTED, ACTUAL, LINE_NO).
* Not both of expected and actual should be null.
*/
protected static <T extends IASTNode> List<ComparisonAttribute> generateBasicComparisonResultAttributes(final T expected, final T actual, final EnumSet<ComparisonArg> args) {
List<ComparisonAttribute> attributes = new ArrayList<>();
attributes.add(new ComparisonAttribute(ComparisonAttrID.EXPECTED, getSimpleClassNameOrNULL(expected), getRawSignatureOrMissing(expected)));
attributes.add(new ComparisonAttribute(ComparisonAttrID.ACTUAL, getSimpleClassNameOrNULL(actual), getRawSignatureOrMissing(actual)));
final IASTFileLocation fileLocation = (expected != null ? expected : actual).getOriginalNode().getFileLocation();
if (args.contains(ComparisonArg.PRINT_CONTEXT_ON_FAIL)) {
attributes.add(new ComparisonAttribute(ComparisonAttrID.EXPECTED_CONTEXT, "some lines", getRawSignatureContextOrMissing(expected, args)));
attributes.add(new ComparisonAttribute(ComparisonAttrID.ACTUAL_CONTEXT, "some lines", getRawSignatureContextOrMissing(actual, args)));
}
if (fileLocation != null) {
attributes.add(new ComparisonAttribute(ComparisonAttrID.LINE_NO, String.valueOf(fileLocation.getStartingLineNumber())));
}
return attributes;
}
use of org.eclipse.cdt.core.dom.ast.IASTFileLocation in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class ASTComparison method getRawSignatureContextOrMissing.
protected static String getRawSignatureContextOrMissing(IASTNode node, EnumSet<ComparisonArg> args) {
if (node == null)
return NODE_MISSING;
IASTNode parent = node;
IASTFileLocation loc = node.getFileLocation();
if (loc == null) {
node.isPartOfTranslationUnitFile();
return getRawSignatureOrMissing(node);
}
while (loc.getNodeLength() < 60 && loc.getEndingLineNumber() - loc.getStartingLineNumber() < 3 && parent.getParent() != null && parent.getParent().getFileLocation() != null) {
parent = parent.getParent();
loc = parent.getFileLocation();
}
String signature = parent.getRawSignature();
;
if (args.contains(ComparisonArg.DO_NOT_PRINT_RELATIVE_LINE_NOS)) {
return signature;
} else {
String[] lines = signature.split(WorkspaceUtil.getWorkspaceLineSeparator());
int beginningLineNo = loc.getStartingLineNumber();
for (int i = 0; i < lines.length; i++) {
lines[i] = String.format("%02d| ", beginningLineNo + i) + lines[i];
}
return String.join(WorkspaceUtil.getWorkspaceLineSeparator(), lines);
}
}
use of org.eclipse.cdt.core.dom.ast.IASTFileLocation in project ch.hsr.ifs.cdttesting by IFS-HSR.
the class ASTWidget method createNode.
private Node<Pair<Button, IASTNode>> createNode(final Button button, final IASTNode astNode) {
final Node<Pair<Button, IASTNode>> node = new Node<>(new Pair<>(button, astNode));
final Point minButtonSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
nodeHeight = Math.max(nodeHeight, minButtonSize.y);
node.setWidth(minButtonSize.x);
node.treatAsLeaf(true);
if (astNode instanceof ICPPASTTranslationUnit) {
button.setBackground(GOLDEN_YELLOW);
button.getFont().getFontData()[0].setStyle(SWT.BOLD);
}
button.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(final MouseEvent e) {
int selectKey = 0;
if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_RIGHT_CLICK)) {
selectKey = 3;
} else if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_LEFT_CLICK)) {
selectKey = 1;
}
if (e.button == selectKey) {
setNodeInNodeView(astNode);
}
if (e.button == 1) {
buildChildrenAndRefresh(node);
}
}
});
button.addMouseTrackListener(new MouseTrackListener() {
@Override
public void mouseHover(final MouseEvent e) {
if (prefStore.getString(PreferenceConstants.P_HOW_TO_SELECT).equals(PreferenceConstants.P_SELECT_BY_MOUSE_OVER)) {
setNodeInNodeView(astNode);
}
IASTFileLocation fileLocation = astNode.getFileLocation();
while (fileLocation.getContextInclusionStatement() != null) {
final IASTPreprocessorIncludeStatement contextInclusionStatement = fileLocation.getContextInclusionStatement();
fileLocation = contextInclusionStatement.getFileLocation();
}
final TextSelection textSelection = new TextSelection(fileLocation.getNodeOffset(), fileLocation.getNodeLength());
CUIPlugin.getActivePage().getActiveEditor().getEditorSite().getSelectionProvider().setSelection(textSelection);
}
@Override
public void mouseExit(final MouseEvent e) {
}
@Override
public void mouseEnter(final MouseEvent e) {
}
});
return node;
}
Aggregations