当前位置: 首页>>代码示例>>Java>>正文


Java ToolFactory类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.ToolFactory的典型用法代码示例。如果您正苦于以下问题:Java ToolFactory类的具体用法?Java ToolFactory怎么用?Java ToolFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ToolFactory类属于org.eclipse.jdt.core包,在下文中一共展示了ToolFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: formatEclipseStyle

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
public static String formatEclipseStyle(final Properties prop, final String content) {
  final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(prop);
  final IDocument document = new Document(content);
  try {
    final TextEdit textEdit =
        codeFormatter.format(
            CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
            content,
            0,
            content.length(),
            0,
            null);
    if (textEdit != null) {
      textEdit.apply(document);
    } else {
      return content;
    }
  } catch (final BadLocationException e) {
    return content;
  }

  return ensureCorrectNewLines(document.get());
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:24,代码来源:JavaFormatter.java

示例2: checkMethodsWithSharedAttributes

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
/**
 * Method to check with methods share common attributes, according to
 * CK definition.
 * @author Mariana Azevedo
 * @since 13/07/2014
 * @param methods
 */
private void checkMethodsWithSharedAttributes(IMethod[] methods){
	
	IScanner scanner = null;
	for (IMethod method : methods) {
		String methodName = method.getElementName();
		
		try {
			scanner = ToolFactory.createScanner(false, false, false, false);
			scanner.setSource(method.getSource().toCharArray());
			while(true){
				int charactere = scanner.getNextToken();
				if (charactere == ITerminalSymbols.TokenNameEOF) break;
				if (charactere == ITerminalSymbols.TokenNameIdentifier) {
					addMethods(new String(scanner.getCurrentTokenSource()), methodName);
				}
			}
		} catch (JavaModelException exception1) {
			logger.error(exception1);
		} catch (InvalidInputException exception2) {
			logger.error(exception2);
		}
		
	}
}
 
开发者ID:mariazevedo88,项目名称:o3smeasures-tool,代码行数:32,代码来源:LackCohesionMethodsJavaModel.java

示例3: calculateSerialVersionId

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
public static Long calculateSerialVersionId(ITypeBinding typeBinding, final IProgressMonitor monitor) throws CoreException, IOException {
	try {
		IFile classfileResource = getClassfile(typeBinding);
		if (classfileResource == null) {
			return null;
		}

		InputStream contents = classfileResource.getContents();
		try {
			IClassFileReader cfReader = ToolFactory.createDefaultClassFileReader(contents, IClassFileReader.ALL);
			if (cfReader != null) {
				return calculateSerialVersionId(cfReader);
			}
		} finally {
			contents.close();
		}
		return null;
	} finally {
		if (monitor != null) {
			monitor.done();
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:SerialVersionHashOperation.java

示例4: normalizeReference

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
/**
 * Removes comments and whitespace
 *
 * @param reference
 *            the type reference
 * @return the reference only consisting of dots and java identifier
 *         characters
 */
public static String normalizeReference(String reference) {
	IScanner scanner = ToolFactory.createScanner(false, false, false, false);
	scanner.setSource(reference.toCharArray());
	StringBuffer sb = new StringBuffer();
	try {
		int tokenType = scanner.getNextToken();
		while (tokenType != ITerminalSymbols.TokenNameEOF) {
			sb.append(scanner.getRawTokenSource());
			tokenType = scanner.getNextToken();
		}
	} catch (InvalidInputException e) {
		Assert.isTrue(false, reference);
	}
	reference = sb.toString();
	return reference;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:CommentAnalyzer.java

示例5: isJustWhitespaceOrComment

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
private static boolean isJustWhitespaceOrComment(int start, int end, IBuffer buffer) {
  if (start == end) return true;
  Assert.isTrue(start <= end);
  String trimmedText = buffer.getText(start, end - start).trim();
  if (0 == trimmedText.length()) {
    return true;
  } else {
    IScanner scanner = ToolFactory.createScanner(false, false, false, null);
    scanner.setSource(trimmedText.toCharArray());
    try {
      return scanner.getNextToken() == ITerminalSymbols.TokenNameEOF;
    } catch (InvalidInputException e) {
      return false;
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:Util.java

示例6: TokenScanner

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
/**
 * Creates a TokenScanner
 *
 * @param typeRoot The type root to scan on
 * @throws CoreException thrown if the buffer cannot be accessed
 */
public TokenScanner(ITypeRoot typeRoot) throws CoreException {
  IJavaProject project = typeRoot.getJavaProject();
  IBuffer buffer = typeRoot.getBuffer();
  if (buffer == null) {
    throw new CoreException(
        createError(DOCUMENT_ERROR, "Element has no source", null)); // $NON-NLS-1$
  }
  String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
  String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
  fScanner =
      ToolFactory.createScanner(
          true, false, true, sourceLevel, complianceLevel); // line info required

  fScanner.setSource(buffer.getCharacters());
  fDocument = null; // use scanner for line information
  fEndPosition = fScanner.getSource().length - 1;
}
 
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:TokenScanner.java

示例7: normalizeReference

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
/**
 * Removes comments and whitespace
 *
 * @param reference the type reference
 * @return the reference only consisting of dots and java identifier characters
 */
public static String normalizeReference(String reference) {
  IScanner scanner = ToolFactory.createScanner(false, false, false, false);
  scanner.setSource(reference.toCharArray());
  StringBuffer sb = new StringBuffer();
  try {
    int tokenType = scanner.getNextToken();
    while (tokenType != ITerminalSymbols.TokenNameEOF) {
      sb.append(scanner.getRawTokenSource());
      tokenType = scanner.getNextToken();
    }
  } catch (InvalidInputException e) {
    Assert.isTrue(false, reference);
  }
  reference = sb.toString();
  return reference;
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:CommentAnalyzer.java

示例8: formatJava

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
private String formatJava(IType type) throws JavaModelException {
  String source = type.getCompilationUnit().getSource();
  CodeFormatter formatter = ToolFactory.createCodeFormatter(type.getJavaProject().getOptions(true));
  TextEdit formatEdit = formatter.format(CodeFormatterFlags.getFlagsForCompilationUnitFormat(), source, 0,
      source.length(), 0, lineDelimiter);
  if (formatEdit == null) {
    CorePluginLog.logError("Could not format source for " + type.getCompilationUnit().getElementName());
    return source;
  }

  Document document = new Document(source);
  try {
    formatEdit.apply(document);
    source = document.get();
  } catch (BadLocationException e) {
    CorePluginLog.logError(e);
  }

  source = Strings.trimLeadingTabsAndSpaces(source);
  return source;
}
 
开发者ID:gwt-plugins,项目名称:gwt-eclipse-plugin,代码行数:22,代码来源:TypeCreator.java

示例9: normalizeReference

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
/**
 * Removes comments and whitespace
 * @param reference the type reference
 * @return the reference only consisting of dots and java identifier characters
 */
public static String normalizeReference(String reference) {
	IScanner scanner= ToolFactory.createScanner(false, false, false, false);
	scanner.setSource(reference.toCharArray());
	StringBuffer sb= new StringBuffer();
	try {
		int tokenType= scanner.getNextToken();
		while (tokenType != ITerminalSymbols.TokenNameEOF) {
			sb.append(scanner.getRawTokenSource());
			tokenType= scanner.getNextToken();
		}
	} catch (InvalidInputException e) {
		Assert.isTrue(false, reference);
	}
	reference= sb.toString();
	return reference;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:CommentAnalyzer.java

示例10: isJustWhitespaceOrComment

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
private static boolean isJustWhitespaceOrComment(int start, int end, IBuffer buffer) {
	if (start == end)
		return true;
	Assert.isTrue(start <= end);
	String trimmedText= buffer.getText(start, end - start).trim();
	if (0 == trimmedText.length()) {
		return true;
	} else {
		IScanner scanner= ToolFactory.createScanner(false, false, false, null);
		scanner.setSource(trimmedText.toCharArray());
		try {
			return scanner.getNextToken() == ITerminalSymbols.TokenNameEOF;
		} catch (InvalidInputException e) {
			return false;
		}
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:Util.java

示例11: calculateSerialVersionId

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
public static Long calculateSerialVersionId(ITypeBinding typeBinding, final IProgressMonitor monitor) throws CoreException, IOException {
	try {
		IFile classfileResource= getClassfile(typeBinding);
		if (classfileResource == null)
			return null;

		InputStream contents= classfileResource.getContents();
		try {
			IClassFileReader cfReader= ToolFactory.createDefaultClassFileReader(contents, IClassFileReader.ALL);
			if (cfReader != null) {
				return calculateSerialVersionId(cfReader);
			}
		} finally {
			contents.close();
		}
		return null;
	} finally {
		if (monitor != null)
			monitor.done();
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:SerialVersionHashOperation.java

示例12: initScanner

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
/**
 * @param source
 *            must be not null
 * @param range
 *            can be null
 * @return may return null, otherwise an initialized scanner which may
 *         answer which source offset index belongs to which source line
 * @throws JavaModelException
 */
private static IScanner initScanner(IType source, ISourceRange range) throws JavaModelException {
    if (range == null) {
        return null;
    }
    char[] charContent = getContent(source);
    if (charContent == null) {
        return null;
    }
    IScanner scanner = ToolFactory.createScanner(false, false, false, true);
    scanner.setSource(charContent);
    int offset = range.getOffset();
    try {
        while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) {
            // do nothing, just wait for the end of stream
            if (offset <= scanner.getCurrentTokenEndPosition()) {
                break;
            }
        }
    } catch (InvalidInputException e) {
        FindbugsPlugin.getDefault().logException(e, "Could not init scanner for type: " + source);
    }
    return scanner;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:33,代码来源:MarkerUtil.java

示例13: disassemble

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
public static String disassemble(IClassFile classFile) {
	ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
	String disassembledByteCode = null;
	try {
		disassembledByteCode = disassembler.disassemble(classFile.getBytes(), LF,
				ClassFileBytesDisassembler.WORKING_COPY);
		disassembledByteCode = MISSING_SOURCES_HEADER + LF + disassembledByteCode;
	} catch (Exception e) {
		// JavaLanguageServerPlugin.logError("Unable to disassemble " +
		// classFile.getHandleIdentifier());
		e.printStackTrace();
	}
	return disassembledByteCode;
}
 
开发者ID:angelozerr,项目名称:codelens-eclipse,代码行数:15,代码来源:JDTUtils.java

示例14: formatUnitSourceCode

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
/**
 * Format a Unit Source Code
 * 
 * @param testInterface
 * @param monitor
 * @throws CoreException 
 */
@SuppressWarnings("unchecked")
public static void formatUnitSourceCode(IFile file, IProgressMonitor monitor) throws CoreException {
	@SuppressWarnings("rawtypes")
	SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
	ICompilationUnit unit = JavaCore.createCompilationUnitFrom(file);
	subMonitor.split(50);
	ICompilationUnit workingCopy = unit.getWorkingCopy(monitor);

	Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();

	options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7);
	options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7);
	options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7);

	options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS,
			DefaultCodeFormatterConstants.createAlignmentValue(true,
					DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE,
					DefaultCodeFormatterConstants.INDENT_ON_COLUMN));

	final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
	ISourceRange range = unit.getSourceRange();
	TextEdit formatEdit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, unit.getSource(),
			range.getOffset(), range.getLength(), 0, null);
	subMonitor.split(30);
	if (formatEdit != null /* && formatEdit.hasChildren()*/) {
		workingCopy.applyTextEdit(formatEdit, monitor);
		workingCopy.reconcile(ICompilationUnit.NO_AST, false, null, null);
		workingCopy.commitWorkingCopy(true, null);
		workingCopy.discardWorkingCopy();
	}
	file.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
	subMonitor.split(20);
}
 
开发者ID:gw4e,项目名称:gw4e.project,代码行数:41,代码来源:JDTManager.java

示例15: JavaCodeFormatter

import org.eclipse.jdt.core.ToolFactory; //导入依赖的package包/类
/**
 * Creates a JavaCodeFormatter using the default formatter options and
 * optionally applying user provided options on top.
 *
 * @param overrideOptions user provided options to apply on top of defaults
 */
public JavaCodeFormatter(final Map<String, Object> overrideOptions) {
    Map formatterOptions = new HashMap<>(DEFAULT_FORMATTER_OPTIONS);
    if (overrideOptions != null) {
        formatterOptions.putAll(overrideOptions);
    }

    this.codeFormatter = ToolFactory.createCodeFormatter(formatterOptions,
                                                         ToolFactory.M_FORMAT_EXISTING);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:16,代码来源:JavaCodeFormatter.java


注:本文中的org.eclipse.jdt.core.ToolFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。