Java Code Examples for org.eclipse.jdt.internal.ui.JavaPlugin#getPluginId()

The following examples show how to use org.eclipse.jdt.internal.ui.JavaPlugin#getPluginId() . 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: FilteredTypesSelectionDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected IStatus validateItem(Object item) {

	if (item == null)
		return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR, "", null); //$NON-NLS-1$

	if (fValidator != null) {
		IType type= ((TypeNameMatch) item).getType();
		if (!type.exists()) {
			String qualifiedName= TypeNameMatchLabelProvider.getText((TypeNameMatch) item, TypeNameMatchLabelProvider.SHOW_FULLYQUALIFIED);
			return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR, Messages.format(JavaUIMessages.FilteredTypesSelectionDialog_error_type_doesnot_exist, qualifiedName), null);
		}
		Object[] elements= { type };
		return fValidator.validate(elements);
	} else
		return Status.OK_STATUS;
}
 
Example 2
Source File: LazyGenericTypeProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds and returns the super type signature in the
 * <code>extends</code> or <code>implements</code> clause of
 * <code>subType</code> that corresponds to <code>superType</code>.
 *
 * @param subType a direct and true sub type of <code>superType</code>
 * @param superType a direct super type (super class or interface) of
 *        <code>subType</code>
 * @return the super type signature of <code>subType</code> referring
 *         to <code>superType</code>
 * @throws JavaModelException if extracting the super type signatures
 *         fails, or if <code>subType</code> contains no super type
 *         signature to <code>superType</code>
 */
private String findMatchingSuperTypeSignature(IType subType, IType superType) throws JavaModelException {
	String[] signatures= getSuperTypeSignatures(subType, superType);
	for (int i= 0; i < signatures.length; i++) {
		String signature= signatures[i];
		String qualified= SignatureUtil.qualifySignature(signature, subType);
		String subFQN= SignatureUtil.stripSignatureToFQN(qualified);

		String superFQN= superType.getFullyQualifiedName();
		if (subFQN.equals(superFQN)) {
			return signature;
		}

		// TODO handle local types
	}

	throw new JavaModelException(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "Illegal hierarchy", null))); //$NON-NLS-1$
}
 
Example 3
Source File: CompilationUnitCompletion.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Finds and returns the super type signature in the
 * <code>extends</code> or <code>implements</code> clause of
 * <code>subType</code> that corresponds to <code>superType</code>.
 *
 * @param subType a direct and true sub type of <code>superType</code>
 * @param superType a direct super type (super class or interface) of
 *        <code>subType</code>
 * @return the super type signature of <code>subType</code> referring
 *         to <code>superType</code>
 * @throws JavaModelException if extracting the super type signatures
 *         fails, or if <code>subType</code> contains no super type
 *         signature to <code>superType</code>
 */
private String findMatchingSuperTypeSignature(IType subType, IType superType) throws JavaModelException {
	String[] signatures= getSuperTypeSignatures(subType, superType);
	for (int i= 0; i < signatures.length; i++) {
		String signature= signatures[i];
		String qualified= SignatureUtil.qualifySignature(signature, subType);
		String subFQN= SignatureUtil.stripSignatureToFQN(qualified);

		String superFQN= superType.getFullyQualifiedName();
		if (subFQN.equals(superFQN)) {
			return signature;
		}

		// handle local types
		if (fLocalTypes.containsValue(subFQN)) {
			return signature;
		}
	}

	throw new JavaModelException(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "Illegal hierarchy", null))); //$NON-NLS-1$
}
 
Example 4
Source File: ProposalSorterHandle.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks that the given attribute value is not <code>null</code>.
 *
 * @param value the value to check if not null
 * @param attribute the attribute
 * @throws InvalidRegistryObjectException if the registry element is no longer valid
 * @throws CoreException if <code>value</code> is <code>null</code>
 */
private void checkNotNull(Object value, String attribute) throws InvalidRegistryObjectException, CoreException {
	if (value == null) {
		Object[] args= { getId(), fElement.getContributor().getName(), attribute };
		String message= Messages.format(JavaTextMessages.CompletionProposalComputerDescriptor_illegal_attribute_message, args);
		IStatus status= new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, message, null);
		throw new CoreException(status);
	}
}
 
Example 5
Source File: SearchParticipantDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected IQueryParticipant create() throws CoreException {
	try {
		return (IQueryParticipant) fConfigurationElement.createExecutableExtension(CLASS);
	} catch (ClassCastException e) {
		throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, SearchMessages.SearchParticipant_error_classCast, e));
	}
}
 
Example 6
Source File: JarImportWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Replaces the old jar file with the new one.
 *
 * @param monitor
 *            the progress monitor to use
 * @throws CoreException
 *             if an error occurs
 */
