当前位置: 首页>>代码示例>>Java>>正文


Java StringLiteral.getEscapedValue方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.StringLiteral.getEscapedValue方法的典型用法代码示例。如果您正苦于以下问题:Java StringLiteral.getEscapedValue方法的具体用法?Java StringLiteral.getEscapedValue怎么用?Java StringLiteral.getEscapedValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.StringLiteral的用法示例。


在下文中一共展示了StringLiteral.getEscapedValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEscapedStringLiteral

import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private static String getEscapedStringLiteral(String stringValue) {
	StringLiteral stringLiteral= AST.newAST(AST.JLS8).newStringLiteral();
	stringLiteral.setLiteralValue(stringValue);
	return stringLiteral.getEscapedValue();
}
 
开发者ID:Microsoft,项目名称:vsminecraft,代码行数:6,代码来源:JavaElementLabelComposer.java

示例2: calculateProposals

import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
public static List<ICompletionProposal> calculateProposals(final StringLiteral stringLiteral,
		final int documentOffset) throws IOException {
	String escapedValue = stringLiteral.getEscapedValue();
	String literalValue = stringLiteral.getLiteralValue();
	LOG.info("literal value = " + literalValue);
	List<ICompletionProposal> sss = new ArrayList<ICompletionProposal>();
	int fromStart = documentOffset - stringLiteral.getStartPosition();
	if (fromStart < 2) {
		LOG.info("fromStart negative : " + fromStart);
		// first char is "
		fromStart = 2;
	}
	if (fromStart >= escapedValue.length()) {
		LOG.info("fromStart more then length : " + fromStart + " >= " + escapedValue.length());
		fromStart = escapedValue.length() - 1;
	}
	LOG.info("position = " + fromStart);
	List<IContentProposal> vvv = RegExpAllProposals.getProposals(escapedValue, fromStart);
	Collections.reverse(vvv);
	int i = 0;
	for (final IContentProposal iContentProposal : vvv) {
		String content = iContentProposal.getContent();
		if (content.length() == 0) {
			continue;
		}
		// getting escaped value of content
		stringLiteral.setLiteralValue(content);
		String content2 = stringLiteral.getEscapedValue();
		content2 = content2.substring(1, content2.length() - 1);
		int diff = content2.length() - content.length();
		LOG.fine(content2);

		ICompletionProposal completionProposal = new RegExpCompletionProposal(content2, documentOffset, 0,
				iContentProposal.getCursorPosition() + diff, null,
				content + " - " + iContentProposal.getDescription(), null, iContentProposal.getDescription(), i++);

		sss.add(completionProposal);
		i++;
	}

	return sss;
}
 
开发者ID:impetuouslab,项目名称:eclipse-filecompletion,代码行数:43,代码来源:RegExpPatternProposalsCalculator.java

示例3: getPickOutStringProposals

import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private static boolean getPickOutStringProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
	// we work with String's
	if (!(node instanceof StringLiteral)) {
		return false;
	}
	// user should select part of String
	int selectionPos= context.getSelectionOffset();
	int selectionLen= context.getSelectionLength();
	if (selectionLen == 0) {
		return false;
	}
	int valueStart= node.getStartPosition() + 1;
	int valueEnd= node.getStartPosition() + node.getLength() - 1;

	// selection must be inside node and the quotes and not contain the full value
	if (selectionPos < valueStart || selectionPos + selectionLen > valueEnd || valueEnd - valueStart == selectionLen) {
		return false;
	}

	// prepare string parts positions
	StringLiteral stringLiteral= (StringLiteral) node;
	String stringValue= stringLiteral.getEscapedValue();

	int firstPos= selectionPos - node.getStartPosition();
	int secondPos= firstPos + selectionLen;


	// prepare new string literals

	AST ast= node.getAST();
	StringLiteral leftLiteral= ast.newStringLiteral();
	StringLiteral centerLiteral= ast.newStringLiteral();
	StringLiteral rightLiteral= ast.newStringLiteral();
	try {
		leftLiteral.setEscapedValue('"' + stringValue.substring(1, firstPos) + '"');
		centerLiteral.setEscapedValue('"' + stringValue.substring(firstPos, secondPos) + '"');
		rightLiteral.setEscapedValue('"' + stringValue.substring(secondPos, stringValue.length() - 1) + '"');
	} catch (IllegalArgumentException e) {
		return false;
	}
	if (resultingCollections == null) {
		return true;
	}

	ASTRewrite rewrite= ASTRewrite.create(ast);

	// prepare new expression instead of StringLiteral
	InfixExpression expression= ast.newInfixExpression();
	expression.setOperator(InfixExpression.Operator.PLUS);
	if (firstPos != 1) {
		expression.setLeftOperand(leftLiteral);
	}


	if (firstPos == 1) {
		expression.setLeftOperand(centerLiteral);
	} else {
		expression.setRightOperand(centerLiteral);
	}

	if (secondPos < stringValue.length() - 1) {
		if (firstPos == 1) {
			expression.setRightOperand(rightLiteral);
		} else {
			expression.extendedOperands().add(rightLiteral);
		}
	}
	// use new expression instead of old StirngLiteral
	rewrite.replace(stringLiteral, expression, null);
	// add correction proposal
	String label= CorrectionMessages.AdvancedQuickAssistProcessor_pickSelectedString;
	Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
	LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.PICK_SELECTED_STRING, image);
	proposal.addLinkedPosition(rewrite.track(centerLiteral), true, "CENTER_STRING"); //$NON-NLS-1$
	resultingCollections.add(proposal);
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:78,代码来源:AdvancedQuickAssistProcessor.java

