com.strobel.core.StringUtilities Java Examples

The following examples show how to use com.strobel.core.StringUtilities. 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: Formatter.java    From huntbugs with Apache License 2.0 5 votes vote down vote up
public static String formatConstant(Object constant) {
    if(constant instanceof String) {
        return StringUtilities.escape((String)constant, true);
    }
    if(constant instanceof TypeReference) {
        return ((TypeReference)constant).getSimpleName()+".class";
    }
    if(constant instanceof Number) {
        return formatValue(constant, FORMAT_PLAIN);
    }
    return String.valueOf(constant);
}
 
Example #2
Source File: MethodTranslator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
public TreeNode visitBreakStatement(
    com.strobel.decompiler.languages.java.ast.BreakStatement node, Void data) {
  String label = node.getLabel();
  if (StringUtilities.isNullOrEmpty(label)) {
    return new BreakStatement();
  } else {
    return new BreakStatement().setLabel(new SimpleName(label));
  }
}
 
Example #3
Source File: MethodTranslator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
public TreeNode visitContinueStatement(
    com.strobel.decompiler.languages.java.ast.ContinueStatement node, Void data) {
  String label = node.getLabel();
  if (StringUtilities.isNullOrEmpty(label)) {
    return new ContinueStatement();
  } else {
    return new ContinueStatement().setLabel(new SimpleName(label));
  }
}
 
Example #4
Source File: Formatter.java    From huntbugs with Apache License 2.0 4 votes vote down vote up
private static String formatString(String value, String format) {
    if (format.equals("const")) {
        return StringUtilities.escape(value, true);
    }
    return value;
}
 
Example #5
Source File: Equi.java    From huntbugs with Apache License 2.0 4 votes vote down vote up
private static boolean equiMethods(final MethodReference left, final MethodReference right) {
    return StringUtilities.equals(left.getFullName(), right.getFullName()) &&
        StringUtilities.equals(left.getErasedSignature(), right.getErasedSignature());
}
 
Example #6
Source File: Equi.java    From huntbugs with Apache License 2.0 4 votes vote down vote up
private static boolean equiFields(final FieldReference left, final FieldReference right) {
    return StringUtilities.equals(left.getFullName(), right.getFullName());
}
 
Example #7
Source File: FindAllBox.java    From Luyten with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent event) {
	tmp_thread = new Thread() {
		public void run() {
			if (findButton.getText().equals("Stop")) {
				if (tmp_thread != null)
					tmp_thread.interrupt();
				setStatus("Stopped.");
				findButton.setText("Find");
				locked = false;
			} else {
				findButton.setText("Stop");
				classesList.clear();
				ConfigSaver configSaver = ConfigSaver.getLoadedInstance();
				DecompilerSettings settings = configSaver.getDecompilerSettings();
				File inFile = MainWindow.model.getOpenedFile();
				boolean filter = ConfigSaver.getLoadedInstance().getLuytenPreferences()
						.isFilterOutInnerClassEntries();
				try {
					JarFile jfile = new JarFile(inFile);
					Enumeration<JarEntry> entLength = jfile.entries();
					initProgressBar(Collections.list(entLength).size());
					Enumeration<JarEntry> ent = jfile.entries();
					while (ent.hasMoreElements() && findButton.getText().equals("Stop")) {
						JarEntry entry = ent.nextElement();
						String name = entry.getName();
						setStatus(name);
						if (filter && name.contains("$"))
							continue;
						if(locked || classname.isSelected()){
							locked = true;
							if(search(entry.getName()))
								addClassName(entry.getName());
						}else{
							if (entry.getName().endsWith(".class")) {
								synchronized (settings) {
									String internalName = StringUtilities.removeRight(entry.getName(), ".class");
									TypeReference type = Model.metadataSystem.lookupType(internalName);
									TypeDefinition resolvedType = null;
									if (type == null || ((resolvedType = type.resolve()) == null)) {
										throw new Exception("Unable to resolve type.");
									}
									StringWriter stringwriter = new StringWriter();
									DecompilationOptions decompilationOptions;
									decompilationOptions = new DecompilationOptions();
									decompilationOptions.setSettings(settings);
									decompilationOptions.setFullDecompilation(true);
									PlainTextOutput plainTextOutput = new PlainTextOutput(stringwriter);
									plainTextOutput.setUnicodeOutputEnabled(
											decompilationOptions.getSettings().isUnicodeOutputEnabled());
									settings.getLanguage().decompileType(resolvedType, plainTextOutput,
											decompilationOptions);
									if (search(stringwriter.toString()))
										addClassName(entry.getName());
								}
							} else {

								StringBuilder sb = new StringBuilder();
								long nonprintableCharactersCount = 0;
								try (InputStreamReader inputStreamReader = new InputStreamReader(
										jfile.getInputStream(entry));
										BufferedReader reader = new BufferedReader(inputStreamReader);) {
									String line;
									while ((line = reader.readLine()) != null) {
										sb.append(line).append("\n");

										for (byte nextByte : line.getBytes()) {
											if (nextByte <= 0) {
												nonprintableCharactersCount++;
											}
										}

									}
								}
								if (nonprintableCharactersCount < 5 && search(sb.toString()))
									addClassName(entry.getName());
							}
						}
					}
					setSearching(false);
					if (findButton.getText().equals("Stop")) {
						setStatus("Done.");
						findButton.setText("Find");
						locked = false;
					}
					jfile.close();
					locked = false;
				} catch (Exception e) {
					Luyten.showExceptionDialog("Exception!", e);
				}

			}
		}
	};
	tmp_thread.start();

}