private void replaceJarFile(final IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(JarImportMessages.JarImportWizard_cleanup_import, 250);
		final URI location= fImportData.getRefactoringFileLocation();
		if (location != null) {
			final IPackageFragmentRoot root= fImportData.getPackageFragmentRoot();
			if (root != null) {
				final URI uri= getLocationURI(root.getRawClasspathEntry());
				if (uri != null) {
					final IFileStore store= EFS.getStore(location);
					if (fImportData.isRenameJarFile()) {
						final URI target= getTargetURI(uri);
						store.copy(EFS.getStore(target), EFS.OVERWRITE, new SubProgressMonitor(monitor, 50, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
						if (!uri.equals(target))
							EFS.getStore(uri).delete(EFS.NONE, new SubProgressMonitor(monitor, 50, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
					} else
						store.copy(EFS.getStore(uri), EFS.OVERWRITE, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
					if (fJavaProject != null)
						fJavaProject.getResource().refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 50, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
					return;
				}
			}
		}
		throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, JarImportMessages.JarImportWizard_error_copying_jar, null));
	} finally {
		monitor.done();
	}
}
 
Example 7
Source File: SnippetPreview.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void doFormatPreview() {
       if (fSnippets.isEmpty()) {
           fPreviewDocument.set(""); //$NON-NLS-1$
           return;
       }

       //This delimiter looks best for invisible characters
       final String delimiter= "\n"; //$NON-NLS-1$

       final StringBuffer buffer= new StringBuffer();
       for (final Iterator<PreviewSnippet> iter= fSnippets.iterator(); iter.hasNext();) {
           final PreviewSnippet snippet= iter.next();
           String formattedSource;
           try {
               formattedSource= CodeFormatterUtil.format(snippet.kind, snippet.source, 0, delimiter, fWorkingValues);
           } catch (Exception e) {
               final IStatus status= new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR,
                   FormatterMessages.JavaPreview_formatter_exception, e);
               JavaPlugin.log(status);
               continue;
           }
           buffer.append(delimiter);
           buffer.append(formattedSource);
           buffer.append(delimiter);
           buffer.append(delimiter);
       }
       fPreviewDocument.set(buffer.toString());
   }
 
Example 8
Source File: ParameterEditDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Status createErrorStatus(String message) {
	return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR, message, null);
}
 
Example 9
Source File: ParameterEditDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Status createWarningStatus(String message) {
	return new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.WARNING, message, null);
}
 
Example 10
Source File: CompletionProposalComputerDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IStatus createExceptionStatus(RuntimeException x) {
	// misbehaving extension - log
	String blame= createBlameMessage();
	String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_runtime_ex;
	return new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, blame + " " + reason, x); //$NON-NLS-1$
}
 
Example 11
Source File: CleanUpRegistry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private synchronized void ensureCleanUpsRegistered() {
	if (fCleanUpDescriptors != null)
		return;


	final ArrayList<CleanUpDescriptor> descriptors= new ArrayList<CleanUpDescriptor>();

	IExtensionPoint point= Platform.getExtensionRegistry().getExtensionPoint(JavaPlugin.getPluginId(), EXTENSION_POINT_NAME);
	IConfigurationElement[] elements= point.getConfigurationElements();
	for (int i= 0; i < elements.length; i++) {
		IConfigurationElement element= elements[i];

		if (CLEAN_UP_CONFIGURATION_ELEMENT_NAME.equals(element.getName())) {
			descriptors.add(new CleanUpDescriptor(element));
		}
	}


	// Make sure we filter those who fail or misbehave
	for (int i= 0; i < descriptors.size(); i++) {
		final CleanUpDescriptor cleanUpDescriptor= descriptors.get(i);
		final boolean disable[]= new boolean[1];
		ISafeRunnable runnable= new SafeRunnable() {
			
			public void run() throws Exception {
				ICleanUp cleanUp= cleanUpDescriptor.createCleanUp();
				if (cleanUp == null)
					disable[0]= true;
				else {
					cleanUp.setOptions(new CleanUpOptions());
					String[] enbledSteps= cleanUp.getStepDescriptions();
					if (enbledSteps != null && enbledSteps.length > 0) {
						JavaPlugin.logErrorMessage(
								Messages.format(FixMessages.CleanUpRegistry_cleanUpAlwaysEnabled_error, new String[] { cleanUpDescriptor.getId(),
								cleanUpDescriptor.fElement.getContributor().getName() }));
						disable[0]= true;
					}
				}
			}
			@Override
			public void handleException(Throwable t) {
				disable[0]= true;
				String message= Messages.format(FixMessages.CleanUpRegistry_cleanUpCreation_error, new String[] { cleanUpDescriptor.getId(),
						cleanUpDescriptor.fElement.getContributor().getName() });
				IStatus status= new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IJavaStatusConstants.INTERNAL_ERROR, message, t);
				JavaPlugin.log(status);
			}

		};
		SafeRunner.run(runnable);
		if (disable[0])
			descriptors.remove(i--);
	}

	fCleanUpDescriptors= descriptors.toArray(new CleanUpDescriptor[descriptors.size()]);
	sort(fCleanUpDescriptors);

}
 
