Example usage for org.eclipse.jdt.core IType getUnderlyingResource

List of usage examples for org.eclipse.jdt.core IType getUnderlyingResource

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IType getUnderlyingResource.

Prototype

IResource getUnderlyingResource() throws JavaModelException;

Source Link

Document

Returns the smallest underlying resource that contains this element, or null if this element is not contained in a resource.

Usage

From source file:com.aliyun.odps.eclipse.launch.shortcut.ODPSApplicationShortcut.java

License:Apache License

protected ILaunchConfiguration createConfiguration(IType type) {
    ILaunchConfiguration config = null;/* w  w w . j  av a 2s  .c  o  m*/
    ILaunchConfigurationWorkingCopy wc = null;
    try {
        // ILaunchConfigurationType configType =
        // DebugPlugin.getDefault().getLaunchManager()
        // .getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);

        ILaunchConfigurationType configType = DebugPlugin.getDefault().getLaunchManager()
                .getLaunchConfigurationType(OdpsEclipseConstants.LAUNCH_CONFIGURATION_TYPE);
        wc = configType.newInstance(null, DebugPlugin.getDefault().getLaunchManager()
                .generateLaunchConfigurationName(type.getTypeQualifiedName('.')));
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, type.getFullyQualifiedName());
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
                type.getJavaProject().getElementName());
        wc.setMappedResources(new IResource[] { type.getUnderlyingResource() });

        config = wc.doSave();

    } catch (CoreException exception) {
        MessageDialog.openError(JDIDebugUIPlugin.getActiveWorkbenchShell(),
                LauncherMessages.JavaLaunchShortcut_3, exception.getStatus().getMessage());
    }
    return config;
}

From source file:com.aliyun.odps.eclipse.launch.shortcut.udf.UDFLaunchShortcuts.java

License:Apache License

protected ILaunchConfiguration createConfiguration(IType type) {
    ILaunchConfiguration config = null;/*  w  ww.  jav  a2s.c  o  m*/
    ILaunchConfigurationWorkingCopy wc = null;
    try {
        // ILaunchConfigurationType configType =
        // DebugPlugin.getDefault().getLaunchManager()
        // .getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);

        ILaunchConfigurationType configType = DebugPlugin.getDefault().getLaunchManager()
                .getLaunchConfigurationType(LaunchConfigurationConstants.ID_LAUNCH_CONFIGURATION_ODPS_UDF);
        wc = configType.newInstance(null, DebugPlugin.getDefault().getLaunchManager()
                .generateLaunchConfigurationName(type.getTypeQualifiedName('.')));
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, type.getFullyQualifiedName());
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
                type.getJavaProject().getElementName());
        wc.setMappedResources(new IResource[] { type.getUnderlyingResource() });

        config = wc.doSave();

    } catch (CoreException exception) {
        MessageDialog.openError(JDIDebugUIPlugin.getActiveWorkbenchShell(),
                LauncherMessages.JavaLaunchShortcut_3, exception.getStatus().getMessage());
    }
    return config;
}

From source file:com.aliyun.odps.eclipse.launch.shortcut.udf.UDFLaunchShortcuts2.java

License:Apache License

protected ILaunchConfiguration createConfiguration(IType type) {
    ILaunchConfiguration config = null;/*from w w  w  .  java  2s.  c om*/
    ILaunchConfigurationWorkingCopy wc = null;
    try {
        ILaunchConfigurationType configType = getConfigurationType();
        wc = configType.newInstance(null,
                getLaunchManager().generateLaunchConfigurationName(type.getTypeQualifiedName('.')));
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, type.getFullyQualifiedName());
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
                type.getJavaProject().getElementName());
        wc.setMappedResources(new IResource[] { type.getUnderlyingResource() });
        config = wc.doSave();
    } catch (CoreException exception) {
        MessageDialog.openError(JDIDebugUIPlugin.getActiveWorkbenchShell(),
                LauncherMessages.JavaLaunchShortcut_3, exception.getStatus().getMessage());
    }
    return config;
}

From source file:com.google.gdt.eclipse.designer.core.util.UtilsTest.java

