List of usage examples for org.eclipse.jdt.core.dom StringLiteral getParent
public final ASTNode getParent()
null
if this is the root node. From source file:org.eclipse.babel.tapiji.tools.java.visitor.ResourceAuditVisitor.java
License:Open Source License
@Override public boolean visit(StringLiteral stringLiteral) { try {/* w w w . j ava 2s.com*/ ASTNode parent = stringLiteral.getParent(); ResourceBundleManager manager = ResourceBundleManager.getManager(projectName); if (manager == null) { return false; } if (parent instanceof MethodInvocation) { MethodInvocation methodInvocation = (MethodInvocation) parent; IRegion region = new Region(stringLiteral.getStartPosition(), stringLiteral.getLength()); // Check if this method invokes the getString-Method on a // ResourceBundle Implementation if (ASTutils.isMatchingMethodParamDesc(methodInvocation, stringLiteral, ASTutils.getRBAccessorDesc())) { // Check if the given Resource-Bundle reference is broken SLLocation rbName = ASTutils.resolveResourceBundleLocation(methodInvocation, ASTutils.getRBDefinitionDesc(), variableBindingManagers); if (rbName == null || manager.isKeyBroken(rbName.getLiteral(), stringLiteral.getLiteralValue())) { // report new problem SLLocation desc = new SLLocation(file, stringLiteral.getStartPosition(), stringLiteral.getStartPosition() + stringLiteral.getLength(), stringLiteral.getLiteralValue()); desc.setData(rbName); brokenStrings.add(desc); } // store position of resource-bundle access keyPositions.put(Long.valueOf(stringLiteral.getStartPosition()), region); bundleKeys.put(region, stringLiteral.getLiteralValue()); bundleReferences.put(region, rbName.getLiteral()); return false; } else if (ASTutils.isMatchingMethodParamDesc(methodInvocation, stringLiteral, ASTutils.getRBDefinitionDesc())) { rbDefReferences.put(Long.valueOf(stringLiteral.getStartPosition()), region); boolean referenceBroken = true; for (String bundle : manager.getResourceBundleIdentifiers()) { if (bundle.trim().equals(stringLiteral.getLiteralValue())) { referenceBroken = false; } } if (referenceBroken) { this.brokenRBReferences.add(new SLLocation(file, stringLiteral.getStartPosition(), stringLiteral.getStartPosition() + stringLiteral.getLength(), stringLiteral.getLiteralValue())); } return false; } } // check if string is followed by a "$NON-NLS$" line comment if (ASTutils.existsNonInternationalisationComment(stringLiteral)) { return false; } // constant string literal found constants.add(new SLLocation(file, stringLiteral.getStartPosition(), stringLiteral.getStartPosition() + stringLiteral.getLength(), stringLiteral.getLiteralValue())); } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:org.eclipse.wst.xml.search.editor.statics.JavaStringLiteralDocumentVisitor.java
License:Open Source License
protected ASTNode accept(StringLiteral node) { ASTNode parent = node.getParent(); return (parent != null && parent.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION ? parent : null); }
From source file:org.eclipselabs.javainterpreter.ExpressionVisitor.java
License:Open Source License
@Override public boolean visit(StringLiteral node) { ASTNode parent = node.getParent(); if (parent == null) result = node.getLiteralValue(); else if (isMethodTarget(node)) methodTarget.put((MethodInvocation) parent, node.getLiteralValue()); else/*from w w w. j av a2 s .c om*/ argsTable.get(parent).add(node.getLiteralValue()); return true; }