Models Why DOM? XML means more than is written there We want to - - PowerPoint PPT Presentation

models
SMART_READER_LITE
LIVE PREVIEW

Models Why DOM? XML means more than is written there We want to - - PowerPoint PPT Presentation

Models Why DOM? XML means more than is written there We want to work with semantic model XML PSI is not very convenient plugin.xml: <idea-plugin> <id>com.intellij.intelliWhisper</id> ... <extension-points>


slide-1
SLIDE 1

Models

slide-2
SLIDE 2
slide-3
SLIDE 3

Why DOM?

XML means more than is written there We want to work with semantic model XML PSI is not very convenient

slide-4
SLIDE 4

plugin.xml:

<idea-plugin> <id>com.intellij.intelliWhisper</id> ... <extension-points> <extension-point name="voice" interface="com.intellij.whisper.Voice"/> ... </extension-points> ... </idea-plugin>

slide-5
SLIDE 5

Extension points' qualified names

IdeaPlugin root = ...; Map<String, PsiClass> result = new HashMap<~>(); String id = root.getId().getValue(); if (id != null) { EPGroup group = root.getEPGroup(); for (ExtensionPoint ep : group.getExtensionPoints()) { String name = ep.getName().getValue(); if (name != null) { result.put(id + "." + name, ep.getInterface().getValue()); } } }

slide-6
SLIDE 6

DOM interfaces

interface IdeaPlugin extends DomElement { GenericDomValue<String> getId(); @SubTag("extension-points") EPGroup getEPGroup(); } interface EPGroup extends DomElement { List<ExtensionPoint> getExtensionPoints(); } interface ExtensionPoint extends DomElement { GenericAttributeValue<String> getName(); GenericAttributeValue<PsiClass> getInterface(); }

slide-7
SLIDE 7

Advantages

Auto-generated implementations Easy reference registration Easy declaration registration Runtime extensibility Optionally: completion for tag & attribute names http://www.jetbrains.com/idea/documentation/dom-rp.html

slide-8
SLIDE 8
slide-9
SLIDE 9

SEM

Compute something by PsiElement and cache it Drop the cache on any change SemService#getSemElement(SemKey, PsiElement) registration: SemContributor register(SemKey<Sem>, ElementPattern<Psi>, NullableFunction<Psi,Sem>) No side effects, please equals/hashCode

slide-10
SLIDE 10
slide-11
SLIDE 11

JAM

Semantics based on Java annotations, method signatures, etc. PsiRef<Psi>: real || imaginary Custom wrappers for members and nested annotations Bound to JamService.JAM_ELEMENT_KEY Domain-specific logic inside wrappers JAM children

slide-12
SLIDE 12

Meta

Registering nested PsiMember JAM considered superfluous JamService.MEMBER_META_KEY Instantiates the JAM element Generates proxy class Knows about children: JamChildrenQuery<ChildJam>

slide-13
SLIDE 13

AOP aspects & introductions

JamChildrenQuery<AopIntroductionImpl> INTRODUCTIONS_QUERY = annotatedFields (DECLARE_PARENTS_ANNO , AopIntroductionImpl.class); JamClassMeta<AopAspectImpl> ASPECT_META = new JamClassMeta<~>(AopAspectImpl.class). addChildrenQuery(INTRODUCTIONS_QUERY ); .... ASPECT_META .register (registrar, psiClass (). withAnnotation(ASPECT_ANNO ). andNot(psiElement ().compiled())); .... jamService.getJamClassElements(AopAspectImpl.class, ASPECT_ANNO , scope) .... public List<AopIntroductionImpl> getIntroductions() { return INTRODUCTIONS_QUERY .findChildren(getClassRef()); }

slide-14
SLIDE 14

Attributes

Annotation meta Attribute meta: class, enum, annotation, string Single or array JamStringAttributeElement<T>: T getValue() JamConverter<T>: T fromString(...), createReferences(...)

slide-15
SLIDE 15

AOP: throwing attribute

JamStringAttributeMeta.Single<PsiParameter> THROWING_META = singleString(THROWING_PARAM , MethodParameterConverter.INSTANCE ); JamAnnotationMeta AFTER_THROWING_META = new JamAnnotationMeta(AFTER_THROWING_ANNO ).addAttribute(THROWING_META ); .... public JamStringAttributeElement<PsiParameter> getReturning() { return AFTER_THROWING_META .getAttribute(getMethod(), THROWING_META ); }

slide-16
SLIDE 16
slide-17
SLIDE 17

POM

Need to resolve somewhere not in PSI FakePsiElement, RenameableFakePsiElement interface PomTarget extends Navigatable {} PomNamedTarget, PsiTarget Register PomTarget's with JamMemberMeta JamPomTargets on string attribute