當前位置: 首頁>>代碼示例>>Java>>正文


Java ICompilationUnit.getWorkingCopy方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.ICompilationUnit.getWorkingCopy方法的典型用法代碼示例。如果您正苦於以下問題:Java ICompilationUnit.getWorkingCopy方法的具體用法?Java ICompilationUnit.getWorkingCopy怎麽用?Java ICompilationUnit.getWorkingCopy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.ICompilationUnit的用法示例。


在下文中一共展示了ICompilationUnit.getWorkingCopy方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createPreparedCU

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
private static ICompilationUnit createPreparedCU(ICompilationUnit cu, Javadoc comment, int wordStart) throws JavaModelException {
	int startpos= comment.getStartPosition();
	boolean isTopLevel= comment.getParent().getParent() instanceof CompilationUnit;
	char[] content= cu.getBuffer().getCharacters().clone();
	if (isTopLevel && (wordStart + 6 < content.length)) {
		content[startpos++]= 'i'; content[startpos++]= 'm'; content[startpos++]= 'p';
		content[startpos++]= 'o'; content[startpos++]= 'r'; content[startpos++]= 't';
	}
	if (wordStart < content.length) {
		for (int i= startpos; i < wordStart; i++) {
			content[i]= ' ';
		}
	}

	/*
	 * Explicitly create a new non-shared working copy.
	 */
	ICompilationUnit newCU= cu.getWorkingCopy(null);
	newCU.getBuffer().setContents(content);
	return newCU;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:22,代碼來源:SimilarElementsRequestor.java

示例2: formatUnitSourceCode

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
/**
 * Format a Unit Source Code
 * 
 * @param testInterface
 * @param monitor
 * @throws CoreException 
 */
@SuppressWarnings("unchecked")
public static void formatUnitSourceCode(IFile file, IProgressMonitor monitor) throws CoreException {
	@SuppressWarnings("rawtypes")
	SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
	ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
	subMonitor.split(50);
	ICompilationUnit workingCopy = unit.getWorkingCopy(monitor);

	Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();

	options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
	options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
	options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);

	options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
			DefaultCodeFormatterConstants.createAlignmentValue(true,
					DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
					DefaultCodeFormatterConstants.INDENT_ON_COLUMN));

	final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
	ISourceRange range = unit.getSourceRange();
	TextEdit formatEdit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, unit.getSource(),
			range.getOffset(), range.getLength(), 0, null);
	subMonitor.split(30);
	if (formatEdit != null /* && formatEdit.hasChildren()*/) {
		workingCopy.applyTextEdit(formatEdit, monitor);
		workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
		workingCopy.commitWorkingCopy(true, null);
		workingCopy.discardWorkingCopy();
	}
	file.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
	subMonitor.split(20);
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:41,代碼來源:JDTManager.java

示例3: updatePathGenerator

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
public static void updatePathGenerator (IFile ifile, String oldPathGenerator,String newPathGenerator) throws CoreException {
	ICompilationUnit cu = JavaCore.createCompilationUnitFrom(ifile);
	 
	ICompilationUnit workingCopy = cu.getWorkingCopy(new NullProgressMonitor());
	
	IBuffer buffer = ((IOpenable)workingCopy).getBuffer();
	String source = buffer.getContents();
	int start = source.indexOf(oldPathGenerator);
	buffer.replace(start, oldPathGenerator.length(), newPathGenerator);
	workingCopy.reconcile(ICompilationUnit.NO_AST, false, workingCopy.getOwner(), new NullProgressMonitor());
    workingCopy.commitWorkingCopy(true, null);
    workingCopy.discardWorkingCopy();
    
    ifile.touch(new NullProgressMonitor ());
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:16,代碼來源:SourceHelper.java

示例4: getWorkingCopy

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
protected ICompilationUnit getWorkingCopy(String path, String source) throws JavaModelException {
	ICompilationUnit workingCopy = getCompilationUnit(path);
	workingCopy.getWorkingCopy(wcOwner, monitor);
	workingCopy.getBuffer().setContents(source);
	workingCopy.makeConsistent(monitor);
	return workingCopy;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:8,代碼來源:AbstractCompilationUnitBasedTest.java

示例5: getStaticImportFavorites

import org.eclipse.jdt.core.ICompilationUnit; //導入方法依賴的package包/類
public static String[] getStaticImportFavorites(ICompilationUnit cu, final String elementName, boolean isMethod, String[] favorites) throws JavaModelException {
	StringBuffer dummyCU= new StringBuffer();
	String packName= cu.getParent().getElementName();
	IType type= cu.findPrimaryType();
	if (type == null) {
		return new String[0];
	}

	if (packName.length() > 0) {
		dummyCU.append("package ").append(packName).append(';'); //$NON-NLS-1$
	}
	dummyCU.append("public class ").append(type.getElementName()).append("{\n static {\n").append(elementName); // static initializer  //$NON-NLS-1$//$NON-NLS-2$
	int offset= dummyCU.length();
	dummyCU.append("\n}\n }"); //$NON-NLS-1$

	ICompilationUnit newCU= null;
	try {
		newCU= cu.getWorkingCopy(null);
		newCU.getBuffer().setContents(dummyCU.toString());

		final HashSet<String> result= new HashSet<>();

		CompletionRequestor requestor= new CompletionRequestor(true) {
			@Override
			public void accept(CompletionProposal proposal) {
				if (elementName.equals(new String(proposal.getName()))) {
					CompletionProposal[] requiredProposals= proposal.getRequiredProposals();
					for (int i= 0; i < requiredProposals.length; i++) {
						CompletionProposal curr= requiredProposals[i];
						if (curr.getKind() == CompletionProposal.METHOD_IMPORT || curr.getKind() == CompletionProposal.FIELD_IMPORT) {
							result.add(JavaModelUtil.concatenateName(Signature.toCharArray(curr.getDeclarationSignature()), curr.getName()));
						}
					}
				}
			}
		};

		if (isMethod) {
			requestor.setIgnored(CompletionProposal.METHOD_REF, false);
			requestor.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true);
		} else {
			requestor.setIgnored(CompletionProposal.FIELD_REF, false);
			requestor.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true);
		}
		requestor.setFavoriteReferences(favorites);

		newCU.codeComplete(offset, requestor);

		return result.toArray(new String[result.size()]);
	} finally {
		if (newCU != null) {
			newCU.discardWorkingCopy();
		}
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:56,代碼來源:SimilarElementsRequestor.java


注:本文中的org.eclipse.jdt.core.ICompilationUnit.getWorkingCopy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。