use of org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource in project linuxtools by eclipse.
the class LinePositionTest method testLineNumber.
@Test
public void testLineNumber() {
String specText = "Patch3: somefilesomewhere.patch" + "\n" + "Patch2: someotherfile.patch";
newFile(specText);
Collection<SpecfileSource> patches = specfile.getPatches();
for (SpecfileSource patch : patches) {
if (patch.getNumber() == 2)
assertEquals(1, patch.getLineNumber());
else if (patch.getNumber() == 3)
assertEquals(0, patch.getLineNumber());
else
fail("Found patch with number different from the expected numbers (2 or 3).");
}
}
use of org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource in project linuxtools by eclipse.
the class LinePositionTest method testLineNumber2.
@Test
public void testLineNumber2() {
String specText = "Patch3: somefilesomewhere.patch" + "\n" + "%patch3";
newFile(specText);
Collection<SpecfileSource> patches = specfile.getPatches();
for (SpecfileSource patch : patches) {
if (patch.getNumber() == 3) {
assertEquals(0, patch.getLineNumber());
assertEquals(1, patch.getLinesUsed().get(0).intValue());
} else
fail("Found patch with number different from the expected 3.");
}
}
use of org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource in project linuxtools by eclipse.
the class PatchApplicationTest method testMultiplePatchLineNumbers.
@Test
public void testMultiplePatchLineNumbers() {
String specText = "Patch3: somefilesomewhere.patch" + "\n" + "%patch3" + "\n" + "blah" + "\n" + "%patch3";
newFile(specText);
SpecfileSource thisPatch = specfile.getPatch(3);
List<Integer> usedList = new ArrayList<>(2);
usedList.add(Integer.valueOf(1));
usedList.add(Integer.valueOf(3));
assertEquals(thisPatch.getLinesUsed(), usedList);
}
use of org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource in project linuxtools by eclipse.
the class PatchApplicationTest method testPatchLineNumber.
@Test
public void testPatchLineNumber() {
String specText = "Patch3: somefilesomewhere.patch" + "\n" + "%patch3";
newFile(specText);
SpecfileSource thisPatch = specfile.getPatch(3);
List<Integer> usedList = new ArrayList<>(1);
usedList.add(Integer.valueOf(1));
assertEquals(thisPatch.getLinesUsed(), usedList);
}
use of org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource in project linuxtools by eclipse.
the class SpecfileElementHyperlinkDetector method detectHyperlinks.
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
if (region == null || textViewer == null) {
return null;
}
IDocument document = textViewer.getDocument();
if (document == null) {
return null;
}
// until a SpecfileEditor#editorSaved is called
if (specfile == null) {
SpecfileEditor a = this.getAdapter(SpecfileEditor.class);
if (a != null && a.getSpecfile() != null) {
specfile = a.getSpecfile();
} else {
SpecfileParser parser = new SpecfileParser();
specfile = parser.parse(document);
}
}
int offset = region.getOffset();
IRegion lineInfo;
String line;
try {
lineInfo = document.getLineInformationOfOffset(offset);
line = document.get(lineInfo.getOffset(), lineInfo.getLength());
} catch (BadLocationException ex) {
return null;
}
int offsetInLine = offset - lineInfo.getOffset();
StringTokenizer tokens = new StringTokenizer(line);
// $NON-NLS-1$
String word = "";
int tempLineOffset = 0;
int wordOffsetInLine = 0;
while (tokens.hasMoreTokens()) {
String tempWord = tokens.nextToken();
// $NON-NLS-1$
Pattern defineRegexp = Pattern.compile("%\\{(.*?)\\}");
Matcher fit = defineRegexp.matcher(tempWord);
while (fit.find()) {
if ((fit.start() + tempLineOffset <= offsetInLine) && (offsetInLine <= fit.end() + tempLineOffset)) {
tempWord = fit.group();
wordOffsetInLine = fit.start();
tempLineOffset += fit.start();
break;
}
}
tempLineOffset += tempWord.length();
word = tempWord;
if (tempLineOffset > offsetInLine) {
break;
}
}
if (word.startsWith(SOURCE_IDENTIFIER)) {
int sourceNumber = Integer.valueOf(word.substring(SOURCE_IDENTIFIER.length(), word.length() - 1)).intValue();
SpecfileSource source = specfile.getSource(sourceNumber);
if (source != null) {
return prepareHyperlink(lineInfo, line, word, source);
}
} else if (word.startsWith(PATCH_IDENTIFIER)) {
int sourceNumber = Integer.valueOf(word.substring(PATCH_IDENTIFIER.length(), word.length())).intValue();
SpecfileSource source = specfile.getPatch(sourceNumber);
if (source != null) {
return prepareHyperlink(lineInfo, line, word, source);
}
} else {
String defineName = getDefineName(word);
SpecfileDefine define = specfile.getDefine(defineName);
if (define != null) {
return prepareHyperlink(lineInfo, line, defineName, define, wordOffsetInLine);
}
}
return null;
}
Aggregations