Search in sources :

Example 1 with SpecfileDefine

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine in project linuxtools by eclipse.

the class SpecfileDefineTest method testDefine.

@Test
public void testDefine() {
    SpecfileDefine blahDefine = specfile.getDefine("blah");
    assertEquals(SpecfileDefine.class, blahDefine.getClass());
    assertEquals("blah", blahDefine.getName());
    assertEquals("bleh", blahDefine.getStringValue());
}
Also used : SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) Test(org.junit.Test)

Example 2 with SpecfileDefine

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine in project linuxtools by eclipse.

the class SpecfileDefineTest method testDefine2.

@Test
public void testDefine2() {
    SpecfileDefine blahDefine = specfile.getDefine("blah2");
    assertEquals(SpecfileDefine.class, blahDefine.getClass());
    assertEquals("blah2", blahDefine.getName());
    assertEquals("bleh", blahDefine.getStringValue());
}
Also used : SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) Test(org.junit.Test)

Example 3 with SpecfileDefine

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine in project linuxtools by eclipse.

the class SpecfileDefineTest method testResolve.

@Test
public void testResolve() {
    SpecfileDefine define1 = new SpecfileDefine("name", "testspec", specfile, specfile.getPackages().getPackage(specfile.getName()));
    specfile.addDefine(define1);
    assertEquals("testspec", ((SpecfileElement) define1).resolve("%{name}"));
}
Also used : SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) Test(org.junit.Test)

Example 4 with SpecfileDefine

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine in project linuxtools by eclipse.

the class SpecfileDefineTest method testDefine3.

@Test
public void testDefine3() {
    SpecfileDefine blahDefine = specfile.getDefine("blah3");
    assertEquals(SpecfileDefine.class, blahDefine.getClass());
    assertEquals("blah3", blahDefine.getName());
    assertEquals(1, blahDefine.getIntValue());
}
Also used : SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) Test(org.junit.Test)

Example 5 with SpecfileDefine

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine 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);
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileDefine(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

SpecfileDefine (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine)12 Test (org.junit.Test)7 BadLocationException (org.eclipse.jface.text.BadLocationException)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 IDocument (org.eclipse.jface.text.IDocument)2 IRegion (org.eclipse.jface.text.IRegion)2 SpecfileSource (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource)2 Specfile (org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)2 SpecfileParser (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser)2 StringTokenizer (com.ibm.icu.util.StringTokenizer)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Region (org.eclipse.jface.text.Region)1 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 SpecfileEditor (org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor)1 SpecfileElementHyperlink (org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlink)1 SpecfileElementHyperlinkDetector (org.eclipse.linuxtools.internal.rpm.ui.editor.hyperlink.SpecfileElementHyperlinkDetector)1