Search in sources :

Example 1 with FacetState

use of org.jetbrains.jps.model.serialization.facet.FacetState in project intellij-community by JetBrains.

the class FacetManagerImpl method addFacets.

private void addFacets(final List<FacetState> facetStates, final Facet underlyingFacet, ModifiableFacetModel model) {
    FacetTypeRegistry registry = FacetTypeRegistry.getInstance();
    for (FacetState child : facetStates) {
        final String typeId = child.getFacetType();
        if (typeId == null) {
            addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.facet.type.isn.t.specified"));
            continue;
        }
        final FacetType<?, ?> type = registry.findFacetType(typeId);
        if (type == null) {
            addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.unknown.facet.type.0", typeId), typeId);
            continue;
        }
        ModuleType moduleType = ModuleType.get(myModule);
        if (!type.isSuitableModuleType(moduleType)) {
            addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facets.are.not.allowed.in.1", type.getPresentableName(), moduleType.getName()));
            continue;
        }
        FacetType<?, ?> expectedUnderlyingType = null;
        FacetTypeId<?> underlyingTypeId = type.getUnderlyingFacetType();
        if (underlyingTypeId != null) {
            expectedUnderlyingType = registry.findFacetType(underlyingTypeId);
        }
        FacetType actualUnderlyingType = underlyingFacet != null ? underlyingFacet.getType() : null;
        if (expectedUnderlyingType != null) {
            if (!expectedUnderlyingType.equals(actualUnderlyingType)) {
                addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.facet.must.be.placed.under.1.facet", type.getPresentableName(), expectedUnderlyingType.getPresentableName()));
                continue;
            }
        } else if (actualUnderlyingType != null) {
            addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.0.cannot.be.placed.under.1", type.getPresentableName(), actualUnderlyingType.getPresentableName()));
            continue;
        }
        try {
            addFacet(type, child, underlyingFacet, model);
        } catch (InvalidDataException e) {
            LOG.info(e);
            addInvalidFacet(child, model, underlyingFacet, ProjectBundle.message("error.message.cannot.load.facet.configuration.0", e.getMessage()));
        }
    }
}
Also used : ModuleType(com.intellij.openapi.module.ModuleType) InvalidFacetType(com.intellij.facet.impl.invalid.InvalidFacetType) FacetState(org.jetbrains.jps.model.serialization.facet.FacetState)

Example 2 with FacetState

use of org.jetbrains.jps.model.serialization.facet.FacetState in project intellij-community by JetBrains.

the class FacetManagerImpl method getState.

@Override
public FacetManagerState getState() {
    FacetManagerState managerState = new FacetManagerState();
    final Facet[] facets = getSortedFacets();
    Map<Facet, List<FacetState>> states = new HashMap<>();
    states.put(null, managerState.getFacets());
    for (Facet facet : facets) {
        final Facet underlyingFacet = facet.getUnderlyingFacet();
        final List<FacetState> parent = states.get(underlyingFacet);
        FacetState facetState;
        if (facet instanceof InvalidFacet) {
            facetState = ((InvalidFacet) facet).getConfiguration().getFacetState();
        } else {
            facetState = new FacetState();
            facetState.setFacetType(facet.getType().getStringId());
            facetState.setName(facet.getName());
            final Element config;
            try {
                FacetConfiguration configuration = facet.getConfiguration();
                config = FacetUtil.saveFacetConfiguration(configuration);
                if (facet instanceof JDOMExternalizable) {
                    //todo[nik] remove
                    ((JDOMExternalizable) facet).writeExternal(config);
                }
            } catch (WriteExternalException e) {
                continue;
            }
            facetState.setConfiguration(config);
        }
        parent.add(facetState);
        states.put(facet, facetState.getSubFacets());
    }
    return managerState;
}
Also used : Element(org.jdom.Element) InvalidFacet(com.intellij.facet.impl.invalid.InvalidFacet) InvalidFacetConfiguration(com.intellij.facet.impl.invalid.InvalidFacetConfiguration) FacetManagerState(org.jetbrains.jps.model.serialization.facet.FacetManagerState) FacetState(org.jetbrains.jps.model.serialization.facet.FacetState) InvalidFacet(com.intellij.facet.impl.invalid.InvalidFacet)

Aggregations

FacetState (org.jetbrains.jps.model.serialization.facet.FacetState)2 InvalidFacet (com.intellij.facet.impl.invalid.InvalidFacet)1 InvalidFacetConfiguration (com.intellij.facet.impl.invalid.InvalidFacetConfiguration)1 InvalidFacetType (com.intellij.facet.impl.invalid.InvalidFacetType)1 ModuleType (com.intellij.openapi.module.ModuleType)1 Element (org.jdom.Element)1 FacetManagerState (org.jetbrains.jps.model.serialization.facet.FacetManagerState)1