Changeset 3569 for devel-tools/trunk


Ignore:
Timestamp:
Mar 25, 2008, 4:49:35 PM (13 years ago)
Author:
yura
Message:
  • Refactoring: checks for null.
Location:
devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core/RfpCore.java

    r3561 r3569  
    44
    55import org.eclipse.core.resources.IProject;
    6 import org.eclipse.core.runtime.CoreException;
    76import org.eclipse.core.runtime.IStatus;
    87import org.eclipse.core.runtime.Plugin;
    98import org.eclipse.core.runtime.Status;
    10 import org.eclipse.jdt.core.JavaCore;
    119
    1210/**
     
    4543    }
    4644
    47     /** May return <code>null</code>. */
     45    /** May return <code>null</code> if argument is <code>null</code>. */
    4846    public static RfpProject getRfpProject (IProject project) {
    49         try {
    50             if (project == null || !project.exists() || !project.hasNature(NATURE_ID)
    51                     || !project.hasNature(JavaCore.NATURE_ID))
    52                 return null;
    53         } catch (CoreException e) {
    54             log(e);
     47        if (project == null)
    5548            return null;
    56         }
    5749        RfpProject rfpProject = RfpCore.rfpProjects.get(project);
    5850        if (rfpProject == null) {
  • devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core/RfpNature.java

    r3524 r3569  
    2020
    2121    public void configure () throws CoreException {
    22         IProjectDescription desc = project.getDescription();
    23         ICommand[] commands = desc.getBuildSpec();
     22        // setup builder
     23        IProjectDescription projectDesc = project.getDescription();
     24        ICommand[] commands = projectDesc.getBuildSpec();
    2425        for (ICommand command : commands)
    25             if (command.getBuilderName().equals(RfpCore.BUILDER_ID))
     26            if (RfpCore.BUILDER_ID.equals(command.getBuilderName()))
    2627                return;
    2728        ICommand[] newCommands = new ICommand[commands.length + 1];
    2829        System.arraycopy(commands, 0, newCommands, 0, commands.length);
    29         ICommand command = desc.newCommand();
     30        ICommand command = projectDesc.newCommand();
    3031        command.setBuilderName(RfpCore.BUILDER_ID);
    3132        newCommands[commands.length] = command;
    32         desc.setBuildSpec(newCommands);
    33         project.setDescription(desc, null);
    34         { // setup the .classpath
    35             IJavaProject javaProject = RfpCore.getRfpProject(project).getJavaProject();
    36             IClasspathEntry[] entriesOld = javaProject.getRawClasspath();
    37             IClasspathEntry[] entriesNew = new IClasspathEntry[entriesOld.length + 2];
    38             System.arraycopy(entriesOld, 0, entriesNew, 0, entriesOld.length);
    39             for (int i = 0; i < entriesOld.length; i++)
    40                 if (entriesOld[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
    41                     IFolder src = project.getFolder("src");
    42                     if (!src.exists())
    43                         src.create(true, true, null);
    44                     entriesNew[i] = JavaCore.newSourceEntry(src.getFullPath());
    45                 }
    46             entriesNew[entriesOld.length + 0] = JavaCore.newContainerEntry(new Path(RfpCore.RFP_CONTAINER));
    47             entriesNew[entriesOld.length + 1] = JavaCore.newContainerEntry(new Path(JavaRuntime.JRE_CONTAINER));
    48             javaProject.setRawClasspath(entriesNew, null);
    49             String filters = javaProject.getOption(EXCLUSION_FILTER_ID, true);
    50             if (filters == null)
    51                 filters = "";
    52             else if (!filters.equals(""))
    53                 filters += ",";
    54             filters += EXCLUSION_EXTENTIONS;
    55             javaProject.setOption(EXCLUSION_FILTER_ID, filters);
    56             javaProject.save(null, true);
    57         }
     33        projectDesc.setBuildSpec(newCommands);
     34        project.setDescription(projectDesc, null);
     35        // setup the classpath
     36        IJavaProject javaProject = RfpCore.getRfpProject(project).getJavaProject();
     37        IClasspathEntry[] entriesOld = javaProject.getRawClasspath();
     38        IClasspathEntry[] entriesNew = new IClasspathEntry[entriesOld.length + 2];
     39        System.arraycopy(entriesOld, 0, entriesNew, 0, entriesOld.length);
     40        for (int i = 0; i < entriesOld.length; i++)
     41            if (entriesOld[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
     42                IFolder src = project.getFolder("src");
     43                if (!src.exists())
     44                    src.create(true, true, null);
     45                entriesNew[i] = JavaCore.newSourceEntry(src.getFullPath());
     46            }
     47        entriesNew[entriesOld.length + 0] = JavaCore.newContainerEntry(new Path(RfpCore.RFP_CONTAINER));
     48        entriesNew[entriesOld.length + 1] = JavaCore.newContainerEntry(new Path(JavaRuntime.JRE_CONTAINER));
     49        javaProject.setRawClasspath(entriesNew, null);
     50        // setup exclusion filter for coping files to output folder
     51        String filters = javaProject.getOption(EXCLUSION_FILTER_ID, true);
     52        if (filters == null)
     53            filters = "";
     54        else if (!filters.equals(""))
     55            filters += ",";
     56        filters += EXCLUSION_EXTENTIONS;
     57        javaProject.setOption(EXCLUSION_FILTER_ID, filters);
     58        javaProject.save(null, true);
    5859    }
    5960
    6061    public void deconfigure () throws CoreException {
    61         IProjectDescription description = getProject().getDescription();
    62         ICommand[] commands = description.getBuildSpec();
     62        IProjectDescription projectDesc = getProject().getDescription();
     63        ICommand[] commands = projectDesc.getBuildSpec();
    6364        for (int i = 0; i < commands.length; i++)
    64             if (commands[i].getBuilderName().equals(RfpCore.BUILDER_ID)) {
     65            if (RfpCore.BUILDER_ID.equals(commands[i].getBuilderName())) {
    6566                ICommand[] newCommands = new ICommand[commands.length - 1];
    6667                System.arraycopy(commands, 0, newCommands, 0, i);
    6768                System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1);
    68                 description.setBuildSpec(newCommands);
    69                 return;
     69                projectDesc.setBuildSpec(newCommands);
     70                break;
    7071            }
    7172    }
Note: See TracChangeset for help on using the changeset viewer.