License:Open Source License

/**
 * Test for {@link Utils#isRemoteService(IResource)}.
 *///from   ww  w. j a  v a  2  s  .com
public void test_isRemoteService_IResource() throws Exception {
    // XML file is NOT RemoteService
    {
        IResource resource = getFileSrc("test/Module.gwt.xml");
        assertTrue(resource.exists());
        assertFalse(Utils.isRemoteService(resource));
    }
    // EntryPoint is NOT RemoteService
    {
        IResource resource = getFileSrc("test/client/Module.java");
        assertTrue(resource.exists());
        assertFalse(Utils.isRemoteService(resource));
    }
    // new RemoteService
    {
        IType type = GTestUtils.createTestService(this)[0];
        IResource resource = type.getUnderlyingResource();
        assertThat(resource).isInstanceOf(IFile.class);
        assertTrue(resource.exists());
        assertTrue(Utils.isRemoteService(resource));
    }
}

From source file:com.google.gdt.eclipse.designer.refactoring.RemoteServiceRenameParticipant.java

License:Open Source License

/**
 * @return the {@link Change} for modifying service name in AST.
 *//*from  w  ww.java 2  s  .c o  m*/
private Change replaceServiceNameInAST(IType serviceType, final String oldServletName,
        final String newServletName) throws Exception {
    ICompilationUnit serviceCompilationUnit = serviceType.getCompilationUnit();
    // parse service type into AST and change servlet path
    CompilationUnit serviceUnit = CodeUtils.parseCompilationUnit(serviceCompilationUnit);
    serviceUnit.recordModifications();
    serviceUnit.accept(new ASTVisitor() {
        @Override
        public void endVisit(StringLiteral node) {
            if (oldServletName.equals(node.getLiteralValue())) {
                node.setLiteralValue(newServletName);
            }
        }
    });
    // create text edits corresponding to that changes in AST
    TextEdit astTextEdit;
    {
        String source = serviceCompilationUnit.getBuffer().getContents();
        Document document = new Document(source);
        astTextEdit = serviceUnit.rewrite(document, serviceType.getJavaProject().getOptions(true));
    }
    // merge AST edit with existing edit for service type file
    {
        IFile serviceTypeFile = (IFile) serviceType.getUnderlyingResource();
        TextChange existingTextChange = getTextChange(serviceTypeFile);
        if (existingTextChange != null) {
            existingTextChange.addEdit(astTextEdit);
            return null;
        } else {
            CompilationUnitChange serviceUnitChange = new CompilationUnitChange(
                    serviceType.getFullyQualifiedName(), serviceCompilationUnit);
            serviceUnitChange.setEdit(astTextEdit);
            return serviceUnitChange;
        }
    }
}

From source file:com.google.gdt.eclipse.designer.uibinder.wizards.UiBinderWizardPage.java

License:Open Source License

@Override
protected void createTypeMembers(IType newType, ImportsManager imports, IProgressMonitor monitor)
        throws CoreException {
    String templatePath = getTemplatePath_Java();
    InputStream template = Activator.getFile(templatePath);
    fillTypeFromTemplate(newType, imports, monitor, template);
    m_javaFile = (IFile) newType.getUnderlyingResource();
}

From source file:com.google.gdt.eclipse.designer.wizards.model.module.CreateModuleOperation.java

License:Open Source License

