jdtutil.java
来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 96 行
JAVA
96 行
/*
* $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/wizard/JDTUtil.java,v 1.1.1.1 2004/07/01 09:07:54 wang_j Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/07/01 09:07:54 $
*
* ====================================================================
*
* The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
*
* Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
* IT Forest Corporation
* All rights reserved.
*
* This software is the confidential and proprietary information of
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
* You shall not disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into with
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
*/
package com.webpump.ui.wizard;
/*
* (c) Copyright Sysdeo SA 2001, 2002.
* All Rights Reserved.
*/
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
/**
* Utility class for JDT
* It might exist better way to implements those operations,
* or they might already exist in JDT
*/
public class JDTUtil {
/**
* Adds a nature to a project
* (From BuildPathsBlock class)
*/
public static void addNatureToProject(IProject project, String natureId) throws CoreException {
IProject proj = project.getProject(); // Needed if project is a IJavaProject
IProjectDescription description = proj.getDescription();
String[] prevNatures= description.getNatureIds();
int natureIndex = -1;
for (int i=0; i<prevNatures.length; i++) {
if(prevNatures[i].equals(natureId)) {
natureIndex = i;
i = prevNatures.length;
}
}
// Add nature only if it is not already there
if(natureIndex == -1) {
String[] newNatures= new String[prevNatures.length + 1];
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
newNatures[prevNatures.length]= natureId;
description.setNatureIds(newNatures);
proj.setDescription(description, null);
}
}
/**
* Remove a Nature to a Project
*/
public static void removeNatureToProject(IProject project, String natureId) throws CoreException {
IProject proj = project.getProject(); // Needed if project is a IJavaProject
IProjectDescription description = proj.getDescription();
String[] prevNatures= description.getNatureIds();
int natureIndex = -1;
for (int i=0; i<prevNatures.length; i++) {
if(prevNatures[i].equals(natureId)) {
natureIndex = i;
i = prevNatures.length;
}
}
// Remove nature only if it exists...
if(natureIndex != -1) {
String[] newNatures= new String[prevNatures.length - 1];
System.arraycopy(prevNatures, 0, newNatures, 0, natureIndex);
System.arraycopy(prevNatures, natureIndex+1, newNatures, natureIndex, prevNatures.length - (natureIndex+1));
description.setNatureIds(newNatures);
proj.setDescription(description, null);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?