Java Code Examples for org.eclipse.jdt.internal.corext.util.JavaModelUtil#concatenateName()
The following examples show how to use
org.eclipse.jdt.internal.corext.util.JavaModelUtil#concatenateName() .
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: Bindings.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static String getImportName(IBinding binding) { ITypeBinding declaring= null; switch (binding.getKind()) { case IBinding.TYPE: return getRawQualifiedName((ITypeBinding) binding); case IBinding.PACKAGE: return binding.getName() + ".*"; //$NON-NLS-1$ case IBinding.METHOD: declaring= ((IMethodBinding) binding).getDeclaringClass(); break; case IBinding.VARIABLE: declaring= ((IVariableBinding) binding).getDeclaringClass(); if (declaring == null) { return binding.getName(); // array.length } break; default: return binding.getName(); } return JavaModelUtil.concatenateName(getRawQualifiedName(declaring), binding.getName()); }
Example 2
Source File: SARLProposalProvider.java From sarl with Apache License 2.0 | 6 votes |
@Override public boolean accept(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { // Avoid auto reference of type. final String fullName = JavaModelUtil.concatenateName(packageName, simpleTypeName); if (Objects.equals(this.modelFullName, fullName)) { return false; } //The following tests are done by the visibility filter. //if (TypeMatchFilters.isInternalClass(simpleTypeName, enclosingTypeNames)) { // return false; //} //if (!TypeMatchFilters.isAcceptableByPreference().accept(modifiers, packageName, // simpleTypeName, enclosingTypeNames, path)) { // return false; //} // Final modifier test if (Flags.isFinal(modifiers)) { return false; } return this.visibilityFilter.accept(modifiers, packageName, simpleTypeName, enclosingTypeNames, path); }
Example 3
Source File: SelfEncapsulateFieldRefactoring.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private String createFieldAccess() throws JavaModelException { String fieldName = fField.getElementName(); boolean nameConflict = fArgName.equals(fieldName); if (JdtFlags.isStatic(fField)) { if (nameConflict) { return JavaModelUtil.concatenateName(fField.getDeclaringType().getElementName(), fieldName); } } else { // if (nameConflict || StubUtility.useThisForFieldAccess(fField.getJavaProject())) { return "this." + fieldName; //$NON-NLS-1$ // } } return fieldName; }
Example 4
Source File: MoveInnerToTopRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void initialize() throws JavaModelException { fQualifiedTypeName= JavaModelUtil.concatenateName(fType.getPackageFragment().getElementName(), fType.getElementName()); fEnclosingInstanceFieldName= getInitialNameForEnclosingInstanceField(); fSourceRewrite= new CompilationUnitRewrite(fType.getCompilationUnit()); fIsInstanceFieldCreationPossible= !(JdtFlags.isStatic(fType) || fType.isAnnotation() || fType.isEnum() || (fType.getDeclaringType() == null && !JavaElementUtil.isMainType(fType))); fIsInstanceFieldCreationMandatory= fIsInstanceFieldCreationPossible && isInstanceFieldCreationMandatory(); fCreateInstanceField= fIsInstanceFieldCreationMandatory; }
Example 5
Source File: ParameterObjectFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Type createType(boolean asTopLevelClass, CompilationUnitRewrite cuRewrite, int position) { String qualifier= asTopLevelClass ? fPackage : fEnclosingType; String concatenateName= JavaModelUtil.concatenateName(qualifier, fClassName); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); ContextSensitiveImportRewriteContext context= createParameterClassAwareContext(asTopLevelClass, cuRewrite, position); String addedImport= importRewrite.addImport(concatenateName, context); cuRewrite.getImportRemover().registerAddedImport(addedImport); AST ast= cuRewrite.getAST(); return ast.newSimpleType(ast.newName(addedImport)); }
Example 6
Source File: SelfEncapsulateFieldRefactoring.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String createFieldAccess() throws JavaModelException { String fieldName= fField.getElementName(); boolean nameConflict= fArgName.equals(fieldName); if (JdtFlags.isStatic(fField)) { if (nameConflict) { return JavaModelUtil.concatenateName(fField.getDeclaringType().getElementName(), fieldName); } } else { if (nameConflict || StubUtility.useThisForFieldAccess(fField.getJavaProject())) { return "this." + fieldName; //$NON-NLS-1$ } } return fieldName; }
Example 7
Source File: JavaElementReturnTypeHyperlink.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void open() { try { String returnTypeSignature= fMethod.getReturnType(); int kind= Signature.getTypeSignatureKind(returnTypeSignature); if (kind == Signature.ARRAY_TYPE_SIGNATURE) { returnTypeSignature= Signature.getElementType(returnTypeSignature); } else if (kind == Signature.CLASS_TYPE_SIGNATURE) { returnTypeSignature= Signature.getTypeErasure(returnTypeSignature); } String returnType= Signature.toString(returnTypeSignature); String[][] resolvedType= fMethod.getDeclaringType().resolveType(returnType); if (resolvedType == null || resolvedType.length == 0) { openMethodAndShowErrorInStatusLine(); return; } String typeName= JavaModelUtil.concatenateName(resolvedType[0][0], resolvedType[0][1]); IType type= fMethod.getJavaProject().findType(typeName, (IProgressMonitor)null); if (type != null) { fOpenAction.run(new StructuredSelection(type)); return; } openMethodAndShowErrorInStatusLine(); } catch (JavaModelException e) { JavaPlugin.log(e); return; } }
Example 8
Source File: GeneratedCssResource.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
private void createType(IPackageFragment pckg, boolean addComments) throws CoreException { IJavaProject javaProject = pckg.getJavaProject(); final IProgressMonitor monitor = new NullProgressMonitor(); // Method name should already have been sanitized and validated, so all we // should have to do to get a type name is just capitalize it String simpleName = StringUtilities.capitalize(getMethodName()); // See if the type name is already used String qualifiedName = JavaModelUtil.concatenateName(pckg.getElementName(), simpleName); IType existingType = JavaModelSearch.findType(javaProject, qualifiedName); if (existingType != null) { if (ClientBundleUtilities.isCssResource(javaProject, existingType)) { // If the existing type is a CssResource, we'll assume that it wraps // this CSS file and use it for our ClientBundle accessor return type // instead of trying to generate another CssResource here. customCssResourceType = existingType; return; } else { // If it's not a CssResource, then we'll need to generate a CssResource // ourself, but we can't use the name. So, let's compute a similar name // that is not already in use. simpleName = StringUtilities.computeUniqueName( getExistingTopLevelTypeNames(pckg), simpleName); } } // Parse the CSS and see if there were problems CssParseResult result = parseCss(); final IStatus status = result.getStatus(); // Bail out when errors occur if (status.getSeverity() == IStatus.ERROR) { throw new CoreException(status); } // For warnings, just display them in a dialog (on the UI thread of course) // TODO: would nice if we could aggregate these and show them all at the end if (status.getSeverity() == IStatus.WARNING) { Display.getDefault().syncExec(new Runnable() { public void run() { MessageDialog.openWarning(null, "CSS Parsing", status.getMessage()); } }); } // Extract the CSS class names final Set<String> cssClassNames = ExtractClassNamesVisitor.exec(result.getStylesheet()); TypeCreator gen = new TypeCreator(pckg, simpleName, TypeCreator.ElementType.INTERFACE, new String[] {ClientBundleUtilities.CSS_RESOURCE_TYPE_NAME}, addComments) { @Override protected void createTypeMembers(IType newType, ImportRewrite imports) throws CoreException { // Create an accessor method for each CSS class for (String cssClass : cssClassNames) { newType.createMethod(computeCssClassMethodSource(newType, cssClass), null, true, monitor); } } }; customCssResourceType = gen.createType(); }
Example 9
Source File: ParameterObjectFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public List<ResourceChange> createTopLevelParameterObject(IPackageFragmentRoot packageFragmentRoot, CreationListener listener) throws CoreException { List<ResourceChange> changes= new ArrayList<ResourceChange>(); IPackageFragment packageFragment= packageFragmentRoot.getPackageFragment(getPackage()); if (!packageFragment.exists()) { changes.add(new CreatePackageChange(packageFragment)); } ICompilationUnit unit= packageFragment.getCompilationUnit(getClassName() + JavaModelUtil.DEFAULT_CU_SUFFIX); Assert.isTrue(!unit.exists()); IJavaProject javaProject= unit.getJavaProject(); ICompilationUnit workingCopy= unit.getWorkingCopy(null); try { // create stub with comments and dummy type String lineDelimiter= StubUtility.getLineDelimiterUsed(javaProject); String fileComment= getFileComment(workingCopy, lineDelimiter); String typeComment= getTypeComment(workingCopy, lineDelimiter); String content= CodeGeneration.getCompilationUnitContent(workingCopy, fileComment, typeComment, "class " + getClassName() + "{}", lineDelimiter); //$NON-NLS-1$ //$NON-NLS-2$ workingCopy.getBuffer().setContents(content); CompilationUnitRewrite cuRewrite= new CompilationUnitRewrite(workingCopy); ASTRewrite rewriter= cuRewrite.getASTRewrite(); CompilationUnit root= cuRewrite.getRoot(); AST ast= cuRewrite.getAST(); ImportRewrite importRewrite= cuRewrite.getImportRewrite(); // retrieve&replace dummy type with real class ListRewrite types= rewriter.getListRewrite(root, CompilationUnit.TYPES_PROPERTY); ASTNode dummyType= (ASTNode) types.getOriginalList().get(0); String newTypeName= JavaModelUtil.concatenateName(getPackage(), getClassName()); TypeDeclaration classDeclaration= createClassDeclaration(newTypeName, cuRewrite, listener); classDeclaration.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD)); Javadoc javadoc= (Javadoc) dummyType.getStructuralProperty(TypeDeclaration.JAVADOC_PROPERTY); rewriter.set(classDeclaration, TypeDeclaration.JAVADOC_PROPERTY, javadoc, null); types.replace(dummyType, classDeclaration, null); // Apply rewrites and discard workingcopy // Using CompilationUnitRewrite.createChange() leads to strange // results String charset= ResourceUtil.getFile(unit).getCharset(false); Document document= new Document(content); try { rewriter.rewriteAST().apply(document); TextEdit rewriteImports= importRewrite.rewriteImports(null); rewriteImports.apply(document); } catch (BadLocationException e) { throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), RefactoringCoreMessages.IntroduceParameterObjectRefactoring_parameter_object_creation_error, e)); } String docContent= document.get(); CreateCompilationUnitChange compilationUnitChange= new CreateCompilationUnitChange(unit, docContent, charset); changes.add(compilationUnitChange); } finally { workingCopy.discardWorkingCopy(); } return changes; }
Example 10
Source File: ContextSensitiveImportRewriteContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private boolean isSameType(ITypeBinding binding, String qualifier, String name) { String qualifiedName= JavaModelUtil.concatenateName(qualifier, name); return binding.getQualifiedName().equals(qualifiedName); }