Example 12
Source File: CompletionProposalComputerDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IStatus createPerformanceStatus(String operation) {
	String blame= createBlameMessage();
	Object[] args= {operation};
	String reason= Messages.format(JavaTextMessages.CompletionProposalComputerDescriptor_reason_performance, args);
	return new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, blame + " " + reason, null); //$NON-NLS-1$
}
 
Example 13
Source File: ProposalSorterHandle.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
Status createExceptionStatus(RuntimeException x) {
	// misbehaving extension - log & disable
	String disable= createBlameMessage();
	String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_runtime_ex;
	return new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, disable + " " + reason, x); //$NON-NLS-1$
}
 
Example 14
Source File: ProposalSorterHandle.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Status createPerformanceStatus(String operation) {
	String disable= createBlameMessage();
	Object[] args= {operation};
	String reason= Messages.format(JavaTextMessages.CompletionProposalComputerDescriptor_reason_performance, args);
	return new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, disable + " " + reason, null); //$NON-NLS-1$
}
 
Example 15
Source File: ProposalSorterHandle.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
Status createExceptionStatus(InvalidRegistryObjectException x) {
	// extension has become invalid - log & disable
	String disable= createBlameMessage();
	String reason= JavaTextMessages.CompletionProposalComputerDescriptor_reason_invalid;
	return new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, disable + " " + reason, x); //$NON-NLS-1$
}
 
Example 16
Source File: FileTransferDragAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private MultiStatus createMultiStatus() {
	return new MultiStatus(JavaPlugin.getPluginId(),
		IStatus.OK, PackagesMessages.DragAdapter_problem, null);
}
 
Example 17
Source File: JarFileExportOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Map<String, ArrayList<IResource>> buildJavaToClassMap(IContainer container, IProgressMonitor monitor) throws CoreException {
	if (container == null || !container.isAccessible())
		return new HashMap<String, ArrayList<IResource>>(0);
	/*
	 * XXX: Bug 6584: Need a way to get class files for a java file (or CU)
	 */
	IClassFileReader cfReader= null;
	IResource[] members= container.members();
	Map<String, ArrayList<IResource>> map= new HashMap<String, ArrayList<IResource>>(members.length);
	for (int i= 0;  i < members.length; i++) {
		if (isClassFile(members[i])) {
			IFile classFile= (IFile)members[i];
			URI location= classFile.getLocationURI();
			if (location != null) {
				InputStream contents= null;
				try {
					contents= EFS.getStore(location).openInputStream(EFS.NONE, monitor);
					cfReader= ToolFactory.createDefaultClassFileReader(contents, IClassFileReader.CLASSFILE_ATTRIBUTES);
				} finally {
					try {
						if (contents != null)
							contents.close();
					} catch (IOException e) {
						throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.ERROR,
							Messages.format(JarPackagerMessages.JarFileExportOperation_errorCannotCloseConnection, BasicElementLabels.getURLPart(Resources.getLocationString(classFile))),
							e));
					}
				}
				if (cfReader != null) {
					ISourceAttribute sourceAttribute= cfReader.getSourceFileAttribute();
					if (sourceAttribute == null) {
						/*
						 * Can't fully build the map because one or more
						 * class file does not contain the name of its
						 * source file.
						 */
						addWarning(Messages.format(
							JarPackagerMessages.JarFileExportOperation_classFileWithoutSourceFileAttribute,
							BasicElementLabels.getURLPart(Resources.getLocationString(classFile))), null);
						return null;
					}
					String javaName= new String(sourceAttribute.getSourceFileName());
					ArrayList<IResource> classFiles= map.get(javaName);
					if (classFiles == null) {
						classFiles= new ArrayList<IResource>(3);
						map.put(javaName, classFiles);
					}
					classFiles.add(classFile);
				}
			}
		}
	}
	return map;
}
 
Example 18
Source File: ParameterObjectFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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 19
Source File: CompilationUnitCompletion.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Given a type parameter of <code>superType</code> at position
 * <code>index</code>, this method computes and returns the (lower)
 * type bound(s) of that parameter for an instance of <code>fType</code>.
 * <p>
 * <code>superType</code> must be a super type of <code>fType</code>,
 * and <code>superType</code> must have at least
 * <code>index + 1</code> type parameters.
 * </p>
 *
 * @param superType the qualified type name of the super type to compute
 *        the type parameter binding for
 * @param index the index into the list of type parameters of
 *        <code>superType</code>
 * @return the binding
 * @throws JavaModelException if any java model operation fails
 * @throws IndexOutOfBoundsException if the index is not valid
 */
public String[] computeBinding(String superType, int index) throws JavaModelException, IndexOutOfBoundsException {
	IJavaProject project= fUnit.getJavaProject();
	IType type= project.findType(superType);
	if (type == null)
		throw new JavaModelException(new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), IStatus.OK, "No such type", null))); //$NON-NLS-1$
	return computeBinding(type, index);
}
 
Example 20
Source File: ModifyDialogTabPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
private IStatus createErrorStatus() {
    return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(FormatterMessages.ModifyDialogTabPage_NumberPreference_error_invalid_value, new String [] {Integer.toString(fMinValue), Integer.toString(fMaxValue)}), null);

}