fede.workspace.eclipse.java.manager.PathFolderVariable.java Source code

Java tutorial

Introduction

Here is the source code for fede.workspace.eclipse.java.manager.PathFolderVariable.java

Source

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 * Copyright (C) 2006-2010 Adele Team/LIG/Grenoble University, France
 */
package fede.workspace.eclipse.java.manager;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IPackageFragmentRoot;

import java.util.UUID;
import fr.imag.adele.cadse.core.content.ContentItem;
import fr.imag.adele.cadse.core.Item;
import fr.imag.adele.cadse.core.impl.var.VariableImpl;
import fr.imag.adele.cadse.core.var.ContextVariable;
import fr.imag.adele.cadse.core.var.Variable;

/**
 * The Class PathFolderVariable.
 * 
 * @author <a href="mailto:stephane.chomat@imag.fr">Stephane Chomat</a>
 */
public class PathFolderVariable extends VariableImpl {

    /** The package name. */
    private Variable packageName;

    /**
     * Instantiates a new path folder variable.
     * 
     * @param id
     *            the id
     * @param packageName
     *            the package name
     */
    public PathFolderVariable(UUID id, String name, Variable packageName) {
        super(id, name);
        this.packageName = packageName;
    }

    public PathFolderVariable(Variable packageName) {
        super();
        this.packageName = packageName;
    }

    /*
     * (non-Javadoc)
     * 
     * @see fr.imag.adele.cadse.core.var.Variable#compute(fr.imag.adele.cadse.core.var.ContextVariable,
     *      fr.imag.adele.cadse.core.Item)
     */
    public String compute(ContextVariable context, Item item) {
        ContentItem parent = item.getContentItem().getParentContentManager();
        IPath p = new Path("");

        if (parent != null) {
            IPackageFragmentRoot pfr = parent.getMainMappingContent(context, IPackageFragmentRoot.class);
            if (pfr != null) {
                p = pfr.getResource().getProjectRelativePath();
            }
        }

        String _packageName = packageName.compute(context, item);
        if (_packageName != null) {
            p = p.append(_packageName.replace('.', '/'));
        }
        return p.toPortableString();
    }

}