Java Code Examples for org.eclipse.xtext.common.types.JvmDeclaredType#getSimpleName()
The following examples show how to use
org.eclipse.xtext.common.types.JvmDeclaredType#getSimpleName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConstructorLinkingCandidate.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
@Override public boolean validate(IAcceptor<? super AbstractDiagnostic> result) { JvmDeclaredType declaringType = getConstructor().getDeclaringType(); if (declaringType.isAbstract()) { String message = "Cannot instantiate the abstract type " + declaringType.getSimpleName(); AbstractDiagnostic diagnostic = new EObjectDiagnosticImpl( Severity.ERROR, IssueCodes.ABSTRACT_CLASS_INSTANTIATION, message, getExpression(), getDefaultValidationFeature(), -1, null); result.accept(diagnostic); return false; } return super.validate(result); }
Example 2
Source File: JvmModelCompleter.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
public void completeJvmConstructor(JvmConstructor constructor) { JvmDeclaredType declaringType = constructor.getDeclaringType(); if(declaringType != null) { String simpleName = declaringType.getSimpleName(); if(simpleName != null) { constructor.setSimpleName(simpleName); return; } } constructor.setSimpleName("unset"); }
Example 3
Source File: XbaseReferenceUpdater.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * @return the currently imported type containing the newTargetType and the element's name relative to that import. */ protected Pair<JvmDeclaredType, QualifiedName> getImportedTypeAndRelativeName(JvmType newTargetType, RewritableImportSection section) { if (!(newTargetType instanceof JvmDeclaredType) || !section.isEnabled()) { return null; } JvmDeclaredType importedType = (JvmDeclaredType) newTargetType; StringBuffer relativeName = new StringBuffer(importedType.getSimpleName()); while(importedType.getDeclaringType() != null && !section.hasImportedType(importedType)) { importedType = importedType.getDeclaringType(); relativeName.insert(0, "."); relativeName.insert(0, importedType.getSimpleName()); } return Tuples.create(importedType, qualifiedNameConverter.toQualifiedName(relativeName.toString())); }
Example 4
Source File: XtendValidator.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
protected String getDeclaratorName(JvmFeature feature) { JvmDeclaredType declarator = feature.getDeclaringType(); if (declarator.isLocal()) { return "new " + Iterables.getLast(declarator.getSuperTypes()).getType().getSimpleName()+ "(){}"; } else { return declarator.getSimpleName(); } }
Example 5
Source File: ProjectAwareUniqueClassNameValidator.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public boolean doCheckUniqueInProject(QualifiedName name, JvmDeclaredType type) throws JavaModelException { IJavaProject javaProject = javaProjectProvider.getJavaProject(type.eResource().getResourceSet()); getContext().put(ProjectAwareUniqueClassNameValidator.OUTPUT_CONFIGS, outputConfigurationProvider.getOutputConfigurations(type.eResource())); String packageName = type.getPackageName(); String typeName = type.getSimpleName(); IndexManager indexManager = JavaModelManager.getIndexManager(); List<IPackageFragmentRoot> sourceFolders = new ArrayList<>(); for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) { if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { sourceFolders.add(root); } } if (sourceFolders.isEmpty() || indexManager.awaitingJobsCount() > 0) { // still indexing - don't enter a busy wait loop but ask the source folders directly SourceTraversal sourceTraversal = doCheckUniqueInProjectSource(packageName != null ? packageName : "", typeName, type, sourceFolders); if (sourceTraversal == SourceTraversal.DUPLICATE) { return false; } else if (sourceTraversal == SourceTraversal.UNIQUE) { return true; } } Set<String> workingCopyPaths = new HashSet<>(); ICompilationUnit[] copies = getWorkingCopies(type); if (copies != null) { for (ICompilationUnit workingCopy : copies) { IPath path = workingCopy.getPath(); if (javaProject.getPath().isPrefixOf(path) && !isDerived(workingCopy.getResource())) { if (workingCopy.getPackageDeclaration(packageName).exists()) { IType result = workingCopy.getType(typeName); if (result.exists()) { addIssue(type, workingCopy.getElementName()); return false; } } workingCopyPaths.add(workingCopy.getPath().toString()); } } } // The code below is adapted from BasicSearchEnginge.searchAllSecondaryTypes // The Index is ready, query it for a secondary type char[] pkg = packageName == null ? CharOperation.NO_CHAR : packageName.toCharArray(); TypeDeclarationPattern pattern = new TypeDeclarationPattern(pkg, // CharOperation.NO_CHAR_CHAR, // top level type - no enclosing type names typeName.toCharArray(), // IIndexConstants.TYPE_SUFFIX, // SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE); IndexQueryRequestor searchRequestor = new IndexQueryRequestor() { @Override public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) { if (workingCopyPaths.contains(documentPath)) { return true; // filter out working copies } IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(documentPath)); if (!isDerived(file)) { addIssue(type, file.getName()); return false; } return true; } }; try { SearchParticipant searchParticipant = BasicSearchEngine.getDefaultSearchParticipant(); // Java search only IJavaSearchScope javaSearchScope = BasicSearchEngine.createJavaSearchScope(sourceFolders.toArray(new IJavaElement[0])); PatternSearchJob patternSearchJob = new PatternSearchJob(pattern, searchParticipant, javaSearchScope, searchRequestor); indexManager.performConcurrentJob(patternSearchJob, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); return true; } catch (Throwable OperationCanceledException) { return false; } }