Psi validating against a DTD for code completion

If you have a DTD in an XML document in Idea correctly it
interprets/validates etc and assists w/ code completion.

How is this achieved programattically? I want to use a DTD to drive the
language I am creating and validate by means of the DTD. Then updating the
language would be as simple as updating the DTD right? Well its an idea of
mine to reduce the code maintenance.

Please can someone help me solve this problem?

Thanks in advance.
- Percy Williams


5 comments

I assume the DTD is parsed and kept in memory. What are you asking about?

Percy Williams wrote:

If you have a DTD in an XML document in Idea correctly it
interprets/validates etc and assists w/ code completion.

How is this achieved programattically? I want to use a DTD to drive the
language I am creating and validate by means of the DTD. Then updating the
language would be as simple as updating the DTD right? Well its an idea of
mine to reduce the code maintenance.

Please can someone help me solve this problem?

Thanks in advance.
- Percy Williams

0

Reading the DTD and using the keywords in the DTD to populate the appropiate
arrays for auto-completion?

"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:e28alo$qot$3@is.intellij.net...
>I assume the DTD is parsed and kept in memory. What are you asking about?
>

Percy Williams wrote:

>> If you have a DTD in an XML document in Idea correctly it
>> interprets/validates etc and assists w/ code completion.
>>
>> How is this achieved programattically? I want to use a DTD to drive the
>> language I am creating and validate by means of the DTD. Then updating
>> the language would be as simple as updating the DTD right? Well its an
>> idea of mine to reduce the code maintenance.
>>
>> Please can someone help me solve this problem?
>>
>> Thanks in advance.
>> - Percy Williams


0

Yes, that sounds like a good approach.

Percy Williams wrote:

Reading the DTD and using the keywords in the DTD to populate the appropiate
arrays for auto-completion?

"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:e28alo$qot$3@is.intellij.net...

>> I assume the DTD is parsed and kept in memory. What are you asking about?
>>
>> Percy Williams wrote:
>>> If you have a DTD in an XML document in Idea correctly it
>>> interprets/validates etc and assists w/ code completion.
>>>
>>> How is this achieved programattically? I want to use a DTD to drive the
>>> language I am creating and validate by means of the DTD. Then updating
>>> the language would be as simple as updating the DTD right? Well its an
>>> idea of mine to reduce the code maintenance.
>>>
>>> Please can someone help me solve this problem?
>>>
>>> Thanks in advance.
>>> - Percy Williams


0

Do you have any sample code which shows how to populate this arrays?

"Keith Lea" <keith@cs.oswego.edu> wrote in message
news:e2irk3$ldo$3@is.intellij.net...

Yes, that sounds like a good approach.

>

Percy Williams wrote:

>> Reading the DTD and using the keywords in the DTD to populate the
>> appropiate arrays for auto-completion?
>>
>> "Keith Lea" <keith@cs.oswego.edu> wrote in message
>> news:e28alo$qot$3@is.intellij.net...
>>> I assume the DTD is parsed and kept in memory. What are you asking
>>> about?
>>>
>>> Percy Williams wrote:
>>>> If you have a DTD in an XML document in Idea correctly it
>>>> interprets/validates etc and assists w/ code completion.
>>>>
>>>> How is this achieved programattically? I want to use a DTD to drive
>>>> the language I am creating and validate by means of the DTD. Then
>>>> updating the language would be as simple as updating the DTD right?
>>>> Well its an idea of mine to reduce the code maintenance.
>>>>
>>>> Please can someone help me solve this problem?
>>>>
>>>> Thanks in advance.
>>>> - Percy Williams
>>

0

I think i have something like what you're describing.
In the Tapestry plugin i extended the html auto-completion. In order to find the additional tag attributes i parse a xml file(tapestry component definition) that contains the list of valid attributes.

In order to achieve this i implemented CompletionData.
My implementation looks something like this:

+public class TemplateCompletionData extends CompletionData
{
{
declareFinalScope(XmlElement.class);

CompletionVariant attributeCompletionVariant = new CompletionVariant(new ElementFilter()
{
public boolean isAcceptable(Object object, PsiElement psiElement)
{
// check if should use this completion for this psiElement
}

public boolean isClassAcceptable(Class aClass)
{
return true;
}
});
attributeCompletionVariant.includeScopeClass(XmlElement.class, true);
attributeCompletionVariant.addCompletion(new AttributeContextGetter(), 0);
registerVariant(attributeCompletionVariant);
}

private class AttributeContextGetter implements ContextGetter
{
/**

  • {@inheritDoc}

*/
public Object[] get(PsiElement psiElement, CompletionContext context)
{
// read the xml file and construct the array with the valid attributes.
}
}
}+

0

Please sign in to leave a comment.