本文整理汇总了Java中org.eclipse.jdt.core.dom.StringLiteral.getLiteralValue方法的典型用法代码示例。如果您正苦于以下问题:Java StringLiteral.getLiteralValue方法的具体用法?Java StringLiteral.getLiteralValue怎么用?Java StringLiteral.getLiteralValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.StringLiteral
的用法示例。
在下文中一共展示了StringLiteral.getLiteralValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateSourceAnnotationValue
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private void validateSourceAnnotationValue(StringLiteral literalNode) throws JavaModelException {
String value = literalNode.getLiteralValue();
// Interpret the literal path as an absolute path, and then as a path
// relative to the containing package (indexing both).
IPath literalPath = new Path(value);
result.addPossibleResourcePath(literalPath);
IPath fullResourcePathIfPackageRelative = getPackagePath(literalNode).append(literalPath);
result.addPossibleResourcePath(fullResourcePathIfPackageRelative);
// If the @Source path was absolute and we found it, great
if (ClasspathResourceUtilities.isResourceOnClasspath(javaProject, literalPath)) {
return;
}
if (!ClasspathResourceUtilities.isResourceOnClasspath(javaProject, fullResourcePathIfPackageRelative)) {
// Didn't work as a relative path either, so now it's an error
IPath expectedResourcePath = computeMissingResourceExpectedPath(literalPath, fullResourcePathIfPackageRelative);
ClientBundleProblem problem = ClientBundleProblem.createMissingResourceFile(literalNode,
literalPath.lastSegment(), expectedResourcePath.removeLastSegments(1));
result.addProblem(problem);
}
}
示例2: traverseMethodParams
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private void traverseMethodParams(MethodDeclaration methodDeclaration) throws IOException {
List parameters = methodDeclaration.parameters();
for (Iterator itParams = parameters.iterator(); itParams.hasNext();) {
SingleVariableDeclaration param = (SingleVariableDeclaration) itParams.next();
ITypeBinding type = param.resolveBinding().getType();
if (hasAnnotation(param.modifiers()) && !type.isPrimitive()) {
SingleMemberAnnotation annotation = getAnnotation(param.modifiers());
Expression value = annotation.getValue();
if (value instanceof StringLiteral) { //@Domain("D")
StringLiteral annotValue = (StringLiteral)value;
String parserInput = annotValue.getLiteralValue();
AnnotationInfo annotInfo = AnnotationInfo.parseAnnotation(parserInput);
DomainParams annot = annotInfo.getAnnotation();
boolean isDom = isDomain(methodDeclaration.resolveBinding().getDeclaringClass(), annot);
boolean isDomPars = isDomainParams(methodDeclaration.resolveBinding().getDeclaringClass(), annot);
ObjectMetricItem archMetricItem = new ObjectMetricItem(param.resolveBinding().getKey(),
param.getName().getFullyQualifiedName(),
param.getType().resolveBinding().getQualifiedName(),
parserInput,
methodDeclaration.resolveBinding().getDeclaringClass().getQualifiedName(),
param.toString(),
Modifier.isStatic(param.getModifiers()),
"MethodParams",
param.resolveBinding().getType().isArray(),
param.resolveBinding().getType().isEnum(),
param.resolveBinding().getType().isParameterizedType(),
isDom,
isDomPars,
annot.isObjectPublicDomain());
if (!objectsHashtable.containsKey(archMetricItem.toString())) {
objectsHashtable.put(archMetricItem.toString(), archMetricItem);
}
// TODO: src.triplets for Method Params
}
}
}
}
示例3: getAnnotationList
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
public List<String> getAnnotationList(List<IExtendedModifier> paramModifiers, String annotation) {
List<String> found = new ArrayList<String>();
for (IExtendedModifier o:paramModifiers){
if (o instanceof SingleMemberAnnotation) {
SingleMemberAnnotation annot = (SingleMemberAnnotation) o;
if (annot.getTypeName().toString().equals(annotation)) {
Expression value = annot.getValue();
if (value instanceof ArrayInitializer) { //@Domains( {"D", "U"})
ArrayInitializer annotValueArray = (ArrayInitializer)value;
found = new ArrayList<String>();
for (Object s:annotValueArray.expressions()){
if (s instanceof StringLiteral) {
StringLiteral sLiteral = (StringLiteral)s;
found.add(sLiteral.getLiteralValue());
}
}
return found;
}
if (value instanceof StringLiteral) { //@Domains ("D")
StringLiteral annotValue = (StringLiteral)value;
String parserInput = annotValue.getLiteralValue();
found = new ArrayList<String>();
found.add(parserInput);
return found;
}
}
}
}
return found;
}
示例4: visit
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
@Override
public boolean visit(VariableDeclarationStatement param) {
ITypeBinding type = param.getType().resolveBinding();
if (hasAnnotation(param.modifiers()) && !type.isPrimitive()) {
List<VariableDeclarationFragment> L = param.fragments();
for (VariableDeclarationFragment oo : L) {
SingleMemberAnnotation annotation = getAnnotation(param.modifiers());
Expression value = annotation.getValue();
if (value instanceof StringLiteral) { //@Domain("D")
StringLiteral annotValue = (StringLiteral)value;
String parserInput = annotValue.getLiteralValue();
AnnotationInfo annotInfo = AnnotationInfo.parseAnnotation(parserInput);
DomainParams annot = annotInfo.getAnnotation();
boolean b = annot.isObjectPublicDomain();
if (b)
{
b = true;
}
boolean isDom = false;
boolean isDomPars = false;
String qualifiedName = "";
// if (oo.resolveBinding().getDeclaringMethod() != null) {
// qualifiedName = oo.resolveBinding().getDeclaringMethod().getDeclaringClass().getQualifiedName();
//
// isDom = isDomain(oo.resolveBinding().getDeclaringMethod().getDeclaringClass(), annot);
// isDomPars = isDomainParams(oo.resolveBinding().getDeclaringMethod().getDeclaringClass(),annot);
//
//
// }
// else
{
qualifiedName = currentType.resolveBinding().getQualifiedName();
isDom = isDomain(currentType.resolveBinding(), annot);
isDomPars = isDomainParams(currentType.resolveBinding() , annot);
}
ObjectMetricItem archMetricItem = new ObjectMetricItem(oo.resolveBinding().getKey(),oo.resolveBinding().getName().toString(),
param.getType().resolveBinding().getQualifiedName().toString(),
parserInput,
qualifiedName,
oo.toString(),
Modifier.isStatic(param.getModifiers()),
"LocalVariable",
type.isArray(),
type.isEnum(),
type.isParameterizedType(),
isDom,
isDomPars,
annot.isObjectPublicDomain()
);
if (!objectsHashtable.containsKey(archMetricItem.toString())) {
objectsHashtable.put(archMetricItem.toString(), archMetricItem);
}
// TODO: src.triplets for Local variables
}
}
}
return super.visit(param);
}
示例5: addUnknownSuppressWarningProposals
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
/**
* Adds a proposal to correct the name of the SuppressWarning annotation
*
* @param context the context
* @param problem the problem
* @param proposals the resulting proposals
*/
public static void addUnknownSuppressWarningProposals(
IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode coveringNode = context.getCoveringNode();
if (!(coveringNode instanceof StringLiteral)) return;
AST ast = coveringNode.getAST();
StringLiteral literal = (StringLiteral) coveringNode;
String literalValue = literal.getLiteralValue();
String[] allWarningTokens = CorrectionEngine.getAllWarningTokens();
for (int i = 0; i < allWarningTokens.length; i++) {
String curr = allWarningTokens[i];
if (NameMatcher.isSimilarName(literalValue, curr)) {
StringLiteral newLiteral = ast.newStringLiteral();
newLiteral.setLiteralValue(curr);
ASTRewrite rewrite = ASTRewrite.create(ast);
rewrite.replace(literal, newLiteral, null);
String label =
Messages.format(
CorrectionMessages.SuppressWarningsSubProcessor_fix_suppress_token_label,
new String[] {curr});
Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal =
new ASTRewriteCorrectionProposal(
label,
context.getCompilationUnit(),
rewrite,
IProposalRelevance.FIX_SUPPRESS_TOKEN,
image);
proposals.add(proposal);
}
}
addRemoveUnusedSuppressWarningProposals(context, problem, proposals);
}
示例6: retrieveVariableReference
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private VariableReference retrieveVariableReference(StringLiteral stringLiteral) {
String string = stringLiteral.getLiteralValue();
PrimitiveStatement<String> stringAssignment = new StringPrimitiveStatement(
testCase.getReference(), string);
testCase.addStatement(stringAssignment);
return stringAssignment.getReturnValue();
}
示例7: addUnknownSuppressWarningProposals
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
/**
* Adds a proposal to correct the name of the SuppressWarning annotation
* @param context the context
* @param problem the problem
* @param proposals the resulting proposals
*/
public static void addUnknownSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode coveringNode= context.getCoveringNode();
if (!(coveringNode instanceof StringLiteral))
return;
AST ast= coveringNode.getAST();
StringLiteral literal= (StringLiteral) coveringNode;
String literalValue= literal.getLiteralValue();
String[] allWarningTokens= CorrectionEngine.getAllWarningTokens();
for (int i= 0; i < allWarningTokens.length; i++) {
String curr= allWarningTokens[i];
if (NameMatcher.isSimilarName(literalValue, curr)) {
StringLiteral newLiteral= ast.newStringLiteral();
newLiteral.setLiteralValue(curr);
ASTRewrite rewrite= ASTRewrite.create(ast);
rewrite.replace(literal, newLiteral, null);
String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_fix_suppress_token_label, new String[] { curr });
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.FIX_SUPPRESS_TOKEN, image);
proposals.add(proposal);
}
}
addRemoveUnusedSuppressWarningProposals(context, problem, proposals);
}
示例8: addUnknownSuppressWarningProposals
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
/**
* Adds a proposal to correct the name of the SuppressWarning annotation
* @param context the context
* @param problem the problem
* @param proposals the resulting proposals
*/
public static void addUnknownSuppressWarningProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode coveringNode= context.getCoveringNode();
if (!(coveringNode instanceof StringLiteral))
return;
AST ast= coveringNode.getAST();
StringLiteral literal= (StringLiteral) coveringNode;
String literalValue= literal.getLiteralValue();
String[] allWarningTokens= CorrectionEngine.getAllWarningTokens();
for (int i= 0; i < allWarningTokens.length; i++) {
String curr= allWarningTokens[i];
if (NameMatcher.isSimilarName(literalValue, curr)) {
StringLiteral newLiteral= ast.newStringLiteral();
newLiteral.setLiteralValue(curr);
ASTRewrite rewrite= ASTRewrite.create(ast);
rewrite.replace(literal, newLiteral, null);
String label= Messages.format(CorrectionMessages.SuppressWarningsSubProcessor_fix_suppress_token_label, new String[] { curr });
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 5, image);
proposals.add(proposal);
}
}
addRemoveUnusedSuppressWarningProposals(context, problem, proposals);
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:33,代码来源:SuppressWarningsSubProcessor.java
示例9: visit
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
@Override
// finds all string literals in a method argument or similar
public boolean visit(StringLiteral node) {
if (!(node.getParent() instanceof MethodInvocation)) { // if a StringLiteral is not in a method invocation, we don't care about it (e.g. ternary
return false;
}
String literalValue = node.getLiteralValue();
if (literalValue.length() == 1) {
replacements.put(node, literalValue.charAt(0));
}
return false;
}
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:14,代码来源:UseCharacterParameterizedMethodResolution.java
示例10: createLiteralMarkerAttrs
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private Map<String, Object> createLiteralMarkerAttrs(StringLiteral literal, String property,
int position, boolean singleProperty) {
String literalValue = literal.getLiteralValue();
int clearRangeStart = 0, clearRangeEnd = 0;
if (singleProperty) {
clearRangeStart = position;
clearRangeEnd = position + property.length();
} else {
int lastComma = literalValue.substring(0, position).lastIndexOf(',');
if (lastComma != -1) {
clearRangeStart = lastComma;
clearRangeEnd = position + property.length();
} else {
int nextComma = literalValue.indexOf(',', position);
if (nextComma != -1) {
clearRangeStart = position;
clearRangeEnd = nextComma + 1;
}
}
}
int startPosition = literal.getStartPosition() + 1;
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put(IMarker.CHAR_START, startPosition + position);
attributes.put(IMarker.CHAR_END, startPosition + position + property.length());
attributes.put(IMarker.SEVERITY, prefs.getScopeStringErrorSeverity());
if (clearRangeEnd != 0) {
attributes.put(ScopeStringConstants.MARKER_ATTR_CLEAR_RANGE_START, startPosition
+ clearRangeStart);
attributes.put(ScopeStringConstants.MARKER_ATTR_CLEAR_RANGE_END, startPosition
+ clearRangeEnd);
}
return attributes;
}
示例11: traverseMethodReturn
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private void traverseMethodReturn(MethodDeclaration methodDeclaration) throws IOException {
Type returnType2 = methodDeclaration.getReturnType2();
if (returnType2 != null) {
ITypeBinding resolveBinding = returnType2.resolveBinding();
noMethods++;
if (resolveBinding.getName().equals("void")) noVoidReturnTypes++;
if (hasAnnotation(methodDeclaration.modifiers()) && !resolveBinding.isPrimitive()) {
SingleMemberAnnotation annotation = getAnnotation(methodDeclaration.modifiers());
Expression value = annotation.getValue();
if (value instanceof StringLiteral) { //@Domain("D")
StringLiteral annotValue = (StringLiteral)value;
String parserInput = annotValue.getLiteralValue();
AnnotationInfo annotInfo = AnnotationInfo.parseAnnotation(parserInput);
DomainParams annot = annotInfo.getAnnotation();
boolean isDom = isDomain(methodDeclaration.resolveBinding().getDeclaringClass(), annot);
boolean isDomPars = isDomainParams(methodDeclaration.resolveBinding().getDeclaringClass(), annot);
ObjectMetricItem archMetricItem = new ObjectMetricItem(methodDeclaration.resolveBinding().getKey(),
methodDeclaration.getName().getFullyQualifiedName(),
resolveBinding.getQualifiedName(),
parserInput,
methodDeclaration.resolveBinding().getDeclaringClass().getQualifiedName(),
returnType2.toString(),
Modifier.isStatic(methodDeclaration.getModifiers()),
"ReturnType",
returnType2.resolveBinding().isArray(),
returnType2.resolveBinding().isEnum(),
returnType2.resolveBinding().isParameterizedType(),
isDom,
isDomPars,
annot.isObjectPublicDomain());
if (!objectsHashtable.containsKey(archMetricItem.toString())) {
objectsHashtable.put(archMetricItem.toString(), archMetricItem);
}
// TODO: src.triplets for MethodReturn type
}
}
}
}
示例12: traverseFields
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
private void traverseFields(TypeDeclaration declaration) {
FieldDeclaration[] fieldDeclarations = declaration.getFields();
for (int i = 0; i < fieldDeclarations.length; i++) {
FieldDeclaration fieldDeclaration = fieldDeclarations[i];
ITypeBinding type = fieldDeclaration.getType().resolveBinding();
if (hasAnnotation(fieldDeclaration.modifiers()) && !type.isPrimitive()) {
List ff = fieldDeclaration.fragments();
for (Object ff1 : ff) {
VariableDeclaration V = (VariableDeclaration) ff1;
String key = V.resolveBinding().getKey();
String name = V.getName().getIdentifier();
String objectType = fieldDeclaration.getType().resolveBinding().getQualifiedName();
String enclosingType = declaration.resolveBinding().getQualifiedName();
String ast = fieldDeclaration.getAST().toString();
boolean isStatic = Modifier.isStatic(fieldDeclaration.getModifiers());
//
SingleMemberAnnotation annotation = getAnnotation(fieldDeclaration.modifiers());
Expression value = annotation.getValue();
if (value instanceof StringLiteral) { //@Domain("D")
StringLiteral annotValue = (StringLiteral)value;
String parserInput = annotValue.getLiteralValue();
AnnotationInfo annotInfo = AnnotationInfo.parseAnnotation(parserInput);
DomainParams annot = annotInfo.getAnnotation();
boolean isDomainParam = isDomainParams(declaration.resolveBinding(), annot);
boolean isDomain = isDomain(declaration.resolveBinding(), annot);
ObjectMetricItem archMetricItem = new ObjectMetricItem(key,name,
objectType,
parserInput,
enclosingType,
ast,
isStatic,
"Field",
type.isArray(),
type.isEnum(),
type.isParameterizedType(),
isDomain,
isDomainParam,
annot.isObjectPublicDomain()
);
// TODO: Do we need the following two lines?
archMetricItem.setDomainParams(isDomainParam);
archMetricItem.setDomain(isDomain);
if (!objectsHashtable.containsKey(archMetricItem.toString())) {
objectsHashtable.put(archMetricItem.toString(), archMetricItem);
}
// TODO: src.triplets for Field
}
else
{
//this should not happen
System.out.println("Error in field declaration: "+ value);
}
}
}
}
}
示例13: openFile
import org.eclipse.jdt.core.dom.StringLiteral; //导入方法依赖的package包/类
public static void openFile(ExecutionEvent event, boolean inEclipse) throws ExecutionException {
LOG.info("execute " + event);
LOG.info("execute " + event.getCommand());
LOG.info("execute " + event.getTrigger());
LOG.info("execute " + event.getApplicationContext());
// event.getTrigger().
try {
LOG.fine("stating proposal");
Event event2 = (Event) event.getTrigger();
LOG.info("widget" + event2.widget);
IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage();
IEditorPart compilationUnit = workbenchPage.getActiveEditor();
IEditorInput editorInput = compilationUnit.getEditorInput();
Object adapter = editorInput.getAdapter(IJavaElement.class);
IEditorPart activeEditor = workbenchPage.getActiveEditor();
if (activeEditor instanceof org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor) {
LOG.info("we are in java editor ");
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor cue = (org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor) activeEditor;
int documentOffset = cue.getViewer().getSelectedRange().x;
if (adapter == null) {
LOG.info("adapter is null");
} else if (adapter instanceof ICompilationUnit) {
ICompilationUnit cu = (ICompilationUnit) adapter;
LOG.fine("we found CompilationUnit");
String source = cu.getSource();
if (FileCompletionImpl.isInStringLiteral(source, documentOffset)) {
FileClassFinder findStringLiteral = FileCompletionImpl.findStringLiteral(source,
documentOffset);
if (findStringLiteral.isFile()) {
StringLiteral fileProposals = findStringLiteral.getFoundedNode();
if (fileProposals == null) {
LOG.info("looks like not in string literal");
} else {
String literalValue = fileProposals.getLiteralValue();
literalValue = literalValue.replace('\\', '/');
File file = new File(literalValue);
if (file.exists()) {
if (inEclipse) {
openFileInEclipse(file);
} else {
openFileInExternalProgram(file);
}
} else {
MessageDialog.openError(null, "File not found",
"File not found: " + file.getAbsolutePath());
}
}
} else {
LOG.info("found but not it is not file");
}
} else {
LOG.info("not in string literal");
}
}
}
} catch (Exception e) {
LOG.log(Level.SEVERE, "error during opening file", e);
MessageDialog.openError(null, "File open error", e + "");
}
}
示例14: 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;
}