Package workspace.contextMenu

Source Code of workspace.contextMenu.VisibilityTester

package workspace.contextMenu;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;

import tree.HaxeTree;
import tree.utils.TreeUtils;
import workspace.commands.RenameCommand;
import workspace.editor.CodeFilesEditor;
import workspace.refactoring.HaxeRenameProcessor;

public class VisibilityTester extends PropertyTester
{
   
    public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
    {
        CodeFilesEditor fragment= (CodeFilesEditor)receiver;
        if ("canRefactor".equals(property))
        {
            HaxeTree node = fragment.getCurrentNode();
            return testCanRefactor(node);
        }
        return false;
    }
   
    private boolean testCanRefactor(HaxeTree node)
    {
        if (!TreeUtils.isNodeValidForUsageAnalysis(node))
        {
            node = TreeUtils.getValidNodeForUsageAnalysis(node);
        }
        if (node == null)
        {
            return false;
        }
        HaxeRenameProcessor pr = RenameCommand.getAppropriateProcessor(node, "");
        if (pr == null)
        {
            return false;
        }
        RefactoringStatus status;
        try
        {
            status = pr.checkInitialConditions(new NullProgressMonitor());
        }
        catch (OperationCanceledException | CoreException e)
        {
            return false;
        }
       
        return status.isOK();
    }
}
TOP

Related Classes of workspace.contextMenu.VisibilityTester

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.