Java Code Examples for org.netbeans.modules.maven.model.pom.POMModel#findComponent()

The following examples show how to use org.netbeans.modules.maven.model.pom.POMModel#findComponent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MoveToDependencyManagementHint.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static List<Dependency> getSelectedDependencies(POMModel mdl, int start, int end) {
    DocumentComponent comp1 = mdl.findComponent(start);

    POMComponent pc = findEnclosing(comp1);
    List<Dependency> dps = null;
    if (pc instanceof org.netbeans.modules.maven.model.pom.Project) {
        org.netbeans.modules.maven.model.pom.Project modprj = (org.netbeans.modules.maven.model.pom.Project) pc;
        dps = modprj.getDependencies();
    } else if (pc instanceof Profile) {
        Profile prf = (Profile) pc;
        dps = prf.getDependencies();
    }
    if (dps == null) {
        return null;
    }
    return extractSelectedDeps(dps, start, end);
}
 
Example 2
Source File: DependencyGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private DependencyContainer findContainer(int pos, POMModel model) {
    Component dc = model.findComponent(pos);
    while (dc != null) {
        if (dc instanceof DependencyContainer) {
            return (DependencyContainer) dc;
        }
        dc = dc.getParent();
    }
    return model.getProject();
}
 
Example 3
Source File: PluginGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private PluginContainer findContainer(int pos, POMModel model) {
    Component dc = model.findComponent(pos);
    while (dc != null) {
        if (dc instanceof PluginContainer) {
            return (PluginContainer) dc;
        }
        dc = dc.getParent();
    }
    Build bld = model.getProject().getBuild();
    if (bld == null) {
        bld = model.getFactory().createBuild();
        model.getProject().setBuild(bld);
    }
    return bld;
}
 
Example 4
Source File: MoveToDependencyManagementHint.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public List<ErrorDescription> getErrorsForDocument(POMModel model, Project prj,
        int selectionStart, int selectionEnd, int caretPosition) {
    List<ErrorDescription> err = new ArrayList<ErrorDescription>();
    if (prj == null) {
        return err;
    }
    DocumentComponent comp1 = model.findComponent(selectionStart);
    DocumentComponent comp2 = model.findComponent(selectionEnd);
    if (comp1 == null || comp2 == null) { //#157213
        return err;
    }
 
    List<Dependency> deps = getSelectedDependencies(model, selectionStart, selectionEnd);
    if (deps != null && !deps.isEmpty()) { //NOI18N
        try {
            Line line = NbEditorUtilities.getLine(model.getBaseDocument(), caretPosition, false);
            err.add(ErrorDescriptionFactory.createErrorDescription(
                    Severity.HINT,
                    NbBundle.getMessage(MoveToDependencyManagementHint.class, "TEXT_MoveToDependencyManagementHint"),
                    Collections.<Fix>singletonList(new MoveFix(selectionStart, selectionEnd, model, prj)),
                    model.getBaseDocument(), line.getLineNumber() + 1));
        } catch (IndexOutOfBoundsException ioob) {
            //#214527
            LOG.log(Level.FINE, "document changed", ioob);
        }
    }
    return err;
}
 
Example 5
Source File: TurnToPropertyHint.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public List<ErrorDescription> getErrorsForDocument(POMModel model, Project prj,
        int selectionStart, int selectionEnd, int caretPosition) {
    List<ErrorDescription> err = new ArrayList<ErrorDescription>();
    if (prj == null) {
        return err;
    }
    DocumentComponent comp1 = model.findComponent(selectionStart);
    DocumentComponent comp2 = model.findComponent(selectionEnd);
    if (comp1 == null || comp2 == null) { //#157213
        return err;
    }
    if (comp1 == comp2 && comp1 instanceof POMExtensibilityElement) {
        POMExtensibilityElement el = (POMExtensibilityElement) comp1;
        int startPos = el.findPosition();
        startPos = startPos + el.getQName().getLocalPart().length() + 2; //2 is brackets
        String text = el.getElementText();
        int endPos = startPos + text.length();
        if (selectionStart >= startPos && selectionEnd <= endPos) {
            //we are in actual text now..
            //TODO also skip when inside expression as well..
            int offset = selectionStart - startPos;
            int endOffset = selectionEnd - startPos;
            String s = text.substring(offset, endOffset);
            if (s.length() > 0) {
                List<Fix> fixes = new ArrayList<Fix>();
                String elementName = el.getQName().getLocalPart();
                Map<String, String> props = loadAllProperties(prj, model, el, selectionStart);
                for (Map.Entry<String, String> ent : props.entrySet()) {
                    if (s.equals(ent.getValue()) && !elementName.equals(ent.getKey())) { //do not want to complete the cycle
                        fixes.add(new PropFix(text, offset, endOffset, el, model, ent.getKey()));
                    }
                }
                fixes.add(new PropFix(text, offset, endOffset, el, model));
                try {
                    Line line = NbEditorUtilities.getLine(model.getBaseDocument(), selectionEnd, false);
                    err.add(ErrorDescriptionFactory.createErrorDescription(
                            Severity.HINT,
                            TIT_TurnToPropertyHint(),
                            fixes,
                            model.getBaseDocument(), line.getLineNumber() + 1));
                } catch (IndexOutOfBoundsException iiob) {
                    //#214527
                    LOG.log(Level.FINE, "document changed", iiob);
                }
                
            }
        }
    }
    return err;
}