use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.
the class RpmMacroOccurrencesUpdater method update.
/**
* Updates the drawn annotations.
*
* @param viewer
* The viewer to get the document and annotation model from
*/
public void update(ISourceViewer viewer) {
try {
IDocument document = viewer.getDocument();
IAnnotationModel model = viewer.getAnnotationModel();
if (document == null || model == null) {
return;
}
removeOldAnnotations(model);
String currentSelectedWord = getWordAtSelection(fEditor.getSelectionProvider().getSelection(), document);
if (isMacro(currentSelectedWord)) {
Specfile spec = fEditor.getSpecfile();
SpecfileDefine define = spec.getDefine(currentSelectedWord);
// $NON-NLS-1$
String word = currentSelectedWord + ": ";
if (define != null) {
word += define.getStringValue();
} else {
// If there's no such define we try to see if it corresponds
// to
// a Source or Patch declaration
String retrivedValue = RPMUtils.getSourceOrPatchValue(spec, currentSelectedWord.toLowerCase());
if (retrivedValue != null) {
word += retrivedValue;
} else {
// If it does not correspond to a Patch or Source macro,
// try to find it
// in the macro proposals list.
retrivedValue = RPMUtils.getMacroValueFromMacroList(currentSelectedWord);
if (retrivedValue != null) {
word += retrivedValue;
}
}
}
createNewAnnotations(currentSelectedWord, word, document, model);
}
} catch (BadLocationException e) {
SpecfileLog.logError(e);
}
}
use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.
the class SpecfileCompletionProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
List<ICompletionProposal> result = new ArrayList<>();
Specfile specfile = new SpecfileParser().parse(viewer.getDocument());
String prefix = completionWord(viewer.getDocument(), offset);
Region region = new Region(offset - prefix.length(), prefix.length());
// RPM macro's are useful in the whole specfile.
List<ICompletionProposal> rpmMacroProposals = computeRpmMacroProposals(region, specfile, prefix);
// Sources completion
List<ICompletionProposal> sourcesProposals = computeSourcesProposals(region, specfile, prefix);
result.addAll(sourcesProposals);
// Get the current content type
String currentContentType = viewer.getDocument().getDocumentPartitioner().getContentType(region.getOffset());
if (currentContentType.equals(SpecfilePartitionScanner.SPEC_PREP)) {
List<ICompletionProposal> patchesProposals = computePatchesProposals(region, specfile, prefix);
result.addAll(patchesProposals);
}
if (currentContentType.equals(SpecfilePartitionScanner.SPEC_PACKAGES)) {
// don't show template in the RPM packages content type.
// (when the line begin with Requires, BuildRequires etc...)
List<ICompletionProposal> rpmPackageProposals = computeRpmPackageProposals(region, prefix);
result.addAll(rpmPackageProposals);
result.addAll(rpmMacroProposals);
} else {
// don't show RPM packages proposals in all others content type.
List<? extends ICompletionProposal> templateProposals = computeTemplateProposals(viewer, region, specfile, prefix);
result.addAll(templateProposals);
result.addAll(rpmMacroProposals);
}
if (currentContentType.equals(SpecfilePartitionScanner.SPEC_GROUP)) {
IDocument document = viewer.getDocument();
try {
int lineNumber = document.getLineOfOffset(region.getOffset());
int lineOffset = document.getLineOffset(lineNumber);
if (region.getOffset() - lineOffset > 5) {
result.clear();
String groupPrefix = getGroupPrefix(viewer, offset);
result.addAll(computeRpmGroupProposals(region, groupPrefix));
}
} catch (BadLocationException e) {
SpecfileLog.logError(e);
}
}
return result.toArray(new ICompletionProposal[result.size()]);
}
use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.
the class SpecfileHover method getHoverInfo.
@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
if (hoverRegion == null || hoverRegion.getLength() == 0) {
return null;
}
Specfile spec = new SpecfileParser().parse(textViewer.getDocument());
String currentSelection;
try {
currentSelection = textViewer.getDocument().get(hoverRegion.getOffset() + 1, hoverRegion.getLength() - 1);
} catch (BadLocationException e) {
return null;
}
// First we try to get a define based on the given name
SpecfileDefine define = spec.getDefine(currentSelection);
// $NON-NLS-1$
String value = currentSelection + ": ";
if (define != null) {
return value + define.getStringValue();
}
String macroLower = currentSelection.toLowerCase();
// If there's no such define we try to see if it corresponds to
// a Source or Patch declaration
String retrivedValue = RPMUtils.getSourceOrPatchValue(spec, macroLower);
if (retrivedValue != null) {
return value + retrivedValue;
} else {
// If it does not correspond to a Patch or Source macro, try to find
// it
// in the macro proposals list.
retrivedValue = RPMUtils.getMacroValueFromMacroList(currentSelection);
if (retrivedValue != null) {
return value + retrivedValue;
} else {
// If it does not correspond to a macro in the list, try to find
// it
// in the RPM list.
retrivedValue = Activator.getDefault().getRpmPackageList().getValue(// $NON-NLS-1$ //$NON-NLS-2$
currentSelection.replaceFirst(":", ""));
if (retrivedValue != null) {
return retrivedValue;
}
}
}
// for unrecognized macros and RPM packages.
return null;
}
use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.
the class SpecfileReconcilingStrategy method reconcile.
private void reconcile() {
Specfile specfile = editor.getSpecfile();
if (specfile != null) {
editor.setSpecfile(editor.getParser().parse(documentProvider.getDocument(editor.getEditorInput())));
outline.update();
updateFolding();
updateEditor();
}
}
use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.
the class SpecfileChangelogFormatter method formatDateLine.
@Override
public String formatDateLine(String authorName, String authorEmail) {
String dateLine;
Specfile specfile = getParsedSpecfile();
// $NON-NLS-1$
String epoch = specfile.getEpoch() == -1 ? EMPTY_STRING : (specfile.getEpoch() + ":");
String version = specfile.getVersion();
String release = specfile.getRelease();
// remove the dist macro if it exist in the release string.
// $NON-NLS-1$
release = release.replaceAll("\\%\\{\\?dist\\}", EMPTY_STRING);
// default format
dateLine = // $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
"* {0} {1} <{2}> {3}{4}-{5}", // $NON-NLS-1$
formatTodaysDate(), // $NON-NLS-1$
authorName, authorEmail, epoch, version, release);
String format = store.getString(PreferenceConstants.P_CHANGELOG_ENTRY_FORMAT);
if (format.equals(PreferenceConstants.P_CHANGELOG_ENTRY_FORMAT_VERSIONED_WITH_SEPARATOR)) {
dateLine = // $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
"* {0} {1} <{2}> - {3}{4}-{5}", // $NON-NLS-1$
formatTodaysDate(), authorName, authorEmail, epoch, version, release);
} else if (format.equals(PreferenceConstants.P_CHANGELOG_ENTRY_FORMAT_UNVERSIONED)) {
// $NON-NLS-1$
dateLine = MessageFormat.format("* {0} {1} <{2}>", formatTodaysDate(), authorName, authorEmail);
}
dateLine = UiUtils.resolveDefines(specfile, dateLine);
return dateLine;
}
Aggregations