示例4: getPickOutStringProposals

import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private static boolean getPickOutStringProposals(IInvocationContext context, ASTNode node, Collection<ICommandAccess> resultingCollections) {
	// we work with String's
	if (!(node instanceof StringLiteral)) {
		return false;
	}
	// user should select part of String
	int selectionPos= context.getSelectionOffset();
	int selectionLen= context.getSelectionLength();
	if (selectionLen == 0) {
		return false;
	}
	int valueStart= node.getStartPosition() + 1;
	int valueEnd= node.getStartPosition() + node.getLength() - 1;

	// selection must be inside node and the quotes and not contain the full value
	if (selectionPos < valueStart || selectionPos + selectionLen > valueEnd || valueEnd - valueStart == selectionLen) {
		return false;
	}

	// prepare string parts positions
	StringLiteral stringLiteral= (StringLiteral) node;
	String stringValue= stringLiteral.getEscapedValue();

	int firstPos= selectionPos - node.getStartPosition();
	int secondPos= firstPos + selectionLen;


	// prepare new string literals

	AST ast= node.getAST();
	StringLiteral leftLiteral= ast.newStringLiteral();
	StringLiteral centerLiteral= ast.newStringLiteral();
	StringLiteral rightLiteral= ast.newStringLiteral();
	try {
		leftLiteral.setEscapedValue('"' + stringValue.substring(1, firstPos) + '"');
		centerLiteral.setEscapedValue('"' + stringValue.substring(firstPos, secondPos) + '"');
		rightLiteral.setEscapedValue('"' + stringValue.substring(secondPos, stringValue.length() - 1) + '"');
	} catch (IllegalArgumentException e) {
		return false;
	}
	if (resultingCollections == null) {
		return true;
	}

	ASTRewrite rewrite= ASTRewrite.create(ast);

	// prepare new expression instead of StringLiteral
	InfixExpression expression= ast.newInfixExpression();
	expression.setOperator(InfixExpression.Operator.PLUS);
	if (firstPos != 1) {
		expression.setLeftOperand(leftLiteral);
	}


	if (firstPos == 1) {
		expression.setLeftOperand(centerLiteral);
	} else {
		expression.setRightOperand(centerLiteral);
	}

	if (secondPos < stringValue.length() - 1) {
		if (firstPos == 1) {
			expression.setRightOperand(rightLiteral);
		} else {
			expression.extendedOperands().add(rightLiteral);
		}
	}
	// use new expression instead of old StirngLiteral
	rewrite.replace(stringLiteral, expression, null);
	// add correction proposal
	String label= CorrectionMessages.AdvancedQuickAssistProcessor_pickSelectedString;
	Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
	LinkedCorrectionProposal proposal= new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image);
	proposal.addLinkedPosition(rewrite.track(centerLiteral), true, "CENTER_STRING"); //$NON-NLS-1$
	resultingCollections.add(proposal);
	return true;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:78,代码来源:AdvancedQuickAssistProcessor.java

示例5: getEscapedStringLiteral

import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
/**
 * Escapes a string value to a literal that can be used in Java source.
 *
 * @param stringValue the string value
 * @return the escaped string
 * @see StringLiteral#getEscapedValue()
 */
public static String getEscapedStringLiteral(String stringValue) {
	StringLiteral stringLiteral= AST.newAST(IASTSharedValues.SHARED_AST_LEVEL).newStringLiteral();
	stringLiteral.setLiteralValue(stringValue);
	return stringLiteral.getEscapedValue();
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:13,代码来源:ASTNodes.java

示例6: getEscapedStringLiteral

import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
/**
 * Escapes a string value to a literal that can be used in Java source.
 *
 * @param stringValue the string value
 * @return the escaped string
 * @see org.eclipse.jdt.core.dom.StringLiteral#getEscapedValue()
 */
public static String getEscapedStringLiteral(String stringValue) {
  StringLiteral stringLiteral = AST.newAST(ASTProvider.SHARED_AST_LEVEL).newStringLiteral();
  stringLiteral.setLiteralValue(stringValue);
  return stringLiteral.getEscapedValue();
}
 
开发者ID:eclipse,项目名称:che,代码行数:13,代码来源:ASTNodes.java

示例7: getEscapedStringLiteral

import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
/**
 * Escapes a string value to a literal that can be used in Java source.
 * 
 * @param stringValue the string value 
 * @return the escaped string
 * @see StringLiteral#getEscapedValue()
 */
public static String getEscapedStringLiteral(String stringValue) {
	StringLiteral stringLiteral= AST.newAST(ASTProvider.SHARED_AST_LEVEL).newStringLiteral();
	stringLiteral.setLiteralValue(stringValue);
	return stringLiteral.getEscapedValue();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:13,代码来源:ASTNodes.java


注:本文中的org.eclipse.jdt.core.dom.StringLiteral.getEscapedValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。