This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 202960 - POM code completion suggests <project> element in plugin <configuration> block
Summary: POM code completion suggests <project> element in plugin <configuration> block
Status: RESOLVED WONTFIX
Alias: None
Product: xml
Classification: Unclassified
Component: Schema (show other bugs)
Version: 7.1
Hardware: All All
: P4 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-03 07:33 UTC by dbell
Modified: 2016-07-07 09:56 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description dbell 2011-10-03 07:33:02 UTC
[ BUILD # : 201109260601 ]
[ JDK VERSION : 1.6.26 ]

Inside a Maven pom.xml, code completion inappropriately suggests "<project>" as
an option inside a plugin's <configuration> section.

e.g. With the carat positioned as follows, "<project>" is included in the list
of code completion suggestions.

<project>
    ...
    <build>
        <plugins>
            <plugin>
                ...
                <configuration>
                    <|
Comment 1 Jesse Glick 2011-10-19 22:43:25 UTC
I have noticed this too. I can confirm that org.netbeans.modules.maven.grammar.AbstractSchemaBasedGrammar.queryElements is not producing the 'project' entry; it is coming from a org.netbeans.modules.xml.schema.completion.CompletionResultItem.

In fact if you comment out xsi:schemaLocation the bug disappears. FWIW the schema declaration of <configuration> is

<xs:element name="configuration" minOccurs="0">
  <xs:annotation.../>
  <xs:complexType>
    <xs:sequence>
      <xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

which does not rule out <project> as a possible child element, of course, but certainly does not suggest it (or anything else for that matter).

I think CompletionUtil.substituteAny is at fault: it should add no completion items when anyNamespace.equals("##any"); and the other clauses should be considered carefully as well, especially anyNamespace.equals("##other").
Comment 2 dbell 2011-10-22 03:20:37 UTC
(In reply to comment #1)
> I think CompletionUtil.substituteAny is at fault: it should add no completion
> items when anyNamespace.equals("##any"); and the other clauses should be
> considered carefully as well, especially anyNamespace.equals("##other").

I think that (as you point out), the schema doesn't define the content of configuration adequately. The benefit of them having anyElement is that they can avoid forcing definers of <configuration> content to use a substitutionGroup (as they would need to if the pom schema restricted the content to, e.g., <config-element abstract="true"/>). This comes at the cost of making the definition too lax.

These kinds of situations (with inappropriately broad suggestions) in XML documents are analogous to situations like Collection.add(Object) in Java. Inasmuch as it satisfies the compiler, any suggestion is appropriate (as any type extends Object),  and the IDE is correct in supplying all suggestions. The IDE is also correct in highlighting "suspicious" usages of Collection.add() in which the added object's type does not match the generic type of the Collection. So, it seems that the Collection API is to blame (for not restricting the method to List<T>.add(T)). In the same way, I think the schema is to blame for the extra suggestions. 

So, I think CompletionUtil is doing the right thing. To make completion more usable, I think we can learn lots from the Java completion. For example, we could restrict initial suggestions, and force the user to invoke completion again for _all_ suggestions (including things like xsi:schemaLocation when <anyAttribute/> is used). We could also perhaps add warnings if there are situations like this one, where the usage is technically valid, but suspicious (like recursive use of <project> in <configuration>). That way, we enable service providers (schema writers) to express themselves through the schema by honouring the schema definition. We also ease the burden on the user of the inappropriately broad schema by adding extra editor features.

TL;DR: I'm happy to close this: in my mind, the schema is at fault.
Comment 3 Jesse Glick 2011-11-08 00:49:40 UTC
I guess you are talking about Collection.remove. The analogy does not really hold because the schema is correct - a POM schema cannot statically know what configuration plugins might take - but one module in the IDE is already offer useful dynamic completion items, whereas a more generic module is offering a pointless item.
Comment 4 Martin Balin 2016-07-07 09:56:28 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss