List of usage examples for org.eclipse.jdt.core.dom Name isQualifiedName
public final boolean isQualifiedName()
QualifiedName
). From source file:ch.acanda.eclipse.pmd.java.resolution.SuppressWarningsQuickFix.java
License:Open Source License
private Annotation findExistingSuppressWarningsAnnotation(final List<IExtendedModifier> modifiers) { for (final IExtendedModifier modifier : modifiers) { if (modifier.isAnnotation()) { final Annotation annotation = (Annotation) modifier; final Name typeName = annotation.getTypeName(); if (typeName.isSimpleName() && "SuppressWarnings".equals(typeName.getFullyQualifiedName()) || typeName.isQualifiedName() && "java.lang.SuppressWarnings".equals(typeName.getFullyQualifiedName())) { return annotation; }/*w w w . ja v a 2 s . c om*/ } } return null; }
From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReversePackage_JavaTypes.java
License:Open Source License
/** * @throws CodeSyncException /*from ww w. j ava 2 s .c o m*/ * @flowerModelElementId _IFwlserfEd6QaI9daHlzjA */ @SuppressWarnings("unchecked") @Override protected ReverseStatus reverseElement(Type modelElement, FileAndAST<CompilationUnit> astElement) throws CodeSyncException { ReverseStatus status = new ReverseStatus(); TypeDeclaration typeDeclaration = JavaSyncUtils.getMasterClass(astElement.getAstElement()); getFullyQualifiedImports().clear(); for (ImportDeclaration id : (List<ImportDeclaration>) astElement.getAstElement().imports()) { Name importedName = id.getName(); SimpleName name; if (importedName.isQualifiedName()) { name = ((QualifiedName) importedName).getName(); } else { name = (SimpleName) importedName; } getFullyQualifiedImports().put(name.toString(), importedName.getFullyQualifiedName()); } if (typeDeclaration.isInterface()) { reverseJavaInterface.currentElement = modelElement; status.applyOr(reverseJavaInterface.reverse((Interface) modelElement, astElement.getAstElement())); reverseJavaInterface.currentElement = null; } else { reverseJavaClass.currentElement = modelElement; status.applyOr(reverseJavaClass.reverse((org.eclipse.uml2.uml.Class) modelElement, astElement.getAstElement())); reverseJavaClass.currentElement = null; } updateSynchronizationTimeStamp(modelElement, astElement); return status; }
From source file:com.google.gdt.eclipse.core.JavaASTUtils.java
License:Open Source License
@SuppressWarnings("unchecked") public static boolean hasSuppressWarnings(BodyDeclaration decl, String warningType) { List<IExtendedModifier> modifiers = decl.modifiers(); for (IExtendedModifier modifier : modifiers) { if (modifier.isAnnotation()) { assert (modifier instanceof Annotation); Annotation annotation = (Annotation) modifier; // Get the (simple) type name of the annotation (we can't resolve the // annotation's type if binding resolution is disabled on our AST). Name annotationType = annotation.getTypeName(); if (annotationType.isQualifiedName()) { annotationType = ((QualifiedName) annotationType).getName(); }/* w w w. j a va2 s .co m*/ assert (annotationType.isSimpleName()); String annotationTypeName = ((SimpleName) annotationType).getIdentifier(); // Look for @SuppressWarnings annotations if (annotationTypeName.equals(SuppressWarnings.class.getSimpleName())) { // Now extract the parameter representing the set of warnings that // should be suppressed if (annotation instanceof SingleMemberAnnotation) { SingleMemberAnnotation suppressWarnings = (SingleMemberAnnotation) annotation; Expression annotationValue = suppressWarnings.getValue(); return containsAnnotationValue(annotationValue, warningType); } else if (annotation instanceof NormalAnnotation) { NormalAnnotation suppressWarnings = (NormalAnnotation) annotation; List<MemberValuePair> annotationValues = suppressWarnings.values(); for (MemberValuePair annotationValue : annotationValues) { SimpleName annotationValueName = annotationValue.getName(); if (annotationValueName.getIdentifier().equals("value")) { return containsAnnotationValue(annotationValue.getValue(), warningType); } } } return false; } } } return false; }
From source file:com.intel.ide.eclipse.mpt.ast.UnresolvedElementsSubProcessor.java
License:Open Source License
public static void importNotFoundProposals(IInvocationContext context, IProblemLocation problem, Map<String, LinkedCorrectionProposal> proposals) throws CoreException { ICompilationUnit cu = context.getCompilationUnit(); ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot()); if (selectedNode == null) { return;/*w w w . jav a 2s. c o m*/ } ImportDeclaration importDeclaration = (ImportDeclaration) ASTNodes.getParent(selectedNode, ASTNode.IMPORT_DECLARATION); if (importDeclaration == null) { return; } if (!importDeclaration.isOnDemand()) { Name name = importDeclaration.getName(); if (importDeclaration.isStatic() && name.isQualifiedName()) { name = ((QualifiedName) name).getQualifier(); } int kind = JavaModelUtil.is50OrHigher(cu.getJavaProject()) ? SimilarElementsRequestor.REF_TYPES : SimilarElementsRequestor.CLASSES | SimilarElementsRequestor.INTERFACES; UnresolvedElementsSubProcessor.addNewTypeProposals(cu, name, kind, IProposalRelevance.IMPORT_NOT_FOUND_NEW_TYPE, proposals); } }
From source file:de.akra.idocit.java.services.JavaInterfaceParser.java
License:Apache License
/** * Create the list of thrown exceptions. The list is wrapped in {@link JavaParameters} * ./*www . ja v a2 s . co m*/ * * @param parent * The parent {@link SignatureElement}. * @param thrownExceptions * The {@link List} of {@link SimpleName} of the thrown exceptions to * process. * @return a new {@link JavaParameters}. */ private JavaParameters processThrownExceptions(final SignatureElement parent, final List<Name> thrownExceptions) { final JavaParameters exceptions = new JavaParameters(parent, Constants.CATEGORY_THROWS, Numerus.SINGULAR, false); exceptions.setDocumentationAllowed(false); exceptions.setIdentifier(StringUtils.EMPTY); exceptions.setQualifiedIdentifier(StringUtils.EMPTY); for (Name name : thrownExceptions) { final ITypeBinding typeBinding = name.resolveTypeBinding(); final JavaParameter exception = new JavaParameter(exceptions, reflectionHelper.deriveNumerus(typeBinding), reflectionHelper.hasPublicAccessableAttributes(typeBinding)); if (typeBinding != null) { // TODO should be the inner structure of Exceptions be // documentable? It // might be make sense for custom Exceptions. exception.setIdentifier(typeBinding.getName()); exception.setQualifiedIdentifier(typeBinding.getQualifiedName()); exception.setDataTypeName(typeBinding.getName()); exception.setQualifiedDataTypeName(typeBinding.getQualifiedName()); } else { String identifier; final String qIdentifier = name.getFullyQualifiedName(); if (name.isQualifiedName()) { final QualifiedName qName = (QualifiedName) name; identifier = qName.getName().getIdentifier(); } else { final SimpleName sName = (SimpleName) name; identifier = sName.getIdentifier(); } exception.setIdentifier(identifier); exception.setQualifiedIdentifier(qIdentifier); exception.setDataTypeName(identifier); exception.setQualifiedDataTypeName(qIdentifier); } SignatureElementUtils.setParametersPaths(delimiters, exceptions.getQualifiedIdentifier(), exception); exceptions.addParameter(exception); } return exceptions; }
From source file:edu.washington.cs.cupid.scripting.java.quickfix.ClasspathProcessor.java
License:Open Source License
private List<IJavaCompletionProposal> buildImportNotFoundProposals(final IInvocationContext context, final IProblemLocation location) { List<IJavaCompletionProposal> proposals = Lists.newArrayList(); ImportDeclaration dec = parentImport(context.getCoveringNode()); if (dec != null) { if (!dec.isOnDemand() && !dec.isStatic()) { Name name = ((QualifiedName) dec.getName()); Bundle bundle = null;/*from w w w . jav a 2s . co m*/ // TODO use ClasspathUtil.bundleForClass here? do { bundle = Platform.getBundle(name.getFullyQualifiedName()); name = ((QualifiedName) name).getQualifier(); } while (name.isQualifiedName() && bundle == null); if (bundle != null) { proposals.add(new AddBundleCompletion(context.getCompilationUnit().getJavaProject(), bundle)); } } } return proposals; }
From source file:lang.java.jdt.internal.FullyQualifyTypeNames.java
License:Open Source License
@Override public boolean visit(SimpleType node) { ITypeBinding tb = node.resolveBinding(); if (tb != null) { IPackageBinding pb = tb.getPackage(); if (pb != null && !pb.isUnnamed()) { String qualifiedTypeName = ""; if (tb.isNested()) { ITypeBinding parent = tb.getDeclaringClass(); String parentString = parent.getName(); while (parent != null && parent.isNested()) { parent = parent.getDeclaringClass(); parentString = parent.getName() + "." + parentString; }/*from w ww . j a v a2 s . com*/ qualifiedTypeName = pb.getName() + "." + parentString + "."; } else { qualifiedTypeName = pb.getName() + "."; } Name stName = node.getName(); if (stName.isQualifiedName()) { QualifiedName qn = (QualifiedName) stName; qualifiedTypeName = qualifiedTypeName + qn.getName().toString(); } else { SimpleName sn = (SimpleName) stName; qualifiedTypeName = qualifiedTypeName + sn.toString(); } SimpleType st = node.getAST().newSimpleType(node.getAST().newName(qualifiedTypeName)); rewriter.replace(node, st, null); } } return true; }
From source file:net.atos.optimus.common.tools.jdt.JavaCodeHelper.java
License:Open Source License
/** * Return the simple name as String from a Name instance *//*from w w w.j av a 2s .c o m*/ public static String getSimpleName(Name n) { String simpleName = null; /* * If it's a fully qualified name, remove package name. */ if (n.isQualifiedName()) { simpleName = n.getFullyQualifiedName().substring(n.getFullyQualifiedName().lastIndexOf('.') + 1); } else { simpleName = n.getFullyQualifiedName(); } return simpleName; }
From source file:org.eclipse.ajdt.internal.debug.ui.actions.ValidBreakpointLocationLocator.java
License:Open Source License
/** * Compute the name of the type which contains this node. * Result will be the name of the type or the inner type which contains this node, but not of the local or anonymous type. *//*from w w w . jav a 2 s. c om*/ static protected String computeTypeName(ASTNode node) { String typeName = null; while (!(node instanceof org.eclipse.jdt.core.dom.CompilationUnit)) { if (node instanceof org.eclipse.jdt.core.dom.AbstractTypeDeclaration) { String identifier = ((org.eclipse.jdt.core.dom.AbstractTypeDeclaration) node).getName() .getIdentifier(); if (typeName == null) { typeName = identifier; } else { typeName = identifier + "$" + typeName; //$NON-NLS-1$ } } else { typeName = null; } node = node.getParent(); } org.eclipse.jdt.core.dom.PackageDeclaration packageDecl = ((org.eclipse.jdt.core.dom.CompilationUnit) node) .getPackage(); String packageIdentifier = ""; //$NON-NLS-1$ if (packageDecl != null) { org.eclipse.jdt.core.dom.Name packageName = packageDecl.getName(); while (packageName.isQualifiedName()) { org.eclipse.jdt.core.dom.QualifiedName qualifiedName = (org.eclipse.jdt.core.dom.QualifiedName) packageName; packageIdentifier = qualifiedName.getName().getIdentifier() + "." + packageIdentifier; //$NON-NLS-1$ packageName = qualifiedName.getQualifier(); } packageIdentifier = ((org.eclipse.jdt.core.dom.SimpleName) packageName).getIdentifier() + "." //$NON-NLS-1$ + packageIdentifier; } return packageIdentifier + typeName; }
From source file:org.eclipse.che.jdt.dom.ASTNodes.java
License:Open Source License
public static String getSimpleNameIdentifier(Name name) { if (name.isQualifiedName()) { return ((QualifiedName) name).getName().getIdentifier(); } else {// w ww. j a v a 2s. c om return ((SimpleName) name).getIdentifier(); } }