public IFile create(ModuleConfiguration configuration) throws Exception {
    String moduleName = configuration.getModuleName();
    String packageName = configuration.getPackageName();
    // create packages
    IPackageFragment packageFragment = getPackage(root, packageName);
    getPackage(root, packageName + ".client");
    getPackage(root, packageName + ".server");
    // //from ww w.  ja v  a 2s .  co  m
    // create folders
    IJavaProject javaProject = packageFragment.getJavaProject();
    IProject project = javaProject.getProject();
    String webFolderName = WebUtils.getWebFolderName(project);
    IFolder webFolder = project.getFolder(webFolderName);
    IFolder webInfFolder = project.getFolder(webFolderName + "/WEB-INF");
    // create module
    IFile file;
    if (configuration.isCreateEntryPoint()) {
        // prepare variables
        Map<String, String> variables = configuration.getVariables();
        variables.put("packageName", packageName);
        variables.put("className", moduleName);
        // prepare 'bootstrap' variable
        String bootstrapPrefix = packageName + "." + moduleName;
        variables.put("bootstrap", bootstrapPrefix + "/" + bootstrapPrefix + ".nocache.js");
        // create module
        file = createFileFromTemplate(packageFragment, moduleName + ".gwt.xml", "Module.gwt.xml", variables);
        // create EntryPoint
        CreateEntryPointOperation entryPointOperation = new CreateEntryPointOperation(root);
        entryPointOperation.create(configuration.getEntryPointConfiguration());
        // create files from templates
        createFileFromTemplate(webFolder, moduleName + ".html", "Module.html", variables);
        createFileFromTemplate(webFolder, moduleName + ".css", "Module.css", variables);
        copyTemplateFiles(webFolder, "images");
        // configure web.xml
        if (!webInfFolder.getFile("web.xml").exists()) {
            variables.put("welcome-file-name", moduleName);
            createFileFromTemplate(webInfFolder, "web.xml", "web.xml", variables);
        }
        // open entry point in editor
        {
            String qualifiedEntryPoint = packageName + ".client." + moduleName;
            IType type = WorkspaceUtils.waitForType(root.getJavaProject(), qualifiedEntryPoint);
            IDE.openEditor(DesignerPlugin.getActivePage(), (IFile) type.getUnderlyingResource(),
                    IDesignerEditor.ID);
        }
    } else {
        // create empty module
        file = createFile(packageFragment, moduleName + ".gwt.xml",
                "<module>\r\n\t<inherits name=\"com.google.gwt.user.User\"/>\r\n</module>");
    }
    return file;
}

From source file:com.halware.nakedide.eclipse.ext.builders.checkers.AbstractChecker.java

License:Open Source License

/**
 * //w ww. j  a va2 s .  c  om
 * @param type
 * @param markerId - as per {@link MarkerConstants}.
 * @param message
 * 
 * @throws JavaModelException
 * @throws CoreException
 */
protected void createProblemMarker(IType type, int markerId, String message)
        throws JavaModelException, CoreException {
    IMarker marker;
    marker = type.getUnderlyingResource().createMarker(Constants.PROBLEM_MARKER);
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(IMarker.MESSAGE, message);
    attributes.put(IMarker.SEVERITY, new Integer(org.eclipse.core.resources.IMarker.SEVERITY_WARNING));
    attributes.put(IMarker.LINE_NUMBER, 1);
    attributes.put(MarkerConstants.ATTR_ID_KEY, markerId);

    marker.setAttributes(attributes);
}

From source file:com.iw.plugins.spindle.core.builder.Build.java

License:Mozilla Public License

/**
 * Trigger fired whenever a type check occurs during a build. Type names are stored in the State
 * and used to by incremental builds/*from   www. j a  v a2s .c  o  m*/
 */
public void typeChecked(String fullyQualifiedName, IType result) {
    if (result == null) {
        if (!fMissingTypes.contains(fullyQualifiedName))
            fMissingTypes.add(fullyQualifiedName);
    } else if (!result.isBinary()) {
        try {
            IResource resource = result.getUnderlyingResource();
            if (!fFoundTypes.contains(resource))
                fFoundTypes.add(resource);
        } catch (JavaModelException e) {
            TapestryCore.log(e);
        }
    }
}

From source file:com.iw.plugins.spindle.ui.wizards.TypeChooseWizardPage.java

License:Mozilla Public License

/**
 * Find the file generated, if it was/* w w  w  .  ja v  a 2s .  com*/
 * 
 * @return the IFile that was generated. If no generation occured, return null
 * @throws JavaModelException
 *             if there is a problem getting the file from the generated Type.
 */
public IFile getGeneratedJavaFile() {
    IFile result = null;
    try {
        IType generated = getCreatedType();
        if (generated != null)
            result = (IFile) generated.getUnderlyingResource();
    } catch (JavaModelException e) {
        UIPlugin.log(e);
    }
    return result;
}